The lexer submodule¶
Warning
The functions and methods listed in this section are implementation details of CondConfigParser. Do not use them in your programs if you rely on API stability, as they are likely to change in incompatible ways without prior notice.
Lexer module of CondConfigParser.
This module defines a Token class, one subclass for every token
type, a TokenType enum.Enum and a Lexer
class.
- class condconfigparser.lexer.TokenType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
AutoNumberIdentifier objects for token types.
- newline = 1¶
- varAssignmentsStart = 2¶
- varAssignmentsEnd = 3¶
- predicateStart = 4¶
- predicateEnd = 5¶
- listStart = 6¶
- listEnd = 7¶
- openParen = 8¶
- closeParen = 9¶
- orOp = 10¶
- andOp = 11¶
- notOp = 12¶
- equalsOp = 13¶
- notEqualsOp = 14¶
- inOp = 15¶
- assignOp = 16¶
- comma = 17¶
- true = 18¶
- false = 19¶
- stringLiteral = 20¶
- variable = 21¶
- rawConfigLine = 22¶
- class condconfigparser.lexer.Token(startline, startcol)[source]¶
Bases:
objectClass representing a token instance (lexeme).
Token.startlineandToken.startcolare 1-based line and column numbers for the first character of the lexeme (i.e., where the token starts in the parsed stream). Assuming it fits on one line of the input stream (which is not necessarily the case for string literal tokens), the column number of its last character is given by:Token.startcol+ len(Token.string) - 1.Instances of this class must be considered immutable. They can be used as dictionary keys and set elements, among others. Since these operations assume that the hash value of the object never changes, it is an error to modify such an object after an operation that relies on its hash value (cf.
object.__hash__()).- string = None¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = None¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.NewlineToken(startline, startcol)[source]¶
Bases:
Token- string = '\n'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '\\n'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.VarAssignmentsStartToken(startline, startcol)[source]¶
Bases:
Token- string = '{'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '{'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.VarAssignmentsEndToken(startline, startcol)[source]¶
Bases:
Token- string = '}'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '}'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.PredicateStartToken(startline, startcol)[source]¶
Bases:
Token- string = '['¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '['¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.PredicateEndToken(startline, startcol)[source]¶
Bases:
Token- string = ']'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = ']'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.ListStartToken(startline, startcol)[source]¶
Bases:
Token- string = '['¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '['¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.ListEndToken(startline, startcol)[source]¶
Bases:
Token- string = ']'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = ']'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.OpenParenToken(startline, startcol)[source]¶
Bases:
Token- string = '('¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '('¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.CloseParenToken(startline, startcol)[source]¶
Bases:
Token- string = ')'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = ')'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.OrToken(startline, startcol)[source]¶
Bases:
Token- string = 'or'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'or'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.AndToken(startline, startcol)[source]¶
Bases:
Token- string = 'and'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'and'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.NotToken(startline, startcol)[source]¶
Bases:
Token- string = 'not'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'not'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.EqualsToken(startline, startcol)[source]¶
Bases:
Token- string = '=='¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '=='¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.NotEqualsToken(startline, startcol)[source]¶
Bases:
Token- string = '!='¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '!='¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.InToken(startline, startcol)[source]¶
Bases:
Token- string = 'in'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'in'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.AssignToken(startline, startcol)[source]¶
Bases:
Token- string = '='¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = '='¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.CommaToken(startline, startcol)[source]¶
Bases:
Token- string = ','¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = ','¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.TrueToken(startline, startcol)[source]¶
Bases:
Token- string = 'True'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'True'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.FalseToken(startline, startcol)[source]¶
Bases:
Token- string = 'False'¶
The raw lexeme, i.e., the exact string read from the parsed file
- stringRepr = 'False'¶
String used for
__str__(), in particular for theNewlineToken
- class condconfigparser.lexer.StringLiteralToken(startline, startcol, unprocessedString, value)[source]¶
Bases:
Token- value¶
String obtained after escape sequences expansion in the string literal
- condconfigparser.lexer.mayClose = {')': (<class 'condconfigparser.lexer.OpenParenToken'>,), ']': (<class 'condconfigparser.lexer.ListStartToken'>, <class 'condconfigparser.lexer.PredicateStartToken'>), '}': (<class 'condconfigparser.lexer.VarAssignmentsStartToken'>,)}¶
Which token(s) may be closed by a given closing delimiter
- class condconfigparser.lexer.Lexer(stream)[source]¶
Bases:
object- WSandComments_cre = re.compile(' *(#.*)?')¶
- keywordOrVariable_cre = re.compile('\\b ([a-zA-Z0-9_]+) \\b', re.VERBOSE)¶
- equalsOp_cre = re.compile('==[^=!]')¶
- notEqualsOp_cre = re.compile('!=[^=!]')¶
- assign_cre = re.compile('=[^=!]')¶
- backslashNewline_cre = re.compile('\\\\\\n')¶
- skipWSNLandComments(delimStack=None)[source]¶
Skip a possibly-multiline mix of spaces and comments.
By default,
NewlineTokeninstances are collected as encountered and returned in the form of a list. However, if delimStack is a non-empty delimiter stack, some of the newline tokens are selectively omitted from the returned list.
- scanBalancedTokens(delimStack)[source]¶
Scan a balanced sequence of tokens.
Normally, the token sequence should start right after a
VarAssignmentsStartToken({) orListStartToken([), which should be found at the top of delimStack. All subsequent tokens will be scanned and yielded until a}or]matching the top of delimStack is found. The method does not consume that closing delimiter, for symmetry with the handling of the opening delimiter.