Class: IgniterLang::Parser
- Inherits:
-
Object
- Object
- IgniterLang::Parser
- Defined in:
- lib/igniter_lang/parser.rb
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
262 263 264 265 266 |
# File 'lib/igniter_lang/parser.rb', line 262 def initialize(tokens) @tokens = tokens @pos = 0 @errors = [] end |
Instance Method Details
#parse ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/igniter_lang/parser.rb', line 268 def parse program = { "kind" => "source_file", "module" => nil, "imports" => [], "traits" => [], "impls" => [], "contract_shapes" => [], "contracts" => [], "types" => [], "functions" => [], "pipelines" => [], "olap_points" => [], "assumptions" => [], "parse_errors" => [] } # optional module declaration if peek_kw?("module") advance program["module"] = parse_module_path end # imports while peek_kw?("import") advance program["imports"] << parse_import end # top-level declarations until peek_type?(:eof) decl = parse_top_decl case decl&.fetch("kind") when "trait" then program["traits"] << decl when "impl" then program["impls"] << decl when "contract_shape" then program["contract_shapes"] << decl when "contract" then program["contracts"] << decl when "type" then program["types"] << decl when "function" then program["functions"] << decl when "pipeline" then program["pipelines"] << decl when "olap_point" then program["olap_points"] << decl when "assumptions" then program["assumptions"].concat(decl.fetch("assumptions", [])) end end program["parse_errors"] = @errors program end |