Class: Element
- Includes:
- SourceCodeDumpable
- Defined in:
- lib/rpdf2txt-rockit/grammar.rb
Overview
A Grammar has a name, a set of tokens, a start symbol and a set of productions. Grammars are modular and can be merged. To help in resolving conflicts when grammars are merged the symbols that are exported from a grammar can be specified. By default all the nonterminals (left hand sides of the productions) are exported.
Productions map a NonTerminal to a sequence of Element’s. Elements can be either symbols (NonTerminals or terminals represented by their string name or symbol) or OperatorElements.
OperatorElements are one of:
Plus - corresponds to the EBNF operator '+', ie. one or several
Mult - corresponds to the EBNF operator '*', ie. zero or several
Maybe - corresponds to the EBNF operator '?', ie. zero or one
List(Elements, separator) - A list of Elements separated by separator
Or - One of a sequence (at least 2) elements
A grammar is in normal form when no OperatorElements are in its productions. Converting a grammar to normal form is called normalization. Converting a syntax tree back to the unnormalized form of its grammar is called denormalization. Normalization is part of this file while denormalization is in a file of its own.
Productions include a syntax tree specification describing how to build a (sub)tree for the syntax tree of the production when it is been matched. The SyntaxTreeSpecification needs to be known at this level since it is affected by normalization.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#sub_elements ⇒ Object
Returns the value of attribute sub_elements.
-
#tree_specification ⇒ Object
Returns the value of attribute tree_specification.
Instance Method Summary collapse
-
#initialize(subElements, treeSpecification = nil) ⇒ Element
constructor
A new instance of Element.
-
#normalize(productions) ⇒ Object
Normalize the element in the context of a production.
Methods included from SourceCodeDumpable
as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src
Constructor Details
#initialize(subElements, treeSpecification = nil) ⇒ Element
Returns a new instance of Element.
39 40 41 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 39 def initialize(subElements, treeSpecification = nil) @sub_elements, @tree_specification = subElements, treeSpecification end |
Instance Attribute Details
#sub_elements ⇒ Object
Returns the value of attribute sub_elements.
37 38 39 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 37 def sub_elements @sub_elements end |
#tree_specification ⇒ Object
Returns the value of attribute tree_specification.
37 38 39 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 37 def tree_specification @tree_specification end |
Instance Method Details
#normalize(productions) ⇒ Object
Normalize the element in the context of a production. The context is needed to give information for naming of extra productions that (may) need to be created. Returns two arrays, the former with the normalization of the element in the existing production and the latter with additional productions needed.
48 49 50 51 52 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 48 def normalize(productions) # Default is that no normalization is needed and no extra productions # are added [productions, []] end |