Class: Rng::ParseTreeProcessor
- Inherits:
-
Object
- Object
- Rng::ParseTreeProcessor
- Defined in:
- lib/rng/parse_tree_processor.rb
Overview
Normalizes parse tree structure into consistent grammar format
Handles three different RNC file structures:
-
Top-level includes (Metanorma-style)
-
Grammar block wrapper
-
Flat grammar
Instance Attribute Summary collapse
-
#grammar_tree ⇒ Object
readonly
Returns the value of attribute grammar_tree.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#preamble ⇒ Object
readonly
Returns the value of attribute preamble.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(tree) ⇒ ParseTreeProcessor
constructor
Initialize with parse tree.
-
#normalize ⇒ self
Normalize the parse tree.
Constructor Details
#initialize(tree) ⇒ ParseTreeProcessor
Initialize with parse tree
24 25 26 27 28 29 |
# File 'lib/rng/parse_tree_processor.rb', line 24 def initialize(tree) @tree = tree @namespace = nil @preamble = nil # NEW: SchemaPreamble object @grammar_tree = nil end |
Instance Attribute Details
#grammar_tree ⇒ Object (readonly)
Returns the value of attribute grammar_tree.
19 20 21 |
# File 'lib/rng/parse_tree_processor.rb', line 19 def grammar_tree @grammar_tree end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
19 20 21 |
# File 'lib/rng/parse_tree_processor.rb', line 19 def namespace @namespace end |
#preamble ⇒ Object (readonly)
Returns the value of attribute preamble.
19 20 21 |
# File 'lib/rng/parse_tree_processor.rb', line 19 def preamble @preamble end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
19 20 21 |
# File 'lib/rng/parse_tree_processor.rb', line 19 def tree @tree end |
Instance Method Details
#normalize ⇒ self
Normalize the parse tree
Extracts namespace and builds consistent grammar structure regardless of input format. Processes raw override blocks.
37 38 39 40 41 42 43 44 |
# File 'lib/rng/parse_tree_processor.rb', line 37 def normalize @preamble = extract_preamble_section # NEW: Extract preamble first @namespace = extract_namespace # KEEP: Legacy namespace extraction @grammar_tree = build_grammar_tree process_raw_overrides!(@grammar_tree) # MODIFIED: Add both old and new metadata self end |