FPIBG Utility
libconf.TokenStream Class Reference

Public Member Functions

 __init__ (self, tokens)
 
 from_file (cls, f, filename=None, includedir='', seenfiles=None)
 
 peek (self)
 
 accept (self, *args)
 
 expect (self, *args)
 
 error (self, msg)
 
 finished (self)
 

Public Attributes

int position = 0
 
 tokens = list(tokens)
 

Detailed Description

Offer a parsing-oriented view on tokens

Provide several methods that are useful to parsers, like ``accept()``,
``expect()``, ...

The ``from_file()`` method is the preferred way to read input files, as
it handles include directives, which the ``Tokenizer`` class does not do.

Constructor & Destructor Documentation

◆ __init__()

libconf.TokenStream.__init__ ( self,
tokens )

Member Function Documentation

◆ accept()

libconf.TokenStream.accept ( self,
* args )
Consume and return the next token if it has the correct type

Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.

If the token type doesn't match, return None.

◆ error()

libconf.TokenStream.error ( self,
msg )
Raise a ConfigParseError at the current input position

◆ expect()

libconf.TokenStream.expect ( self,
* args )
Consume and return the next token if it has the correct type

Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.

If the token type doesn't match, raise a ConfigParseError.

◆ finished()

libconf.TokenStream.finished ( self)
Return ``True`` if the end of the token stream is reached.

◆ from_file()

libconf.TokenStream.from_file ( cls,
f,
filename = None,
includedir = '',
seenfiles = None )
Create a token stream by reading an input file

Read tokens from `f`. If an include directive ('@include "file.cfg"')
is found, read its contents as well.

The `filename` argument is used for error messages and to detect
circular imports. ``includedir`` sets the lookup directory for included
files.  ``seenfiles`` is used internally to detect circular includes,
and should normally not be supplied by users of is function.

◆ peek()

libconf.TokenStream.peek ( self)
Return (but do not consume) the next token

At the end of input, ``None`` is returned.

Member Data Documentation

◆ position

int libconf.TokenStream.position = 0

◆ tokens

libconf.TokenStream.tokens = list(tokens)

The documentation for this class was generated from the following file: