Class: RuboCop::AST::NodePattern::Parser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- RuboCop::AST::NodePattern::Parser
- Extended by:
- SimpleForwardable
- Defined in:
- lib/rubocop/ast/node_pattern/parser.rb,
lib/rubocop/ast/node_pattern/with_meta.rb,
lib/rubocop/ast/node_pattern/parser.racc.rb
Overview
Parser for NodePattern Note: class reopened in ‘parser.racc`
Doc on how this fits in the compiling process:
/docs/modules/ROOT/pages/node_pattern.adoc
Direct Known Subclasses
Defined Under Namespace
Classes: WithMeta
Constant Summary collapse
- Builder =
NodePattern::Builder
- Lexer =
NodePattern::Lexer
- Racc_arg =
[ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ]
- Racc_token_to_s_table =
[ "$end", "error", "tSYMBOL", "tNUMBER", "tSTRING", "tWILDCARD", "tPARAM_NAMED", "tPARAM_CONST", "tPARAM_NUMBER", "tFUNCTION_CALL", "tPREDICATE", "tNODE_TYPE", "tARG_LIST", "tUNIFY", "tREGEXP", "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"!\"", "\"^\"", "\"`\"", "\"$\"", "\"{\"", "\"}\"", "\"<\"", "\">\"", "\"?\"", "\"*\"", "\"+\"", "\"...\"", "\",\"", "\"|\"", "$start", "node_pattern", "node_pattern_no_union", "union", "variadic_pattern_list", "node_pattern_list", "args", "atom", "separated_variadic_patterns", "variadic_pattern", "repetition", "opt_capture", "opt_rest", "rest", "arg_list" ]
- Racc_debug_parser =
false
Instance Method Summary collapse
- #_reduce_10(val, _values) ⇒ Object
- #_reduce_11(val, _values) ⇒ Object
-
#_reduce_13(val, _values) ⇒ Object
reduce 12 omitted.
- #_reduce_14(val, _values) ⇒ Object
- #_reduce_15(val, _values) ⇒ Object
- #_reduce_16(val, _values) ⇒ Object
- #_reduce_17(val, _values) ⇒ Object
- #_reduce_18(val, _values) ⇒ Object
- #_reduce_19(val, _values) ⇒ Object
-
#_reduce_2(val, _values) ⇒ Object
reduce 1 omitted.
- #_reduce_20(val, _values) ⇒ Object
- #_reduce_21(val, _values) ⇒ Object
- #_reduce_22(val, _values) ⇒ Object
-
#_reduce_25(val, _values) ⇒ Object
reduce 24 omitted.
- #_reduce_26(val, _values) ⇒ Object
- #_reduce_3(val, _values) ⇒ Object
-
#_reduce_33(val, _values) ⇒ Object
reduce 32 omitted.
-
#_reduce_37(val, _values) ⇒ Object
reduce 36 omitted.
- #_reduce_38(val, _values) ⇒ Object
- #_reduce_39(val, _values) ⇒ Object
- #_reduce_4(val, _values) ⇒ Object
- #_reduce_40(val, _values) ⇒ Object
- #_reduce_41(val, _values) ⇒ Object
- #_reduce_42(val, _values) ⇒ Object
- #_reduce_43(val, _values) ⇒ Object
- #_reduce_44(val, _values) ⇒ Object
- #_reduce_45(val, _values) ⇒ Object
- #_reduce_46(val, _values) ⇒ Object
- #_reduce_5(val, _values) ⇒ Object
- #_reduce_6(val, _values) ⇒ Object
- #_reduce_7(val, _values) ⇒ Object
- #_reduce_8(val, _values) ⇒ Object
- #_reduce_9(val, _values) ⇒ Object
- #_reduce_none(val, _values) ⇒ Object
-
#initialize(builder = self.class::Builder.new) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object
-
#parse(source) ⇒ NodePattern::Node
(Similar API to ‘parser` gem) Parses a source and returns the AST.
Methods included from SimpleForwardable
Constructor Details
#initialize(builder = self.class::Builder.new) ⇒ Parser
Returns a new instance of Parser.
19 20 21 22 |
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 19 def initialize(builder = self.class::Builder.new) super() @builder = builder end |
Instance Method Details
#_reduce_10(val, _values) ⇒ Object
335 336 337 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 335 def _reduce_10(val, _values) emit_call :predicate, *val end |
#_reduce_11(val, _values) ⇒ Object
339 340 341 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 339 def _reduce_11(val, _values) emit_call :node_type, *val end |
#_reduce_13(val, _values) ⇒ Object
reduce 12 omitted
345 346 347 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 345 def _reduce_13(val, _values) emit_atom :symbol, *val end |
#_reduce_14(val, _values) ⇒ Object
349 350 351 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 349 def _reduce_14(val, _values) emit_atom :number, *val end |
#_reduce_15(val, _values) ⇒ Object
353 354 355 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 353 def _reduce_15(val, _values) emit_atom :string, *val end |
#_reduce_16(val, _values) ⇒ Object
357 358 359 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 357 def _reduce_16(val, _values) emit_atom :const, *val end |
#_reduce_17(val, _values) ⇒ Object
361 362 363 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 361 def _reduce_17(val, _values) emit_atom :named_parameter, *val end |
#_reduce_18(val, _values) ⇒ Object
365 366 367 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 365 def _reduce_18(val, _values) emit_atom :positional_parameter, *val end |
#_reduce_19(val, _values) ⇒ Object
369 370 371 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 369 def _reduce_19(val, _values) emit_atom :regexp, *val end |
#_reduce_2(val, _values) ⇒ Object
reduce 1 omitted
303 304 305 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 303 def _reduce_2(val, _values) enforce_unary(val[0]) end |
#_reduce_20(val, _values) ⇒ Object
373 374 375 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 373 def _reduce_20(val, _values) emit_atom :wildcard, *val end |
#_reduce_21(val, _values) ⇒ Object
377 378 379 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 377 def _reduce_21(val, _values) emit_atom :unify, *val end |
#_reduce_22(val, _values) ⇒ Object
381 382 383 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 381 def _reduce_22(val, _values) emit_union(*val) end |
#_reduce_25(val, _values) ⇒ Object
reduce 24 omitted
389 390 391 392 393 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 389 def _reduce_25(val, _values) main, repeat_t = val emit_unary_op(:repetition, repeat_t, main, repeat_t) end |
#_reduce_26(val, _values) ⇒ Object
395 396 397 398 399 400 401 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 395 def _reduce_26(val, _values) opt_capture, bracket, node_pattern_list, opt_rest, close_bracket = val node_pattern_list << opt_rest if opt_rest main = emit_list :any_order, bracket, node_pattern_list, close_bracket emit_capture(opt_capture, main) end |
#_reduce_3(val, _values) ⇒ Object
307 308 309 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 307 def _reduce_3(val, _values) emit_list :sequence, *val end |
#_reduce_33(val, _values) ⇒ Object
reduce 32 omitted
415 416 417 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 415 def _reduce_33(val, _values) emit_capture(val[0], emit_atom(:rest, val[1])) end |
#_reduce_37(val, _values) ⇒ Object
reduce 36 omitted
425 426 427 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 425 def _reduce_37(val, _values) val end |
#_reduce_38(val, _values) ⇒ Object
429 430 431 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 429 def _reduce_38(val, _values) val end |
#_reduce_39(val, _values) ⇒ Object
433 434 435 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 433 def _reduce_39(val, _values) val[0] << val[2] end |
#_reduce_4(val, _values) ⇒ Object
311 312 313 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 311 def _reduce_4(val, _values) emit_list :intersection, *val end |
#_reduce_40(val, _values) ⇒ Object
437 438 439 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 437 def _reduce_40(val, _values) val end |
#_reduce_41(val, _values) ⇒ Object
441 442 443 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 441 def _reduce_41(val, _values) val[0] << val[1] end |
#_reduce_42(val, _values) ⇒ Object
445 446 447 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 445 def _reduce_42(val, _values) val end |
#_reduce_43(val, _values) ⇒ Object
449 450 451 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 449 def _reduce_43(val, _values) val[0] << val[1] end |
#_reduce_44(val, _values) ⇒ Object
453 454 455 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 453 def _reduce_44(val, _values) [[]] end |
#_reduce_45(val, _values) ⇒ Object
457 458 459 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 457 def _reduce_45(val, _values) val[0].last << val[1]; val[0] end |
#_reduce_46(val, _values) ⇒ Object
461 462 463 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 461 def _reduce_46(val, _values) val[0] << [] end |
#_reduce_5(val, _values) ⇒ Object
315 316 317 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 315 def _reduce_5(val, _values) emit_unary_op :negation, *val end |
#_reduce_6(val, _values) ⇒ Object
319 320 321 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 319 def _reduce_6(val, _values) emit_unary_op :ascend, *val end |
#_reduce_7(val, _values) ⇒ Object
323 324 325 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 323 def _reduce_7(val, _values) emit_unary_op :descend, *val end |
#_reduce_8(val, _values) ⇒ Object
327 328 329 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 327 def _reduce_8(val, _values) emit_capture(*val) end |
#_reduce_9(val, _values) ⇒ Object
331 332 333 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 331 def _reduce_9(val, _values) emit_call :function_call, *val end |
#_reduce_none(val, _values) ⇒ Object
465 466 467 |
# File 'lib/rubocop/ast/node_pattern/parser.racc.rb', line 465 def _reduce_none(val, _values) val[0] end |
#inspect ⇒ Object
40 41 42 |
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 40 def inspect "<##{self.class}>" end |
#parse(source) ⇒ NodePattern::Node
(Similar API to ‘parser` gem) Parses a source and returns the AST.
31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/ast/node_pattern/parser.rb', line 31 def parse(source) @lexer = self.class::Lexer.new(source) do_parse rescue Lexer::Error => e raise NodePattern::Invalid, e. ensure @lexer = nil # Don't keep references end |