montepy.input_parser.parser_base module#
- class montepy.input_parser.parser_base.MCNP_Parser#
Bases:
Parser
Base class for all MCNP parsers that provides basics.
Added in version 0.2.0: This was added with the major parser rework.
- classifier(p)#
The classifier of a data input.
This represents the first word of the data input. E.g.:
M4
, IMP:N,F104:p
- Return type:
- classifier_phrase(p)#
A classifier with its padding.
- Return type:
- data_prefix(p)#
- debugfile = None#
- equals_sign(p)#
The seperation between a key and value for a parameter.
- Returns:
a str ValueNode
- Return type:
- errok()#
Clear the error status
- error(token)#
Default error handling.
Puts the data into a queue that can be pulled out later for one final clear debug.
- Parameters:
token (Token) – the token that broke the parsing rules.
- file_atom(p)#
- file_name(p)#
A file name.
- Return type:
str
- file_phrase(p)#
A file name with or without its padding.
- Returns:
a str ValueNode.
- Return type:
- identifier_phrase(p)#
A non-zero number with or without padding converted to int.
- Returns:
an int ValueNode
- Return type:
- index_position(value)#
- line_position(value)#
- log = <montepy.input_parser.parser_base.SLY_Supressor object>#
- modifier(p)#
A character that modifies a classifier, e.g.,
*TR
.- Returns:
the modifier
- Return type:
str
- null_ident_phrase(p)#
A zero number with or without its padding, for identification.
- Returns:
an int ValueNode
- Return type:
- null_phrase(p)#
A zero number with or without its padding.
- Returns:
a float ValueNode
- Return type:
- number_phrase(p)#
A non-zero number with or without padding.
- Returns:
a float ValueNode
- Return type:
- numerical_phrase(p)#
Any number, including 0, with its padding.
- Returns:
a float ValueNode
- Return type:
- padding(p)#
Anything that is not semantically significant: white space, and comments.
- Returns:
All sequential padding.
- Return type:
- param_seperator(p)#
The seperation between a key and value for a parameter.
- Returns:
a str ValueNode
- Return type:
- parameter(p)#
A singular Key-value pair.
- Returns:
the parameter.
- Return type:
- parameters(p)#
A list of the parameters (key, value pairs) for this input.
- Returns:
all parameters
- Return type:
- parse(token_generator, input=None)#
Parses the token stream and returns a syntax tree.
If the parsing fails None will be returned. The error queue can be retrieved from
parser.log.clear_queue()
.- Parameters:
token_generator (generator) – the token generator from
lexer.tokenize
.input (Input) – the input that is being lexed and parsed.
- Return type:
- part(p)#
- particle_type(p)#
- precedence = (('left', 'SPACE'), ('left', 'TEXT'))#
- restart()#
Clears internal state information about the current parse.
Should be ran before a new object is parsed.
- shortcut_phrase(p)#
A complete shortcut, which should be used, and not shortcut_sequence.
- Returns:
the parsed shortcut.
- Return type:
- shortcut_sequence(p)#
A shortcut (repeat, multiply, interpolate, or jump).
- Returns:
the parsed shortcut.
- Return type:
- shortcut_start(p)#
- text_phrase(p)#
A string with or without its padding.
- Returns:
a str ValueNode.
- Return type:
- tokens = {'COMMENT', 'COMPLEMENT', 'DOLLAR_COMMENT', 'FILE_PATH', 'INTERPOLATE', 'JUMP', 'KEYWORD', 'LIBRARY_SUFFIX', 'LOG_INTERPOLATE', 'MESSAGE', 'MULTIPLY', 'NULL', 'NUMBER', 'NUMBER_WORD', 'NUM_INTERPOLATE', 'NUM_JUMP', 'NUM_LOG_INTERPOLATE', 'NUM_MULTIPLY', 'NUM_REPEAT', 'PARTICLE', 'PARTICLE_SPECIAL', 'REPEAT', 'SOURCE_COMMENT', 'SPACE', 'SURFACE_TYPE', 'TALLY_COMMENT', 'TEXT', 'THERMAL_LAW', 'ZAID'}#
- track_positions = True#
- class montepy.input_parser.parser_base.MetaBuilder(classname, bases, attributes)#
Bases:
ParserMeta
Custom MetaClass for allowing subclassing of MCNP_Parser.
Added in version 0.2.0: This was added with the major parser rework.
Note: overloading functions is not allowed.
- mro()#
Return a type’s method resolution order.
- protected_names = {'debugfile', 'dont_copy', 'errok', 'error', 'index_position', 'line_position', 'log', 'parse', 'restart', 'tokens'}#
- class montepy.input_parser.parser_base.SLY_Supressor#
Bases:
object
This is a fake logger meant to mostly make warnings dissapear.
Added in version 0.2.0: This was added with the major parser rework.
- clear_queue()#
Clears the error queue and returns all errors.
Returns a list of dictionaries. The dictionary has the keys: “message”, “token”, “line.
- Returns:
A list of the errors since the queue was last cleared.
- Return type:
list
- critical(msg, *args, **kwargs)#
- debug(msg, *args, **kwargs)#
- error(msg, *args, **kwargs)#
- info(msg, *args, **kwargs)#
- parse_error(msg, token=None, lineno=0, index=0)#
Adds a SLY parsing error to the error queue for being dumped later.
- Parameters:
msg (str) – The message to display.
token (Token) – the token that caused the error if any.
lineno (int) – the current lineno of the error (from SLY not the file), if any.
- warning(msg, *args, **kwargs)#