View Source Renewex.Grammar (renewex v0.10.0)
This module defines the grammar to parse Renew *.rnw
files.
The Renew grammar is version dependent and depends on the Java class hierarchy defined in renew.
This module defines a struct to describe the class hierarchy and some specialized function to parse specific classes.
Summary
Functions
This struct describes the class hierarchy for a specific version of Renew that should be applied as grammar.
The version
field is an integer between -1 (the original renew version) and 11 (the newest Renew version at the time of writing this comment).
The latest version of Renew to be used preferably.
The earliest version of Renew to be used for files that do not specify their own version explicitly.
Constructs a new grammar struct for the given version.
Applies a specific rul to the current parser state.
Serialize the given field_values
according to the given grammar rule
.
Checks if for the given grammar and given class name the skip skip_super flag is set.
If the skip_super flag is set, the grammar rules of the parent class shall not be applied during parsing.
This corresponds to NOT calling super.read()
in the java implementation of the class.
Functions
This struct describes the class hierarchy for a specific version of Renew that should be applied as grammar.
The version
field is an integer between -1 (the original renew version) and 11 (the newest Renew version at the time of writing this comment).
The hierarchy
field contains a Map
from Java class names to class descriptions. It mirrors the Java class definitions defined in Renew.
This is done because the grammar that is used for reading and writing Renew files is implicitly defined via the Java implementation.
In order to match the grammar exactly this Java class hierarchy is reenacted.
The latest version of Renew to be used preferably.
The earliest version of Renew to be used for files that do not specify their own version explicitly.
Constructs a new grammar struct for the given version.
Applies a specific rul to the current parser state.
Parameters
- parser: the current state of the parser
- rule: the name of the parser rule to apply. The parse rule is a java class name that must be defined in the grammars hierarchy.
- into: an
Storable
struct into which the parsed values shall be appended
Returns
{:ok, Renew.Storable{into | fields: parsed_fields}, next_parse_state}
if the rule was applied successfully. Whereparsed_fields
contain the values that have been parsed by the rule and next_parse_state is the state of the parser after having consumed the tokens processed by the parse rule{:error, reason, next_parse_state}
if the rule could not be applied for some reason.
Serialize the given field_values
according to the given grammar rule
.
Parameters
serializer
: The serializer into which output the result is appended.rule
: The name of the grammar rule to be used for serializtation. The actual grammar definition comes from theserializer
.field_values
: The map of values to be serialized.
Resturns
Either {:ok, new_serializer}
if the serializtation was successful.
Otheriwse {:error, reason}
if it failed for some reason
.
Checks if for the given grammar and given class name the skip skip_super flag is set.
If the skip_super flag is set, the grammar rules of the parent class shall not be applied during parsing.
This corresponds to NOT calling super.read()
in the java implementation of the class.
Parameters
- grammar: the current state of the parser
- rule: name of the grammar rule
Returns
- if the the :skip_user flag has been set for the given rule in the given grammar.