Class: Kumi::Parser::DirectParser
- Inherits:
-
Object
- Object
- Kumi::Parser::DirectParser
- Includes:
- Helpers
- Defined in:
- lib/kumi/parser/direct_parser.rb
Overview
Direct AST construction parser using recursive descent with embedded token metadata
Instance Method Summary collapse
-
#initialize(tokens) ⇒ DirectParser
constructor
A new instance of DirectParser.
- #parse ⇒ Object
Methods included from Helpers
#advance_and_return_token, #convert_literal_value, #expect_field_name_token, #map_operator_token_to_function_name, #next_is_kwarg_after_comma?, #parse_args_and_opts_inside_parens, #parse_kw_literal_value, #parse_optional_decl_kwargs, #skip_comments_and_newlines
Constructor Details
#initialize(tokens) ⇒ DirectParser
Returns a new instance of DirectParser.
9 10 11 12 13 |
# File 'lib/kumi/parser/direct_parser.rb', line 9 def initialize(tokens) @tokens = tokens @pos = 0 @imported_names = Set.new end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kumi/parser/direct_parser.rb', line 15 def parse skip_comments_and_newlines # Parse root-level imports (before schema) root_imports = parse_imports @imported_names.merge(root_imports.flat_map(&:names)) schema_node = parse_schema # If we have root imports, add them to the schema if root_imports.any? # Merge root imports with schema imports schema_node.imports.concat(root_imports) end skip_comments_and_newlines expect_token(:eof) schema_node end |