parselly 0.1.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1506 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # DO NOT MODIFY!!!!
4
+ # This file is automatically generated by Racc 1.8.1
5
+ # from Racc grammar file "parser.y".
6
+ #
7
+
8
+ ###### racc/parser.rb begin
9
+ unless $".find {|p| p.end_with?('/racc/parser.rb')}
10
+ $".push "#{__dir__}/racc/parser.rb"
11
+ self.class.module_eval(<<'...end racc/parser.rb/module_eval...', 'racc/parser.rb', 1)
12
+ #--
13
+ # Copyright (c) 1999-2006 Minero Aoki
14
+ #
15
+ # This program is free software.
16
+ # You can distribute/modify this program under the same terms of ruby.
17
+ #
18
+ # As a special exception, when this code is copied by Racc
19
+ # into a Racc output file, you may use that output file
20
+ # without restriction.
21
+ #++
22
+
23
+ unless $".find {|p| p.end_with?('/racc/info.rb')}
24
+ $".push "#{__dir__}/racc/info.rb"
25
+
26
+ module Racc
27
+ VERSION = '1.8.1'
28
+ Version = VERSION
29
+ Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
30
+ end
31
+
32
+ end
33
+
34
+
35
+ module Racc
36
+ class ParseError < StandardError; end
37
+ end
38
+ unless defined?(::ParseError)
39
+ ParseError = Racc::ParseError # :nodoc:
40
+ end
41
+
42
+ # Racc is an LALR(1) parser generator.
43
+ # It is written in Ruby itself, and generates Ruby programs.
44
+ #
45
+ # == Command-line Reference
46
+ #
47
+ # racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
48
+ # [-e<var>rubypath</var>] [--executable=<var>rubypath</var>]
49
+ # [-v] [--verbose]
50
+ # [-O<var>filename</var>] [--log-file=<var>filename</var>]
51
+ # [-g] [--debug]
52
+ # [-E] [--embedded]
53
+ # [-l] [--no-line-convert]
54
+ # [-c] [--line-convert-all]
55
+ # [-a] [--no-omit-actions]
56
+ # [-C] [--check-only]
57
+ # [-S] [--output-status]
58
+ # [--version] [--copyright] [--help] <var>grammarfile</var>
59
+ #
60
+ # [+grammarfile+]
61
+ # Racc grammar file. Any extension is permitted.
62
+ # [-o+outfile+, --output-file=+outfile+]
63
+ # A filename for output. default is <+filename+>.tab.rb
64
+ # [-O+filename+, --log-file=+filename+]
65
+ # Place logging output in file +filename+.
66
+ # Default log file name is <+filename+>.output.
67
+ # [-e+rubypath+, --executable=+rubypath+]
68
+ # output executable file(mode 755). where +path+ is the Ruby interpreter.
69
+ # [-v, --verbose]
70
+ # verbose mode. create +filename+.output file, like yacc's y.output file.
71
+ # [-g, --debug]
72
+ # add debug code to parser class. To display debugging information,
73
+ # use this '-g' option and set @yydebug true in parser class.
74
+ # [-E, --embedded]
75
+ # Output parser which doesn't need runtime files (racc/parser.rb).
76
+ # [-F, --frozen]
77
+ # Output parser which declares frozen_string_literals: true
78
+ # [-C, --check-only]
79
+ # Check syntax of racc grammar file and quit.
80
+ # [-S, --output-status]
81
+ # Print messages time to time while compiling.
82
+ # [-l, --no-line-convert]
83
+ # turns off line number converting.
84
+ # [-c, --line-convert-all]
85
+ # Convert line number of actions, inner, header and footer.
86
+ # [-a, --no-omit-actions]
87
+ # Call all actions, even if an action is empty.
88
+ # [--version]
89
+ # print Racc version and quit.
90
+ # [--copyright]
91
+ # Print copyright and quit.
92
+ # [--help]
93
+ # Print usage and quit.
94
+ #
95
+ # == Generating Parser Using Racc
96
+ #
97
+ # To compile Racc grammar file, simply type:
98
+ #
99
+ # $ racc parse.y
100
+ #
101
+ # This creates Ruby script file "parse.tab.y". The -o option can change the output filename.
102
+ #
103
+ # == Writing A Racc Grammar File
104
+ #
105
+ # If you want your own parser, you have to write a grammar file.
106
+ # A grammar file contains the name of your parser class, grammar for the parser,
107
+ # user code, and anything else.
108
+ # When writing a grammar file, yacc's knowledge is helpful.
109
+ # If you have not used yacc before, Racc is not too difficult.
110
+ #
111
+ # Here's an example Racc grammar file.
112
+ #
113
+ # class Calcparser
114
+ # rule
115
+ # target: exp { print val[0] }
116
+ #
117
+ # exp: exp '+' exp
118
+ # | exp '*' exp
119
+ # | '(' exp ')'
120
+ # | NUMBER
121
+ # end
122
+ #
123
+ # Racc grammar files resemble yacc files.
124
+ # But (of course), this is Ruby code.
125
+ # yacc's $$ is the 'result', $0, $1... is
126
+ # an array called 'val', and $-1, $-2... is an array called '_values'.
127
+ #
128
+ # See the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for
129
+ # more information on grammar files.
130
+ #
131
+ # == Parser
132
+ #
133
+ # Then you must prepare the parse entry method. There are two types of
134
+ # parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
135
+ #
136
+ # Racc::Parser#do_parse is simple.
137
+ #
138
+ # It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
139
+ # This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
140
+ # EOF is [false, false].
141
+ # (TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
142
+ # If you want to change this, see the grammar reference.
143
+ #
144
+ # Racc::Parser#yyparse is little complicated, but useful.
145
+ # It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
146
+ #
147
+ # For example, <code>yyparse(obj, :scan)</code> causes
148
+ # calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
149
+ #
150
+ # == Debugging
151
+ #
152
+ # When debugging, "-v" or/and the "-g" option is helpful.
153
+ #
154
+ # "-v" creates verbose log file (.output).
155
+ # "-g" creates a "Verbose Parser".
156
+ # Verbose Parser prints the internal status when parsing.
157
+ # But it's _not_ automatic.
158
+ # You must use -g option and set +@yydebug+ to +true+ in order to get output.
159
+ # -g option only creates the verbose parser.
160
+ #
161
+ # === Racc reported syntax error.
162
+ #
163
+ # Isn't there too many "end"?
164
+ # grammar of racc file is changed in v0.10.
165
+ #
166
+ # Racc does not use '%' mark, while yacc uses huge number of '%' marks..
167
+ #
168
+ # === Racc reported "XXXX conflicts".
169
+ #
170
+ # Try "racc -v xxxx.y".
171
+ # It causes producing racc's internal log file, xxxx.output.
172
+ #
173
+ # === Generated parsers does not work correctly
174
+ #
175
+ # Try "racc -g xxxx.y".
176
+ # This command let racc generate "debugging parser".
177
+ # Then set @yydebug=true in your parser.
178
+ # It produces a working log of your parser.
179
+ #
180
+ # == Re-distributing Racc runtime
181
+ #
182
+ # A parser, which is created by Racc, requires the Racc runtime module;
183
+ # racc/parser.rb.
184
+ #
185
+ # Ruby 1.8.x comes with Racc runtime module,
186
+ # you need NOT distribute Racc runtime files.
187
+ #
188
+ # If you want to include the Racc runtime module with your parser.
189
+ # This can be done by using '-E' option:
190
+ #
191
+ # $ racc -E -omyparser.rb myparser.y
192
+ #
193
+ # This command creates myparser.rb which `includes' Racc runtime.
194
+ # Only you must do is to distribute your parser file (myparser.rb).
195
+ #
196
+ # Note: parser.rb is ruby license, but your parser is not.
197
+ # Your own parser is completely yours.
198
+ module Racc
199
+
200
+ unless defined?(Racc_No_Extensions)
201
+ Racc_No_Extensions = false # :nodoc:
202
+ end
203
+
204
+ class Parser
205
+
206
+ Racc_Runtime_Version = ::Racc::VERSION
207
+ Racc_Runtime_Core_Version_R = ::Racc::VERSION
208
+
209
+ begin
210
+ if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
211
+ require 'jruby'
212
+ require 'racc/cparse-jruby.jar'
213
+ com.headius.racc.Cparse.new.load(JRuby.runtime, false)
214
+ else
215
+ require 'racc/cparse'
216
+ end
217
+
218
+ unless new.respond_to?(:_racc_do_parse_c, true)
219
+ raise LoadError, 'old cparse.so'
220
+ end
221
+ if Racc_No_Extensions
222
+ raise LoadError, 'selecting ruby version of racc runtime core'
223
+ end
224
+
225
+ Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
226
+ Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
227
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
228
+ Racc_Runtime_Type = 'c' # :nodoc:
229
+ rescue LoadError
230
+ Racc_Main_Parsing_Routine = :_racc_do_parse_rb
231
+ Racc_YY_Parse_Method = :_racc_yyparse_rb
232
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
233
+ Racc_Runtime_Type = 'ruby'
234
+ end
235
+
236
+ def Parser.racc_runtime_type # :nodoc:
237
+ Racc_Runtime_Type
238
+ end
239
+
240
+ def _racc_setup
241
+ @yydebug = false unless self.class::Racc_debug_parser
242
+ @yydebug = false unless defined?(@yydebug)
243
+ if @yydebug
244
+ @racc_debug_out = $stderr unless defined?(@racc_debug_out)
245
+ @racc_debug_out ||= $stderr
246
+ end
247
+ arg = self.class::Racc_arg
248
+ arg[13] = true if arg.size < 14
249
+ arg
250
+ end
251
+
252
+ def _racc_init_sysvars
253
+ @racc_state = [0]
254
+ @racc_tstack = []
255
+ @racc_vstack = []
256
+
257
+ @racc_t = nil
258
+ @racc_val = nil
259
+
260
+ @racc_read_next = true
261
+
262
+ @racc_user_yyerror = false
263
+ @racc_error_status = 0
264
+ end
265
+
266
+ # The entry point of the parser. This method is used with #next_token.
267
+ # If Racc wants to get token (and its value), calls next_token.
268
+ #
269
+ # Example:
270
+ # def parse
271
+ # @q = [[1,1],
272
+ # [2,2],
273
+ # [3,3],
274
+ # [false, '$']]
275
+ # do_parse
276
+ # end
277
+ #
278
+ # def next_token
279
+ # @q.shift
280
+ # end
281
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
282
+ def do_parse
283
+ #{Racc_Main_Parsing_Routine}(_racc_setup(), false)
284
+ end
285
+ RUBY
286
+
287
+ # The method to fetch next token.
288
+ # If you use #do_parse method, you must implement #next_token.
289
+ #
290
+ # The format of return value is [TOKEN_SYMBOL, VALUE].
291
+ # +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
292
+ # for 'IDENT'. ";" (String) for ';'.
293
+ #
294
+ # The final symbol (End of file) must be false.
295
+ def next_token
296
+ raise NotImplementedError, "#{self.class}\#next_token is not defined"
297
+ end
298
+
299
+ def _racc_do_parse_rb(arg, in_debug)
300
+ action_table, action_check, action_default, action_pointer,
301
+ _, _, _, _,
302
+ _, _, token_table, * = arg
303
+
304
+ _racc_init_sysvars
305
+ tok = act = i = nil
306
+
307
+ catch(:racc_end_parse) {
308
+ while true
309
+ if i = action_pointer[@racc_state[-1]]
310
+ if @racc_read_next
311
+ if @racc_t != 0 # not EOF
312
+ tok, @racc_val = next_token()
313
+ unless tok # EOF
314
+ @racc_t = 0
315
+ else
316
+ @racc_t = (token_table[tok] or 1) # error token
317
+ end
318
+ racc_read_token(@racc_t, tok, @racc_val) if @yydebug
319
+ @racc_read_next = false
320
+ end
321
+ end
322
+ i += @racc_t
323
+ unless i >= 0 and
324
+ act = action_table[i] and
325
+ action_check[i] == @racc_state[-1]
326
+ act = action_default[@racc_state[-1]]
327
+ end
328
+ else
329
+ act = action_default[@racc_state[-1]]
330
+ end
331
+ while act = _racc_evalact(act, arg)
332
+ ;
333
+ end
334
+ end
335
+ }
336
+ end
337
+
338
+ # Another entry point for the parser.
339
+ # If you use this method, you must implement RECEIVER#METHOD_ID method.
340
+ #
341
+ # RECEIVER#METHOD_ID is a method to get next token.
342
+ # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
343
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
344
+ def yyparse(recv, mid)
345
+ #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
346
+ end
347
+ RUBY
348
+
349
+ def _racc_yyparse_rb(recv, mid, arg, c_debug)
350
+ action_table, action_check, action_default, action_pointer,
351
+ _, _, _, _,
352
+ _, _, token_table, * = arg
353
+
354
+ _racc_init_sysvars
355
+
356
+ catch(:racc_end_parse) {
357
+ until i = action_pointer[@racc_state[-1]]
358
+ while act = _racc_evalact(action_default[@racc_state[-1]], arg)
359
+ ;
360
+ end
361
+ end
362
+ recv.__send__(mid) do |tok, val|
363
+ unless tok
364
+ @racc_t = 0
365
+ else
366
+ @racc_t = (token_table[tok] or 1) # error token
367
+ end
368
+ @racc_val = val
369
+ @racc_read_next = false
370
+
371
+ i += @racc_t
372
+ unless i >= 0 and
373
+ act = action_table[i] and
374
+ action_check[i] == @racc_state[-1]
375
+ act = action_default[@racc_state[-1]]
376
+ end
377
+ while act = _racc_evalact(act, arg)
378
+ ;
379
+ end
380
+
381
+ while !(i = action_pointer[@racc_state[-1]]) ||
382
+ ! @racc_read_next ||
383
+ @racc_t == 0 # $
384
+ unless i and i += @racc_t and
385
+ i >= 0 and
386
+ act = action_table[i] and
387
+ action_check[i] == @racc_state[-1]
388
+ act = action_default[@racc_state[-1]]
389
+ end
390
+ while act = _racc_evalact(act, arg)
391
+ ;
392
+ end
393
+ end
394
+ end
395
+ }
396
+ end
397
+
398
+ ###
399
+ ### common
400
+ ###
401
+
402
+ def _racc_evalact(act, arg)
403
+ action_table, action_check, _, action_pointer,
404
+ _, _, _, _,
405
+ _, _, _, shift_n,
406
+ reduce_n, * = arg
407
+ nerr = 0 # tmp
408
+
409
+ if act > 0 and act < shift_n
410
+ #
411
+ # shift
412
+ #
413
+ if @racc_error_status > 0
414
+ @racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
415
+ end
416
+ @racc_vstack.push @racc_val
417
+ @racc_state.push act
418
+ @racc_read_next = true
419
+ if @yydebug
420
+ @racc_tstack.push @racc_t
421
+ racc_shift @racc_t, @racc_tstack, @racc_vstack
422
+ end
423
+
424
+ elsif act < 0 and act > -reduce_n
425
+ #
426
+ # reduce
427
+ #
428
+ code = catch(:racc_jump) {
429
+ @racc_state.push _racc_do_reduce(arg, act)
430
+ false
431
+ }
432
+ if code
433
+ case code
434
+ when 1 # yyerror
435
+ @racc_user_yyerror = true # user_yyerror
436
+ return -reduce_n
437
+ when 2 # yyaccept
438
+ return shift_n
439
+ else
440
+ raise '[Racc Bug] unknown jump code'
441
+ end
442
+ end
443
+
444
+ elsif act == shift_n
445
+ #
446
+ # accept
447
+ #
448
+ racc_accept if @yydebug
449
+ throw :racc_end_parse, @racc_vstack[0]
450
+
451
+ elsif act == -reduce_n
452
+ #
453
+ # error
454
+ #
455
+ case @racc_error_status
456
+ when 0
457
+ unless arg[21] # user_yyerror
458
+ nerr += 1
459
+ on_error @racc_t, @racc_val, @racc_vstack
460
+ end
461
+ when 3
462
+ if @racc_t == 0 # is $
463
+ # We're at EOF, and another error occurred immediately after
464
+ # attempting auto-recovery
465
+ throw :racc_end_parse, nil
466
+ end
467
+ @racc_read_next = true
468
+ end
469
+ @racc_user_yyerror = false
470
+ @racc_error_status = 3
471
+ while true
472
+ if i = action_pointer[@racc_state[-1]]
473
+ i += 1 # error token
474
+ if i >= 0 and
475
+ (act = action_table[i]) and
476
+ action_check[i] == @racc_state[-1]
477
+ break
478
+ end
479
+ end
480
+ throw :racc_end_parse, nil if @racc_state.size <= 1
481
+ @racc_state.pop
482
+ @racc_vstack.pop
483
+ if @yydebug
484
+ @racc_tstack.pop
485
+ racc_e_pop @racc_state, @racc_tstack, @racc_vstack
486
+ end
487
+ end
488
+ return act
489
+
490
+ else
491
+ raise "[Racc Bug] unknown action #{act.inspect}"
492
+ end
493
+
494
+ racc_next_state(@racc_state[-1], @racc_state) if @yydebug
495
+
496
+ nil
497
+ end
498
+
499
+ def _racc_do_reduce(arg, act)
500
+ _, _, _, _,
501
+ goto_table, goto_check, goto_default, goto_pointer,
502
+ nt_base, reduce_table, _, _,
503
+ _, use_result, * = arg
504
+
505
+ state = @racc_state
506
+ vstack = @racc_vstack
507
+ tstack = @racc_tstack
508
+
509
+ i = act * -3
510
+ len = reduce_table[i]
511
+ reduce_to = reduce_table[i+1]
512
+ method_id = reduce_table[i+2]
513
+ void_array = []
514
+
515
+ tmp_t = tstack[-len, len] if @yydebug
516
+ tmp_v = vstack[-len, len]
517
+ tstack[-len, len] = void_array if @yydebug
518
+ vstack[-len, len] = void_array
519
+ state[-len, len] = void_array
520
+
521
+ # tstack must be updated AFTER method call
522
+ if use_result
523
+ vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
524
+ else
525
+ vstack.push __send__(method_id, tmp_v, vstack)
526
+ end
527
+ tstack.push reduce_to
528
+
529
+ racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
530
+
531
+ k1 = reduce_to - nt_base
532
+ if i = goto_pointer[k1]
533
+ i += state[-1]
534
+ if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
535
+ return curstate
536
+ end
537
+ end
538
+ goto_default[k1]
539
+ end
540
+
541
+ # This method is called when a parse error is found.
542
+ #
543
+ # ERROR_TOKEN_ID is an internal ID of token which caused error.
544
+ # You can get string representation of this ID by calling
545
+ # #token_to_str.
546
+ #
547
+ # ERROR_VALUE is a value of error token.
548
+ #
549
+ # value_stack is a stack of symbol values.
550
+ # DO NOT MODIFY this object.
551
+ #
552
+ # This method raises ParseError by default.
553
+ #
554
+ # If this method returns, parsers enter "error recovering mode".
555
+ def on_error(t, val, vstack)
556
+ raise ParseError, sprintf("parse error on value %s (%s)",
557
+ val.inspect, token_to_str(t) || '?')
558
+ end
559
+
560
+ # Enter error recovering mode.
561
+ # This method does not call #on_error.
562
+ def yyerror
563
+ throw :racc_jump, 1
564
+ end
565
+
566
+ # Exit parser.
567
+ # Return value is +Symbol_Value_Stack[0]+.
568
+ def yyaccept
569
+ throw :racc_jump, 2
570
+ end
571
+
572
+ # Leave error recovering mode.
573
+ def yyerrok
574
+ @racc_error_status = 0
575
+ end
576
+
577
+ # For debugging output
578
+ def racc_read_token(t, tok, val)
579
+ @racc_debug_out.print 'read '
580
+ @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
581
+ @racc_debug_out.puts val.inspect
582
+ @racc_debug_out.puts
583
+ end
584
+
585
+ def racc_shift(tok, tstack, vstack)
586
+ @racc_debug_out.puts "shift #{racc_token2str tok}"
587
+ racc_print_stacks tstack, vstack
588
+ @racc_debug_out.puts
589
+ end
590
+
591
+ def racc_reduce(toks, sim, tstack, vstack)
592
+ out = @racc_debug_out
593
+ out.print 'reduce '
594
+ if toks.empty?
595
+ out.print ' <none>'
596
+ else
597
+ toks.each {|t| out.print ' ', racc_token2str(t) }
598
+ end
599
+ out.puts " --> #{racc_token2str(sim)}"
600
+ racc_print_stacks tstack, vstack
601
+ @racc_debug_out.puts
602
+ end
603
+
604
+ def racc_accept
605
+ @racc_debug_out.puts 'accept'
606
+ @racc_debug_out.puts
607
+ end
608
+
609
+ def racc_e_pop(state, tstack, vstack)
610
+ @racc_debug_out.puts 'error recovering mode: pop token'
611
+ racc_print_states state
612
+ racc_print_stacks tstack, vstack
613
+ @racc_debug_out.puts
614
+ end
615
+
616
+ def racc_next_state(curstate, state)
617
+ @racc_debug_out.puts "goto #{curstate}"
618
+ racc_print_states state
619
+ @racc_debug_out.puts
620
+ end
621
+
622
+ def racc_print_stacks(t, v)
623
+ out = @racc_debug_out
624
+ out.print ' ['
625
+ t.each_index do |i|
626
+ out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
627
+ end
628
+ out.puts ' ]'
629
+ end
630
+
631
+ def racc_print_states(s)
632
+ out = @racc_debug_out
633
+ out.print ' ['
634
+ s.each {|st| out.print ' ', st }
635
+ out.puts ' ]'
636
+ end
637
+
638
+ def racc_token2str(tok)
639
+ self.class::Racc_token_to_s_table[tok] or
640
+ raise "[Racc Bug] can't convert token #{tok} to string"
641
+ end
642
+
643
+ # Convert internal ID of token symbol to the string.
644
+ def token_to_str(t)
645
+ self.class::Racc_token_to_s_table[t]
646
+ end
647
+
648
+ end
649
+
650
+ end
651
+
652
+ ...end racc/parser.rb/module_eval...
653
+ end
654
+ ###### racc/parser.rb end
655
+
656
+ require 'set'
657
+
658
+ # Pre-computed sets for faster lookup
659
+ CAN_END_COMPOUND = Set[:IDENT, :STAR, :RPAREN, :RBRACKET].freeze
660
+ CAN_START_COMPOUND = Set[:IDENT, :STAR, :DOT, :HASH, :LBRACKET, :COLON].freeze
661
+ TYPE_SELECTOR_TYPES = Set[:IDENT, :STAR].freeze
662
+ SUBCLASS_SELECTOR_TYPES = Set[:DOT, :HASH, :LBRACKET, :COLON].freeze
663
+ NTH_PSEUDO_NAMES = Set['nth-child', 'nth-last-child', 'nth-of-type', 'nth-last-of-type', 'nth-col', 'nth-last-col'].freeze
664
+ AN_PLUS_B_REGEX = /^(even|odd|[+-]?\d*n(?:[+-]\d+)?|[+-]?n(?:[+-]\d+)?|\d+)$/.freeze
665
+
666
+ module Parselly
667
+ class Parser < Racc::Parser
668
+
669
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 272)
670
+ def parse(input)
671
+ @lexer = Parselly::Lexer.new(input)
672
+ @tokens = @lexer.tokenize
673
+ preprocess_tokens!
674
+ @index = 0
675
+ @current_position = { line: 1, column: 1 }
676
+ ast = do_parse
677
+ normalize_an_plus_b(ast)
678
+ ast
679
+ end
680
+
681
+ def preprocess_tokens!
682
+ return if @tokens.size <= 1
683
+
684
+ new_tokens = Array.new(@tokens.size + (@tokens.size / 2)) # Pre-allocate with conservative estimate
685
+ new_tokens_idx = 0
686
+
687
+ last_idx = @tokens.size - 1
688
+ @tokens.each_with_index do |token, i|
689
+ new_tokens[new_tokens_idx] = token
690
+ new_tokens_idx += 1
691
+
692
+ if i < last_idx
693
+ next_token = @tokens[i + 1]
694
+ if needs_descendant?(token, next_token)
695
+ pos = { line: token[2][:line], column: token[2][:column] }
696
+ new_tokens[new_tokens_idx] = [:DESCENDANT, ' ', pos]
697
+ new_tokens_idx += 1
698
+ end
699
+ end
700
+ end
701
+
702
+ @tokens = new_tokens.first(new_tokens_idx)
703
+ end
704
+
705
+ # Insert DESCENDANT combinator if:
706
+ # - Current token can end a compound selector
707
+ # - Next token can start a compound selector
708
+ # - EXCEPT when current is type_selector and next is subclass_selector
709
+ # (they belong to the same compound selector)
710
+ def needs_descendant?(current, next_tok)
711
+ current_type = current[0]
712
+ next_type = next_tok[0]
713
+
714
+ # Type selector followed by subclass selector = same compound
715
+ return false if TYPE_SELECTOR_TYPES.include?(current_type) &&
716
+ SUBCLASS_SELECTOR_TYPES.include?(next_type)
717
+
718
+ CAN_END_COMPOUND.include?(current_type) && CAN_START_COMPOUND.include?(next_type)
719
+ end
720
+
721
+ def normalize_an_plus_b(node)
722
+ return unless node.respond_to?(:children) && node.children
723
+
724
+ if node.type == :pseudo_function && NTH_PSEUDO_NAMES.include?(node.value)
725
+ child = node.children.first
726
+ if child&.type == :selector_list
727
+ an_plus_b_value = extract_an_plus_b_value(child)
728
+ if an_plus_b_value
729
+ node.replace_child(0, Node.new(:an_plus_b, an_plus_b_value, child.position))
730
+ end
731
+ end
732
+ end
733
+ node.children.compact.each { |child| normalize_an_plus_b(child) }
734
+ end
735
+
736
+ def extract_an_plus_b_value(selector_list_node)
737
+ return nil unless selector_list_node.children.size == 1
738
+
739
+ seq = selector_list_node.children.first
740
+ return nil unless seq.type == :simple_selector_sequence && seq.children.size == 1
741
+
742
+ type_sel = seq.children.first
743
+ return nil unless type_sel.type == :type_selector
744
+
745
+ value = type_sel.value
746
+ value if value =~ AN_PLUS_B_REGEX
747
+ end
748
+
749
+ def next_token
750
+ return [false, nil] if @index >= @tokens.size
751
+
752
+ token_type, token_value, token_position = @tokens[@index]
753
+ @index += 1
754
+ @current_position = token_position
755
+
756
+ [token_type, token_value]
757
+ end
758
+
759
+ def on_error(token_id, val, vstack)
760
+ token_name = token_to_str(token_id) || '?'
761
+ pos = @current_position || { line: '?', column: '?' }
762
+ raise "Parse error: unexpected #{token_name} '#{val}' at #{pos[:line]}:#{pos[:column]}"
763
+ end
764
+ ...end parser.y/module_eval...
765
+ ##### State transition tables begin ###
766
+
767
+ racc_action_table = [
768
+ 55, 57, 60, 14, 15, 8, 16, 35, 18, 67,
769
+ 17, 19, 25, 26, 27, 28, 32, 36, 68, 79,
770
+ 7, 33, 61, 14, 15, 8, 16, 43, 80, 72,
771
+ 17, 71, 25, 26, 27, 28, 45, 46, 47, 48,
772
+ 49, 50, 7, 54, 53, 14, 15, 8, 16, 34,
773
+ 7, 37, 17, 14, 15, 8, 16, 19, 7, 51,
774
+ 17, 14, 15, 8, 16, 82, 7, 52, 17, 14,
775
+ 15, 8, 16, 88, 83, 65, 17, 14, 15, 66,
776
+ 16, 69, 89, 70, 17, 14, 15, 73, 16, 77,
777
+ 78, 81, 17, 25, 26, 27, 28, 25, 26, 27,
778
+ 28, 73, 86, 87, 90, 91, 92, 93 ]
779
+
780
+ racc_action_check = [
781
+ 51, 51, 51, 51, 51, 51, 51, 17, 1, 55,
782
+ 51, 2, 51, 51, 51, 51, 14, 17, 55, 70,
783
+ 73, 15, 51, 73, 73, 73, 73, 34, 70, 61,
784
+ 73, 61, 73, 73, 73, 73, 34, 34, 34, 34,
785
+ 34, 34, 0, 44, 44, 0, 0, 0, 0, 16,
786
+ 19, 18, 0, 19, 19, 19, 19, 20, 22, 35,
787
+ 19, 22, 22, 22, 22, 72, 64, 36, 22, 64,
788
+ 64, 64, 64, 81, 72, 53, 64, 4, 4, 54,
789
+ 4, 56, 81, 60, 4, 30, 30, 62, 30, 67,
790
+ 68, 71, 30, 3, 3, 3, 3, 23, 23, 23,
791
+ 23, 74, 79, 80, 82, 83, 88, 89 ]
792
+
793
+ racc_action_pointer = [
794
+ 40, 8, -2, 79, 72, nil, nil, nil, nil, nil,
795
+ nil, nil, nil, nil, 14, 19, 47, 5, 51, 48,
796
+ 44, nil, 56, 83, nil, nil, nil, nil, nil, nil,
797
+ 80, nil, nil, nil, 18, 49, 65, nil, nil, nil,
798
+ nil, nil, nil, nil, 41, nil, nil, nil, nil, nil,
799
+ nil, -2, nil, 66, 70, -6, 70, nil, nil, nil,
800
+ 81, 27, 74, nil, 64, nil, nil, 85, 86, nil,
801
+ 4, 89, 50, 18, 88, nil, nil, nil, nil, 98,
802
+ 99, 58, 100, 101, nil, nil, nil, nil, 102, 103,
803
+ nil, nil, nil, nil ]
804
+
805
+ racc_action_default = [
806
+ -61, -61, -2, -6, -16, -14, -15, -19, -20, -21,
807
+ -22, -23, -24, -25, -61, -61, -61, -61, -61, -61,
808
+ -2, -4, -61, -6, -8, -9, -10, -11, -12, -13,
809
+ -16, -18, -26, -27, -61, -37, -61, 94, -1, -3,
810
+ -5, -7, -17, -28, -61, -31, -32, -33, -34, -35,
811
+ -36, -61, -39, -61, -61, -19, -61, -40, -41, -42,
812
+ -54, -61, -56, -59, -61, -29, -30, -61, -61, -38,
813
+ -45, -61, -53, -61, -56, -58, -60, -46, -47, -61,
814
+ -61, -50, -61, -61, -55, -57, -43, -44, -61, -61,
815
+ -51, -52, -48, -49 ]
816
+
817
+ racc_goto_table = [
818
+ 2, 30, 31, 64, 62, 21, 75, 1, 40, 24,
819
+ 29, 44, 56, 58, 59, nil, nil, nil, 85, 38,
820
+ nil, nil, nil, 39, nil, 64, 84, 30, 42, 41,
821
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
822
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
823
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
824
+ nil, nil, nil, nil, 76 ]
825
+
826
+ racc_goto_check = [
827
+ 2, 12, 13, 6, 23, 4, 25, 1, 5, 8,
828
+ 10, 19, 20, 21, 22, nil, nil, nil, 25, 2,
829
+ nil, nil, nil, 4, nil, 6, 23, 12, 13, 8,
830
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
831
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
832
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
833
+ nil, nil, nil, nil, 2 ]
834
+
835
+ racc_goto_pointer = [
836
+ nil, 7, 0, nil, 3, -14, -48, nil, 6, nil,
837
+ 6, nil, -3, -2, nil, nil, nil, nil, nil, -23,
838
+ -39, -38, -37, -47, nil, -56 ]
839
+
840
+ racc_goto_default = [
841
+ nil, nil, 63, 20, nil, 3, 22, 23, nil, 4,
842
+ nil, 5, 6, nil, 9, 10, 11, 12, 13, nil,
843
+ nil, nil, nil, nil, 74, nil ]
844
+
845
+ racc_reduce_table = [
846
+ 0, 0, :racc_error,
847
+ 2, 29, :_reduce_1,
848
+ 0, 30, :_reduce_2,
849
+ 2, 30, :_reduce_3,
850
+ 2, 27, :_reduce_4,
851
+ 2, 33, :_reduce_5,
852
+ 0, 34, :_reduce_6,
853
+ 2, 34, :_reduce_7,
854
+ 2, 28, :_reduce_8,
855
+ 1, 32, :_reduce_9,
856
+ 1, 32, :_reduce_10,
857
+ 1, 32, :_reduce_11,
858
+ 1, 32, :_reduce_12,
859
+ 2, 31, :_reduce_13,
860
+ 1, 35, :_reduce_14,
861
+ 1, 35, :_reduce_15,
862
+ 0, 39, :_reduce_16,
863
+ 2, 39, :_reduce_17,
864
+ 1, 36, :_reduce_18,
865
+ 1, 37, :_reduce_19,
866
+ 1, 37, :_reduce_20,
867
+ 1, 38, :_reduce_21,
868
+ 1, 38, :_reduce_22,
869
+ 1, 38, :_reduce_23,
870
+ 1, 38, :_reduce_24,
871
+ 1, 38, :_reduce_25,
872
+ 2, 40, :_reduce_26,
873
+ 2, 41, :_reduce_27,
874
+ 3, 42, :_reduce_28,
875
+ 5, 42, :_reduce_29,
876
+ 5, 42, :_reduce_30,
877
+ 1, 45, :_reduce_31,
878
+ 1, 45, :_reduce_32,
879
+ 1, 45, :_reduce_33,
880
+ 1, 45, :_reduce_34,
881
+ 1, 45, :_reduce_35,
882
+ 1, 45, :_reduce_36,
883
+ 2, 43, :_reduce_37,
884
+ 5, 43, :_reduce_38,
885
+ 3, 44, :_reduce_39,
886
+ 1, 46, :_reduce_40,
887
+ 1, 46, :_reduce_41,
888
+ 1, 46, :_reduce_42,
889
+ 4, 47, :_reduce_43,
890
+ 4, 47, :_reduce_44,
891
+ 2, 47, :_reduce_45,
892
+ 3, 47, :_reduce_46,
893
+ 3, 47, :_reduce_47,
894
+ 5, 47, :_reduce_48,
895
+ 5, 47, :_reduce_49,
896
+ 3, 47, :_reduce_50,
897
+ 4, 47, :_reduce_51,
898
+ 4, 47, :_reduce_52,
899
+ 2, 47, :_reduce_53,
900
+ 1, 47, :_reduce_54,
901
+ 2, 50, :_reduce_55,
902
+ 0, 51, :_reduce_56,
903
+ 2, 51, :_reduce_57,
904
+ 2, 48, :_reduce_58,
905
+ 1, 49, :_reduce_59,
906
+ 2, 49, :_reduce_60 ]
907
+
908
+ racc_reduce_n = 61
909
+
910
+ racc_shift_n = 94
911
+
912
+ racc_token_table = {
913
+ false => 0,
914
+ :error => 1,
915
+ :IDENT => 2,
916
+ :STRING => 3,
917
+ :NUMBER => 4,
918
+ :HASH => 5,
919
+ :DOT => 6,
920
+ :STAR => 7,
921
+ :LBRACKET => 8,
922
+ :RBRACKET => 9,
923
+ :LPAREN => 10,
924
+ :RPAREN => 11,
925
+ :COLON => 12,
926
+ :COMMA => 13,
927
+ :CHILD => 14,
928
+ :ADJACENT => 15,
929
+ :SIBLING => 16,
930
+ :DESCENDANT => 17,
931
+ :EQUAL => 18,
932
+ :INCLUDES => 19,
933
+ :DASHMATCH => 20,
934
+ :PREFIXMATCH => 21,
935
+ :SUFFIXMATCH => 22,
936
+ :SUBSTRINGMATCH => 23,
937
+ :MINUS => 24,
938
+ "-temp-group" => 25 }
939
+
940
+ racc_nt_base = 26
941
+
942
+ racc_use_result_var = true
943
+
944
+ Racc_arg = [
945
+ racc_action_table,
946
+ racc_action_check,
947
+ racc_action_default,
948
+ racc_action_pointer,
949
+ racc_goto_table,
950
+ racc_goto_check,
951
+ racc_goto_default,
952
+ racc_goto_pointer,
953
+ racc_nt_base,
954
+ racc_reduce_table,
955
+ racc_token_table,
956
+ racc_shift_n,
957
+ racc_reduce_n,
958
+ racc_use_result_var ]
959
+ Ractor.make_shareable(Racc_arg) if defined?(Ractor)
960
+
961
+ Racc_token_to_s_table = [
962
+ "$end",
963
+ "error",
964
+ "IDENT",
965
+ "STRING",
966
+ "NUMBER",
967
+ "HASH",
968
+ "DOT",
969
+ "STAR",
970
+ "LBRACKET",
971
+ "RBRACKET",
972
+ "LPAREN",
973
+ "RPAREN",
974
+ "COLON",
975
+ "COMMA",
976
+ "CHILD",
977
+ "ADJACENT",
978
+ "SIBLING",
979
+ "DESCENDANT",
980
+ "EQUAL",
981
+ "INCLUDES",
982
+ "DASHMATCH",
983
+ "PREFIXMATCH",
984
+ "SUFFIXMATCH",
985
+ "SUBSTRINGMATCH",
986
+ "MINUS",
987
+ "\"-temp-group\"",
988
+ "$start",
989
+ "selector_list",
990
+ "complex_selector",
991
+ "\"-group@COMMA-complex_selector\"",
992
+ "\"-many@-group@COMMA-complex_selector\"",
993
+ "compound_selector",
994
+ "combinator",
995
+ "\"-group@combinator-compound_selector\"",
996
+ "\"-many@-group@combinator-compound_selector\"",
997
+ "simple_selector_head",
998
+ "simple_selector_tail",
999
+ "type_selector",
1000
+ "subclass_selector",
1001
+ "\"-many@subclass_selector\"",
1002
+ "id_selector",
1003
+ "class_selector",
1004
+ "attribute_selector",
1005
+ "pseudo_class_selector",
1006
+ "pseudo_element_selector",
1007
+ "attr_matcher",
1008
+ "any_value",
1009
+ "an_plus_b",
1010
+ "relative_selector_list",
1011
+ "relative_selector",
1012
+ "\"-group@COMMA-relative_selector\"",
1013
+ "\"-many@-group@COMMA-relative_selector\"" ]
1014
+ Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
1015
+
1016
+ Racc_debug_parser = true
1017
+
1018
+ ##### State transition tables end #####
1019
+
1020
+ # reduce 0 omitted
1021
+
1022
+ module_eval(<<'.,.,', 'parser.y', 31)
1023
+ def _reduce_1(val, _values, result)
1024
+ result = val
1025
+ result
1026
+ end
1027
+ .,.,
1028
+
1029
+ module_eval(<<'.,.,', 'parser.y', 31)
1030
+ def _reduce_2(val, _values, result)
1031
+ result = val[1] ? val[1].unshift(val[0]) : val
1032
+ result
1033
+ end
1034
+ .,.,
1035
+
1036
+ module_eval(<<'.,.,', 'parser.y', 31)
1037
+ def _reduce_3(val, _values, result)
1038
+ result = val[1] ? val[1].unshift(val[0]) : val
1039
+ result
1040
+ end
1041
+ .,.,
1042
+
1043
+ module_eval(<<'.,.,', 'parser.y', 26)
1044
+ def _reduce_4(val, _values, result)
1045
+ result = Node.new(:selector_list, nil, @current_position)
1046
+ result.add_child(val[0])
1047
+ val[1].each { |pair| result.add_child(pair[1]) }
1048
+
1049
+ result
1050
+ end
1051
+ .,.,
1052
+
1053
+ module_eval(<<'.,.,', 'parser.y', 49)
1054
+ def _reduce_5(val, _values, result)
1055
+ result = val
1056
+ result
1057
+ end
1058
+ .,.,
1059
+
1060
+ module_eval(<<'.,.,', 'parser.y', 49)
1061
+ def _reduce_6(val, _values, result)
1062
+ result = val[1] ? val[1].unshift(val[0]) : val
1063
+ result
1064
+ end
1065
+ .,.,
1066
+
1067
+ module_eval(<<'.,.,', 'parser.y', 49)
1068
+ def _reduce_7(val, _values, result)
1069
+ result = val[1] ? val[1].unshift(val[0]) : val
1070
+ result
1071
+ end
1072
+ .,.,
1073
+
1074
+ module_eval(<<'.,.,', 'parser.y', 35)
1075
+ def _reduce_8(val, _values, result)
1076
+ if val[1].empty?
1077
+ result = val[0]
1078
+ else
1079
+ result = val[0]
1080
+ val[1].each do |pair|
1081
+ node = Node.new(:selector, nil, result.position)
1082
+ node.add_child(result)
1083
+ node.add_child(pair[0])
1084
+ node.add_child(pair[1])
1085
+ result = node
1086
+ end
1087
+ end
1088
+
1089
+ result
1090
+ end
1091
+ .,.,
1092
+
1093
+ module_eval(<<'.,.,', 'parser.y', 52)
1094
+ def _reduce_9(val, _values, result)
1095
+ result = Node.new(:child_combinator, '>', @current_position)
1096
+ result
1097
+ end
1098
+ .,.,
1099
+
1100
+ module_eval(<<'.,.,', 'parser.y', 54)
1101
+ def _reduce_10(val, _values, result)
1102
+ result = Node.new(:adjacent_combinator, '+', @current_position)
1103
+ result
1104
+ end
1105
+ .,.,
1106
+
1107
+ module_eval(<<'.,.,', 'parser.y', 56)
1108
+ def _reduce_11(val, _values, result)
1109
+ result = Node.new(:sibling_combinator, '~', @current_position)
1110
+ result
1111
+ end
1112
+ .,.,
1113
+
1114
+ module_eval(<<'.,.,', 'parser.y', 58)
1115
+ def _reduce_12(val, _values, result)
1116
+ result = Node.new(:descendant_combinator, ' ', @current_position)
1117
+ result
1118
+ end
1119
+ .,.,
1120
+
1121
+ module_eval(<<'.,.,', 'parser.y', 64)
1122
+ def _reduce_13(val, _values, result)
1123
+ result = Node.new(:simple_selector_sequence, nil, val[0].position)
1124
+ result.add_child(val[0])
1125
+ val[1].each { |sel| result.add_child(sel) } unless val[1].empty?
1126
+
1127
+ result
1128
+ end
1129
+ .,.,
1130
+
1131
+ module_eval(<<'.,.,', 'parser.y', 72)
1132
+ def _reduce_14(val, _values, result)
1133
+ result = val[0]
1134
+ result
1135
+ end
1136
+ .,.,
1137
+
1138
+ module_eval(<<'.,.,', 'parser.y', 74)
1139
+ def _reduce_15(val, _values, result)
1140
+ result = val[0]
1141
+ result
1142
+ end
1143
+ .,.,
1144
+
1145
+ module_eval(<<'.,.,', 'parser.y', 81)
1146
+ def _reduce_16(val, _values, result)
1147
+ result = val[1] ? val[1].unshift(val[0]) : val
1148
+ result
1149
+ end
1150
+ .,.,
1151
+
1152
+ module_eval(<<'.,.,', 'parser.y', 81)
1153
+ def _reduce_17(val, _values, result)
1154
+ result = val[1] ? val[1].unshift(val[0]) : val
1155
+ result
1156
+ end
1157
+ .,.,
1158
+
1159
+ module_eval(<<'.,.,', 'parser.y', 79)
1160
+ def _reduce_18(val, _values, result)
1161
+ result = val[0]
1162
+ result
1163
+ end
1164
+ .,.,
1165
+
1166
+ module_eval(<<'.,.,', 'parser.y', 84)
1167
+ def _reduce_19(val, _values, result)
1168
+ result = Node.new(:type_selector, val[0], @current_position)
1169
+ result
1170
+ end
1171
+ .,.,
1172
+
1173
+ module_eval(<<'.,.,', 'parser.y', 86)
1174
+ def _reduce_20(val, _values, result)
1175
+ result = Node.new(:universal_selector, '*', @current_position)
1176
+ result
1177
+ end
1178
+ .,.,
1179
+
1180
+ module_eval(<<'.,.,', 'parser.y', 91)
1181
+ def _reduce_21(val, _values, result)
1182
+ result = val[0]
1183
+ result
1184
+ end
1185
+ .,.,
1186
+
1187
+ module_eval(<<'.,.,', 'parser.y', 93)
1188
+ def _reduce_22(val, _values, result)
1189
+ result = val[0]
1190
+ result
1191
+ end
1192
+ .,.,
1193
+
1194
+ module_eval(<<'.,.,', 'parser.y', 95)
1195
+ def _reduce_23(val, _values, result)
1196
+ result = val[0]
1197
+ result
1198
+ end
1199
+ .,.,
1200
+
1201
+ module_eval(<<'.,.,', 'parser.y', 97)
1202
+ def _reduce_24(val, _values, result)
1203
+ result = val[0]
1204
+ result
1205
+ end
1206
+ .,.,
1207
+
1208
+ module_eval(<<'.,.,', 'parser.y', 99)
1209
+ def _reduce_25(val, _values, result)
1210
+ result = val[0]
1211
+ result
1212
+ end
1213
+ .,.,
1214
+
1215
+ module_eval(<<'.,.,', 'parser.y', 104)
1216
+ def _reduce_26(val, _values, result)
1217
+ result = Node.new(:id_selector, val[1], @current_position)
1218
+ result
1219
+ end
1220
+ .,.,
1221
+
1222
+ module_eval(<<'.,.,', 'parser.y', 109)
1223
+ def _reduce_27(val, _values, result)
1224
+ result = Node.new(:class_selector, val[1], @current_position)
1225
+ result
1226
+ end
1227
+ .,.,
1228
+
1229
+ module_eval(<<'.,.,', 'parser.y', 114)
1230
+ def _reduce_28(val, _values, result)
1231
+ result = Node.new(:attribute_selector, val[1], @current_position)
1232
+ result
1233
+ end
1234
+ .,.,
1235
+
1236
+ module_eval(<<'.,.,', 'parser.y', 117)
1237
+ def _reduce_29(val, _values, result)
1238
+ result = Node.new(:attribute_selector, nil, @current_position)
1239
+ result.add_child(Node.new(:attribute, val[1], @current_position))
1240
+ result.add_child(val[2])
1241
+ result.add_child(Node.new(:value, val[3], @current_position))
1242
+
1243
+ result
1244
+ end
1245
+ .,.,
1246
+
1247
+ module_eval(<<'.,.,', 'parser.y', 124)
1248
+ def _reduce_30(val, _values, result)
1249
+ result = Node.new(:attribute_selector, nil, @current_position)
1250
+ result.add_child(Node.new(:attribute, val[1], @current_position))
1251
+ result.add_child(val[2])
1252
+ result.add_child(Node.new(:value, val[3], @current_position))
1253
+
1254
+ result
1255
+ end
1256
+ .,.,
1257
+
1258
+ module_eval(<<'.,.,', 'parser.y', 133)
1259
+ def _reduce_31(val, _values, result)
1260
+ result = Node.new(:equal_operator, '=', @current_position)
1261
+ result
1262
+ end
1263
+ .,.,
1264
+
1265
+ module_eval(<<'.,.,', 'parser.y', 135)
1266
+ def _reduce_32(val, _values, result)
1267
+ result = Node.new(:includes_operator, '~=', @current_position)
1268
+ result
1269
+ end
1270
+ .,.,
1271
+
1272
+ module_eval(<<'.,.,', 'parser.y', 137)
1273
+ def _reduce_33(val, _values, result)
1274
+ result = Node.new(:dashmatch_operator, '|=', @current_position)
1275
+ result
1276
+ end
1277
+ .,.,
1278
+
1279
+ module_eval(<<'.,.,', 'parser.y', 139)
1280
+ def _reduce_34(val, _values, result)
1281
+ result = Node.new(:prefixmatch_operator, '^=', @current_position)
1282
+ result
1283
+ end
1284
+ .,.,
1285
+
1286
+ module_eval(<<'.,.,', 'parser.y', 141)
1287
+ def _reduce_35(val, _values, result)
1288
+ result = Node.new(:suffixmatch_operator, '$=', @current_position)
1289
+ result
1290
+ end
1291
+ .,.,
1292
+
1293
+ module_eval(<<'.,.,', 'parser.y', 143)
1294
+ def _reduce_36(val, _values, result)
1295
+ result = Node.new(:substringmatch_operator, '*=', @current_position)
1296
+ result
1297
+ end
1298
+ .,.,
1299
+
1300
+ module_eval(<<'.,.,', 'parser.y', 148)
1301
+ def _reduce_37(val, _values, result)
1302
+ result = Node.new(:pseudo_class, val[1], @current_position)
1303
+ result
1304
+ end
1305
+ .,.,
1306
+
1307
+ module_eval(<<'.,.,', 'parser.y', 151)
1308
+ def _reduce_38(val, _values, result)
1309
+ fn = Node.new(:pseudo_function, val[1], @current_position)
1310
+ fn.add_child(val[3])
1311
+ result = fn
1312
+
1313
+ result
1314
+ end
1315
+ .,.,
1316
+
1317
+ module_eval(<<'.,.,', 'parser.y', 159)
1318
+ def _reduce_39(val, _values, result)
1319
+ result = Node.new(:pseudo_element, val[2], @current_position)
1320
+ result
1321
+ end
1322
+ .,.,
1323
+
1324
+ module_eval(<<'.,.,', 'parser.y', 164)
1325
+ def _reduce_40(val, _values, result)
1326
+ result = Node.new(:argument, val[0], @current_position)
1327
+ result
1328
+ end
1329
+ .,.,
1330
+
1331
+ module_eval(<<'.,.,', 'parser.y', 166)
1332
+ def _reduce_41(val, _values, result)
1333
+ result = val[0]
1334
+ result
1335
+ end
1336
+ .,.,
1337
+
1338
+ module_eval(<<'.,.,', 'parser.y', 168)
1339
+ def _reduce_42(val, _values, result)
1340
+ result = val[0]
1341
+ result
1342
+ end
1343
+ .,.,
1344
+
1345
+ module_eval(<<'.,.,', 'parser.y', 175)
1346
+ def _reduce_43(val, _values, result)
1347
+ # Handle 'An+B' like '2n+1'
1348
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}+#{val[3]}", @current_position)
1349
+
1350
+ result
1351
+ end
1352
+ .,.,
1353
+
1354
+ module_eval(<<'.,.,', 'parser.y', 180)
1355
+ def _reduce_44(val, _values, result)
1356
+ # Handle 'An-B' like '2n-1'
1357
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}-#{val[3]}", @current_position)
1358
+
1359
+ result
1360
+ end
1361
+ .,.,
1362
+
1363
+ module_eval(<<'.,.,', 'parser.y', 185)
1364
+ def _reduce_45(val, _values, result)
1365
+ # Handle 'An' like '2n' or composite like '2n-1' (when '-1' is part of IDENT)
1366
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}", @current_position)
1367
+
1368
+ result
1369
+ end
1370
+ .,.,
1371
+
1372
+ module_eval(<<'.,.,', 'parser.y', 190)
1373
+ def _reduce_46(val, _values, result)
1374
+ # Handle 'n+B' like 'n+5' or keywords followed by offset (rare but valid)
1375
+ result = Node.new(:an_plus_b, "#{val[0]}+#{val[2]}", @current_position)
1376
+
1377
+ result
1378
+ end
1379
+ .,.,
1380
+
1381
+ module_eval(<<'.,.,', 'parser.y', 195)
1382
+ def _reduce_47(val, _values, result)
1383
+ # Handle 'n-B' like 'n-3'
1384
+ result = Node.new(:an_plus_b, "#{val[0]}-#{val[2]}", @current_position)
1385
+
1386
+ result
1387
+ end
1388
+ .,.,
1389
+
1390
+ module_eval(<<'.,.,', 'parser.y', 201)
1391
+ def _reduce_48(val, _values, result)
1392
+ # Handle '-An+B' like '-2n+1'
1393
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}+#{val[4]}", @current_position)
1394
+
1395
+ result
1396
+ end
1397
+ .,.,
1398
+
1399
+ module_eval(<<'.,.,', 'parser.y', 206)
1400
+ def _reduce_49(val, _values, result)
1401
+ # Handle '-An-B' like '-2n-1'
1402
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}-#{val[4]}", @current_position)
1403
+
1404
+ result
1405
+ end
1406
+ .,.,
1407
+
1408
+ module_eval(<<'.,.,', 'parser.y', 211)
1409
+ def _reduce_50(val, _values, result)
1410
+ # Handle '-An' like '-2n' or composite like '-2n+1' (when '+1' is part of IDENT)
1411
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}", @current_position)
1412
+
1413
+ result
1414
+ end
1415
+ .,.,
1416
+
1417
+ module_eval(<<'.,.,', 'parser.y', 216)
1418
+ def _reduce_51(val, _values, result)
1419
+ # Handle '-n+B' like '-n+3'
1420
+ result = Node.new(:an_plus_b, "-#{val[1]}+#{val[3]}", @current_position)
1421
+
1422
+ result
1423
+ end
1424
+ .,.,
1425
+
1426
+ module_eval(<<'.,.,', 'parser.y', 221)
1427
+ def _reduce_52(val, _values, result)
1428
+ # Handle '-n-B' like '-n-2'
1429
+ result = Node.new(:an_plus_b, "-#{val[1]}-#{val[3]}", @current_position)
1430
+
1431
+ result
1432
+ end
1433
+ .,.,
1434
+
1435
+ module_eval(<<'.,.,', 'parser.y', 226)
1436
+ def _reduce_53(val, _values, result)
1437
+ # Handle '-n' or composite like '-n+3' (when '+3' is part of IDENT)
1438
+ result = Node.new(:an_plus_b, "-#{val[1]}", @current_position)
1439
+
1440
+ result
1441
+ end
1442
+ .,.,
1443
+
1444
+ module_eval(<<'.,.,', 'parser.y', 232)
1445
+ def _reduce_54(val, _values, result)
1446
+ # Handle just a number like '3'
1447
+ result = Node.new(:an_plus_b, val[0].to_s, @current_position)
1448
+
1449
+ result
1450
+ end
1451
+ .,.,
1452
+
1453
+ module_eval(<<'.,.,', 'parser.y', 245)
1454
+ def _reduce_55(val, _values, result)
1455
+ result = val
1456
+ result
1457
+ end
1458
+ .,.,
1459
+
1460
+ module_eval(<<'.,.,', 'parser.y', 245)
1461
+ def _reduce_56(val, _values, result)
1462
+ result = val[1] ? val[1].unshift(val[0]) : val
1463
+ result
1464
+ end
1465
+ .,.,
1466
+
1467
+ module_eval(<<'.,.,', 'parser.y', 245)
1468
+ def _reduce_57(val, _values, result)
1469
+ result = val[1] ? val[1].unshift(val[0]) : val
1470
+ result
1471
+ end
1472
+ .,.,
1473
+
1474
+ module_eval(<<'.,.,', 'parser.y', 240)
1475
+ def _reduce_58(val, _values, result)
1476
+ result = Node.new(:selector_list, nil, @current_position)
1477
+ result.add_child(val[0])
1478
+ val[1].each { |pair| result.add_child(pair[1]) }
1479
+
1480
+ result
1481
+ end
1482
+ .,.,
1483
+
1484
+ module_eval(<<'.,.,', 'parser.y', 248)
1485
+ def _reduce_59(val, _values, result)
1486
+ result = val[0]
1487
+ result
1488
+ end
1489
+ .,.,
1490
+
1491
+ module_eval(<<'.,.,', 'parser.y', 251)
1492
+ def _reduce_60(val, _values, result)
1493
+ result = Node.new(:selector, nil, val[0].position)
1494
+ result.add_child(val[0])
1495
+ result.add_child(val[1])
1496
+
1497
+ result
1498
+ end
1499
+ .,.,
1500
+
1501
+ def _reduce_none(val, _values, result)
1502
+ val[0]
1503
+ end
1504
+
1505
+ end # class Parser
1506
+ end # module Parselly