View Source Renewex.Grammar (renewex v0.1.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.

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

Link to this function

%Renewex.Grammar{}

View Source (struct)

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.

Link to this function

new(version \\ latest_version())

View Source

Constructs a new grammar struct for the given version.

Link to this function

parse(parser, rule, into)

View Source

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, %Storable{into | fields: parsed_fields}, next_parse_state} if the rule was applied successfully. Where parsed_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.
Link to this function

should_skip_super(grammar, rule)

View Source

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.