parselly 0.1.0 → 1.0.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,1513 @@
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
+
657
+ module Parselly
658
+ class Parser < Racc::Parser
659
+
660
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 263)
661
+ def parse(input)
662
+ @lexer = Parselly::Lexer.new(input)
663
+ @tokens = @lexer.tokenize
664
+ preprocess_tokens!
665
+ @index = 0
666
+ @current_position = { line: 1, column: 1 }
667
+ ast = do_parse
668
+ normalize_an_plus_b(ast)
669
+ ast
670
+ end
671
+
672
+ def preprocess_tokens!
673
+ new_tokens = []
674
+ i = 0
675
+ while i < @tokens.size
676
+ token = @tokens[i]
677
+ next_token = @tokens[i + 1]
678
+ new_tokens << token
679
+ if next_token && needs_descendant?(token, next_token)
680
+ pos = { line: token[2][:line], column: token[2][:column] }
681
+ new_tokens << [:DESCENDANT, ' ', pos]
682
+ end
683
+ i += 1
684
+ end
685
+
686
+ @tokens = new_tokens
687
+ end
688
+
689
+ # Insert DESCENDANT combinator if:
690
+ # - Current token can end a compound selector
691
+ # - Next token can start a compound selector
692
+ # - EXCEPT when current is type_selector and next is subclass_selector
693
+ # (they belong to the same compound selector)
694
+ def needs_descendant?(current, next_tok)
695
+ current_type = current[0]
696
+ next_type = next_tok[0]
697
+
698
+ can_end = can_end_compound?(current_type)
699
+ can_start = can_start_compound?(next_type)
700
+
701
+ # Type selector followed by subclass selector = same compound
702
+ if [:IDENT, :STAR].include?(current_type) &&
703
+ [:DOT, :HASH, :LBRACKET, :COLON].include?(next_type)
704
+ return false
705
+ end
706
+
707
+ can_end && can_start
708
+ end
709
+
710
+ def can_end_compound?(token_type)
711
+ [:IDENT, :STAR, :RPAREN, :RBRACKET].include?(token_type)
712
+ end
713
+
714
+ def can_start_compound?(token_type)
715
+ # Type selectors and subclass selectors can start a compound selector
716
+ [:IDENT, :STAR, :DOT, :HASH, :LBRACKET, :COLON].include?(token_type)
717
+ end
718
+
719
+ def normalize_an_plus_b(node)
720
+ return unless node.respond_to?(:children) && node.children
721
+
722
+ if node.type == :pseudo_function && nth_pseudo?(node.value)
723
+ child = node.children.first
724
+ if child && child.type == :selector_list
725
+ an_plus_b_value = extract_an_plus_b_value(child)
726
+ if an_plus_b_value
727
+ node.children[0] = Node.new(:an_plus_b, an_plus_b_value, child.position)
728
+ end
729
+ end
730
+ end
731
+ node.children.compact.each { |child| normalize_an_plus_b(child) }
732
+ end
733
+
734
+ def nth_pseudo?(name)
735
+ %w[nth-child nth-last-child nth-of-type nth-last-of-type nth-col nth-last-col].include?(name)
736
+ end
737
+
738
+ def extract_an_plus_b_value(selector_list_node)
739
+ return nil unless selector_list_node.children.size == 1
740
+
741
+ seq = selector_list_node.children.first
742
+ return nil unless seq.type == :simple_selector_sequence
743
+ return nil unless seq.children.size == 1
744
+
745
+ type_sel = seq.children.first
746
+ return nil unless type_sel.type == :type_selector
747
+
748
+ value = type_sel.value
749
+ if value =~ /^(even|odd|[+-]?\d*n(?:[+-]\d+)?|[+-]?n(?:[+-]\d+)?|\d+)$/
750
+ value
751
+ else
752
+ nil
753
+ end
754
+ end
755
+
756
+ def next_token
757
+ return [false, nil] if @index >= @tokens.size
758
+
759
+ token_type, token_value, token_position = @tokens[@index]
760
+ @index += 1
761
+ @current_position = token_position
762
+
763
+ [token_type, token_value]
764
+ end
765
+
766
+ def on_error(token_id, val, vstack)
767
+ token_name = token_to_str(token_id) || '?'
768
+ pos = @current_position || { line: '?', column: '?' }
769
+ raise "Parse error: unexpected #{token_name} '#{val}' at #{pos[:line]}:#{pos[:column]}"
770
+ end
771
+ ...end parser.y/module_eval...
772
+ ##### State transition tables begin ###
773
+
774
+ racc_action_table = [
775
+ 55, 57, 60, 14, 15, 8, 16, 35, 18, 67,
776
+ 17, 19, 25, 26, 27, 28, 32, 36, 68, 79,
777
+ 7, 33, 61, 14, 15, 8, 16, 43, 80, 72,
778
+ 17, 71, 25, 26, 27, 28, 45, 46, 47, 48,
779
+ 49, 50, 7, 54, 53, 14, 15, 8, 16, 34,
780
+ 7, 37, 17, 14, 15, 8, 16, 19, 7, 51,
781
+ 17, 14, 15, 8, 16, 82, 7, 52, 17, 14,
782
+ 15, 8, 16, 88, 83, 65, 17, 14, 15, 66,
783
+ 16, 69, 89, 70, 17, 14, 15, 73, 16, 77,
784
+ 78, 81, 17, 25, 26, 27, 28, 25, 26, 27,
785
+ 28, 73, 86, 87, 90, 91, 92, 93 ]
786
+
787
+ racc_action_check = [
788
+ 51, 51, 51, 51, 51, 51, 51, 17, 1, 55,
789
+ 51, 2, 51, 51, 51, 51, 14, 17, 55, 70,
790
+ 73, 15, 51, 73, 73, 73, 73, 34, 70, 61,
791
+ 73, 61, 73, 73, 73, 73, 34, 34, 34, 34,
792
+ 34, 34, 0, 44, 44, 0, 0, 0, 0, 16,
793
+ 19, 18, 0, 19, 19, 19, 19, 20, 22, 35,
794
+ 19, 22, 22, 22, 22, 72, 64, 36, 22, 64,
795
+ 64, 64, 64, 81, 72, 53, 64, 4, 4, 54,
796
+ 4, 56, 81, 60, 4, 30, 30, 62, 30, 67,
797
+ 68, 71, 30, 3, 3, 3, 3, 23, 23, 23,
798
+ 23, 74, 79, 80, 82, 83, 88, 89 ]
799
+
800
+ racc_action_pointer = [
801
+ 40, 8, -2, 79, 72, nil, nil, nil, nil, nil,
802
+ nil, nil, nil, nil, 14, 19, 47, 5, 51, 48,
803
+ 44, nil, 56, 83, nil, nil, nil, nil, nil, nil,
804
+ 80, nil, nil, nil, 18, 49, 65, nil, nil, nil,
805
+ nil, nil, nil, nil, 41, nil, nil, nil, nil, nil,
806
+ nil, -2, nil, 66, 70, -6, 70, nil, nil, nil,
807
+ 81, 27, 74, nil, 64, nil, nil, 85, 86, nil,
808
+ 4, 89, 50, 18, 88, nil, nil, nil, nil, 98,
809
+ 99, 58, 100, 101, nil, nil, nil, nil, 102, 103,
810
+ nil, nil, nil, nil ]
811
+
812
+ racc_action_default = [
813
+ -61, -61, -2, -6, -16, -14, -15, -19, -20, -21,
814
+ -22, -23, -24, -25, -61, -61, -61, -61, -61, -61,
815
+ -2, -4, -61, -6, -8, -9, -10, -11, -12, -13,
816
+ -16, -18, -26, -27, -61, -37, -61, 94, -1, -3,
817
+ -5, -7, -17, -28, -61, -31, -32, -33, -34, -35,
818
+ -36, -61, -39, -61, -61, -19, -61, -40, -41, -42,
819
+ -54, -61, -56, -59, -61, -29, -30, -61, -61, -38,
820
+ -45, -61, -53, -61, -56, -58, -60, -46, -47, -61,
821
+ -61, -50, -61, -61, -55, -57, -43, -44, -61, -61,
822
+ -51, -52, -48, -49 ]
823
+
824
+ racc_goto_table = [
825
+ 2, 30, 31, 64, 62, 21, 75, 1, 40, 24,
826
+ 29, 44, 56, 58, 59, nil, nil, nil, 85, 38,
827
+ nil, nil, nil, 39, nil, 64, 84, 30, 42, 41,
828
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
829
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
830
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
831
+ nil, nil, nil, nil, 76 ]
832
+
833
+ racc_goto_check = [
834
+ 2, 12, 13, 6, 23, 4, 25, 1, 5, 8,
835
+ 10, 19, 20, 21, 22, nil, nil, nil, 25, 2,
836
+ nil, nil, nil, 4, nil, 6, 23, 12, 13, 8,
837
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
838
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
839
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
840
+ nil, nil, nil, nil, 2 ]
841
+
842
+ racc_goto_pointer = [
843
+ nil, 7, 0, nil, 3, -14, -48, nil, 6, nil,
844
+ 6, nil, -3, -2, nil, nil, nil, nil, nil, -23,
845
+ -39, -38, -37, -47, nil, -56 ]
846
+
847
+ racc_goto_default = [
848
+ nil, nil, 63, 20, nil, 3, 22, 23, nil, 4,
849
+ nil, 5, 6, nil, 9, 10, 11, 12, 13, nil,
850
+ nil, nil, nil, nil, 74, nil ]
851
+
852
+ racc_reduce_table = [
853
+ 0, 0, :racc_error,
854
+ 2, 29, :_reduce_1,
855
+ 0, 30, :_reduce_2,
856
+ 2, 30, :_reduce_3,
857
+ 2, 27, :_reduce_4,
858
+ 2, 33, :_reduce_5,
859
+ 0, 34, :_reduce_6,
860
+ 2, 34, :_reduce_7,
861
+ 2, 28, :_reduce_8,
862
+ 1, 32, :_reduce_9,
863
+ 1, 32, :_reduce_10,
864
+ 1, 32, :_reduce_11,
865
+ 1, 32, :_reduce_12,
866
+ 2, 31, :_reduce_13,
867
+ 1, 35, :_reduce_14,
868
+ 1, 35, :_reduce_15,
869
+ 0, 39, :_reduce_16,
870
+ 2, 39, :_reduce_17,
871
+ 1, 36, :_reduce_18,
872
+ 1, 37, :_reduce_19,
873
+ 1, 37, :_reduce_20,
874
+ 1, 38, :_reduce_21,
875
+ 1, 38, :_reduce_22,
876
+ 1, 38, :_reduce_23,
877
+ 1, 38, :_reduce_24,
878
+ 1, 38, :_reduce_25,
879
+ 2, 40, :_reduce_26,
880
+ 2, 41, :_reduce_27,
881
+ 3, 42, :_reduce_28,
882
+ 5, 42, :_reduce_29,
883
+ 5, 42, :_reduce_30,
884
+ 1, 45, :_reduce_31,
885
+ 1, 45, :_reduce_32,
886
+ 1, 45, :_reduce_33,
887
+ 1, 45, :_reduce_34,
888
+ 1, 45, :_reduce_35,
889
+ 1, 45, :_reduce_36,
890
+ 2, 43, :_reduce_37,
891
+ 5, 43, :_reduce_38,
892
+ 3, 44, :_reduce_39,
893
+ 1, 46, :_reduce_40,
894
+ 1, 46, :_reduce_41,
895
+ 1, 46, :_reduce_42,
896
+ 4, 47, :_reduce_43,
897
+ 4, 47, :_reduce_44,
898
+ 2, 47, :_reduce_45,
899
+ 3, 47, :_reduce_46,
900
+ 3, 47, :_reduce_47,
901
+ 5, 47, :_reduce_48,
902
+ 5, 47, :_reduce_49,
903
+ 3, 47, :_reduce_50,
904
+ 4, 47, :_reduce_51,
905
+ 4, 47, :_reduce_52,
906
+ 2, 47, :_reduce_53,
907
+ 1, 47, :_reduce_54,
908
+ 2, 50, :_reduce_55,
909
+ 0, 51, :_reduce_56,
910
+ 2, 51, :_reduce_57,
911
+ 2, 48, :_reduce_58,
912
+ 1, 49, :_reduce_59,
913
+ 2, 49, :_reduce_60 ]
914
+
915
+ racc_reduce_n = 61
916
+
917
+ racc_shift_n = 94
918
+
919
+ racc_token_table = {
920
+ false => 0,
921
+ :error => 1,
922
+ :IDENT => 2,
923
+ :STRING => 3,
924
+ :NUMBER => 4,
925
+ :HASH => 5,
926
+ :DOT => 6,
927
+ :STAR => 7,
928
+ :LBRACKET => 8,
929
+ :RBRACKET => 9,
930
+ :LPAREN => 10,
931
+ :RPAREN => 11,
932
+ :COLON => 12,
933
+ :COMMA => 13,
934
+ :CHILD => 14,
935
+ :ADJACENT => 15,
936
+ :SIBLING => 16,
937
+ :DESCENDANT => 17,
938
+ :EQUAL => 18,
939
+ :INCLUDES => 19,
940
+ :DASHMATCH => 20,
941
+ :PREFIXMATCH => 21,
942
+ :SUFFIXMATCH => 22,
943
+ :SUBSTRINGMATCH => 23,
944
+ :MINUS => 24,
945
+ "-temp-group" => 25 }
946
+
947
+ racc_nt_base = 26
948
+
949
+ racc_use_result_var = true
950
+
951
+ Racc_arg = [
952
+ racc_action_table,
953
+ racc_action_check,
954
+ racc_action_default,
955
+ racc_action_pointer,
956
+ racc_goto_table,
957
+ racc_goto_check,
958
+ racc_goto_default,
959
+ racc_goto_pointer,
960
+ racc_nt_base,
961
+ racc_reduce_table,
962
+ racc_token_table,
963
+ racc_shift_n,
964
+ racc_reduce_n,
965
+ racc_use_result_var ]
966
+ Ractor.make_shareable(Racc_arg) if defined?(Ractor)
967
+
968
+ Racc_token_to_s_table = [
969
+ "$end",
970
+ "error",
971
+ "IDENT",
972
+ "STRING",
973
+ "NUMBER",
974
+ "HASH",
975
+ "DOT",
976
+ "STAR",
977
+ "LBRACKET",
978
+ "RBRACKET",
979
+ "LPAREN",
980
+ "RPAREN",
981
+ "COLON",
982
+ "COMMA",
983
+ "CHILD",
984
+ "ADJACENT",
985
+ "SIBLING",
986
+ "DESCENDANT",
987
+ "EQUAL",
988
+ "INCLUDES",
989
+ "DASHMATCH",
990
+ "PREFIXMATCH",
991
+ "SUFFIXMATCH",
992
+ "SUBSTRINGMATCH",
993
+ "MINUS",
994
+ "\"-temp-group\"",
995
+ "$start",
996
+ "selector_list",
997
+ "complex_selector",
998
+ "\"-group@COMMA-complex_selector\"",
999
+ "\"-many@-group@COMMA-complex_selector\"",
1000
+ "compound_selector",
1001
+ "combinator",
1002
+ "\"-group@combinator-compound_selector\"",
1003
+ "\"-many@-group@combinator-compound_selector\"",
1004
+ "simple_selector_head",
1005
+ "simple_selector_tail",
1006
+ "type_selector",
1007
+ "subclass_selector",
1008
+ "\"-many@subclass_selector\"",
1009
+ "id_selector",
1010
+ "class_selector",
1011
+ "attribute_selector",
1012
+ "pseudo_class_selector",
1013
+ "pseudo_element_selector",
1014
+ "attr_matcher",
1015
+ "any_value",
1016
+ "an_plus_b",
1017
+ "relative_selector_list",
1018
+ "relative_selector",
1019
+ "\"-group@COMMA-relative_selector\"",
1020
+ "\"-many@-group@COMMA-relative_selector\"" ]
1021
+ Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
1022
+
1023
+ Racc_debug_parser = true
1024
+
1025
+ ##### State transition tables end #####
1026
+
1027
+ # reduce 0 omitted
1028
+
1029
+ module_eval(<<'.,.,', 'parser.y', 31)
1030
+ def _reduce_1(val, _values, result)
1031
+ result = val
1032
+ result
1033
+ end
1034
+ .,.,
1035
+
1036
+ module_eval(<<'.,.,', 'parser.y', 31)
1037
+ def _reduce_2(val, _values, result)
1038
+ result = val[1] ? val[1].unshift(val[0]) : val
1039
+ result
1040
+ end
1041
+ .,.,
1042
+
1043
+ module_eval(<<'.,.,', 'parser.y', 31)
1044
+ def _reduce_3(val, _values, result)
1045
+ result = val[1] ? val[1].unshift(val[0]) : val
1046
+ result
1047
+ end
1048
+ .,.,
1049
+
1050
+ module_eval(<<'.,.,', 'parser.y', 26)
1051
+ def _reduce_4(val, _values, result)
1052
+ result = Node.new(:selector_list, nil, @current_position)
1053
+ result.add_child(val[0])
1054
+ val[1].each { |pair| result.add_child(pair[1]) }
1055
+
1056
+ result
1057
+ end
1058
+ .,.,
1059
+
1060
+ module_eval(<<'.,.,', 'parser.y', 49)
1061
+ def _reduce_5(val, _values, result)
1062
+ result = val
1063
+ result
1064
+ end
1065
+ .,.,
1066
+
1067
+ module_eval(<<'.,.,', 'parser.y', 49)
1068
+ def _reduce_6(val, _values, result)
1069
+ result = val[1] ? val[1].unshift(val[0]) : val
1070
+ result
1071
+ end
1072
+ .,.,
1073
+
1074
+ module_eval(<<'.,.,', 'parser.y', 49)
1075
+ def _reduce_7(val, _values, result)
1076
+ result = val[1] ? val[1].unshift(val[0]) : val
1077
+ result
1078
+ end
1079
+ .,.,
1080
+
1081
+ module_eval(<<'.,.,', 'parser.y', 35)
1082
+ def _reduce_8(val, _values, result)
1083
+ if val[1].empty?
1084
+ result = val[0]
1085
+ else
1086
+ result = val[0]
1087
+ val[1].each do |pair|
1088
+ node = Node.new(:selector, nil, result.position)
1089
+ node.add_child(result)
1090
+ node.add_child(pair[0])
1091
+ node.add_child(pair[1])
1092
+ result = node
1093
+ end
1094
+ end
1095
+
1096
+ result
1097
+ end
1098
+ .,.,
1099
+
1100
+ module_eval(<<'.,.,', 'parser.y', 52)
1101
+ def _reduce_9(val, _values, result)
1102
+ result = Node.new(:child_combinator, '>', @current_position)
1103
+ result
1104
+ end
1105
+ .,.,
1106
+
1107
+ module_eval(<<'.,.,', 'parser.y', 54)
1108
+ def _reduce_10(val, _values, result)
1109
+ result = Node.new(:adjacent_combinator, '+', @current_position)
1110
+ result
1111
+ end
1112
+ .,.,
1113
+
1114
+ module_eval(<<'.,.,', 'parser.y', 56)
1115
+ def _reduce_11(val, _values, result)
1116
+ result = Node.new(:sibling_combinator, '~', @current_position)
1117
+ result
1118
+ end
1119
+ .,.,
1120
+
1121
+ module_eval(<<'.,.,', 'parser.y', 58)
1122
+ def _reduce_12(val, _values, result)
1123
+ result = Node.new(:descendant_combinator, ' ', @current_position)
1124
+ result
1125
+ end
1126
+ .,.,
1127
+
1128
+ module_eval(<<'.,.,', 'parser.y', 64)
1129
+ def _reduce_13(val, _values, result)
1130
+ result = Node.new(:simple_selector_sequence, nil, val[0].position)
1131
+ result.add_child(val[0])
1132
+ val[1].each { |sel| result.add_child(sel) } unless val[1].empty?
1133
+
1134
+ result
1135
+ end
1136
+ .,.,
1137
+
1138
+ module_eval(<<'.,.,', 'parser.y', 72)
1139
+ def _reduce_14(val, _values, result)
1140
+ result = val[0]
1141
+ result
1142
+ end
1143
+ .,.,
1144
+
1145
+ module_eval(<<'.,.,', 'parser.y', 74)
1146
+ def _reduce_15(val, _values, result)
1147
+ result = val[0]
1148
+ result
1149
+ end
1150
+ .,.,
1151
+
1152
+ module_eval(<<'.,.,', 'parser.y', 81)
1153
+ def _reduce_16(val, _values, result)
1154
+ result = val[1] ? val[1].unshift(val[0]) : val
1155
+ result
1156
+ end
1157
+ .,.,
1158
+
1159
+ module_eval(<<'.,.,', 'parser.y', 81)
1160
+ def _reduce_17(val, _values, result)
1161
+ result = val[1] ? val[1].unshift(val[0]) : val
1162
+ result
1163
+ end
1164
+ .,.,
1165
+
1166
+ module_eval(<<'.,.,', 'parser.y', 79)
1167
+ def _reduce_18(val, _values, result)
1168
+ result = val[0]
1169
+ result
1170
+ end
1171
+ .,.,
1172
+
1173
+ module_eval(<<'.,.,', 'parser.y', 84)
1174
+ def _reduce_19(val, _values, result)
1175
+ result = Node.new(:type_selector, val[0], @current_position)
1176
+ result
1177
+ end
1178
+ .,.,
1179
+
1180
+ module_eval(<<'.,.,', 'parser.y', 86)
1181
+ def _reduce_20(val, _values, result)
1182
+ result = Node.new(:universal_selector, '*', @current_position)
1183
+ result
1184
+ end
1185
+ .,.,
1186
+
1187
+ module_eval(<<'.,.,', 'parser.y', 91)
1188
+ def _reduce_21(val, _values, result)
1189
+ result = val[0]
1190
+ result
1191
+ end
1192
+ .,.,
1193
+
1194
+ module_eval(<<'.,.,', 'parser.y', 93)
1195
+ def _reduce_22(val, _values, result)
1196
+ result = val[0]
1197
+ result
1198
+ end
1199
+ .,.,
1200
+
1201
+ module_eval(<<'.,.,', 'parser.y', 95)
1202
+ def _reduce_23(val, _values, result)
1203
+ result = val[0]
1204
+ result
1205
+ end
1206
+ .,.,
1207
+
1208
+ module_eval(<<'.,.,', 'parser.y', 97)
1209
+ def _reduce_24(val, _values, result)
1210
+ result = val[0]
1211
+ result
1212
+ end
1213
+ .,.,
1214
+
1215
+ module_eval(<<'.,.,', 'parser.y', 99)
1216
+ def _reduce_25(val, _values, result)
1217
+ result = val[0]
1218
+ result
1219
+ end
1220
+ .,.,
1221
+
1222
+ module_eval(<<'.,.,', 'parser.y', 104)
1223
+ def _reduce_26(val, _values, result)
1224
+ result = Node.new(:id_selector, val[1], @current_position)
1225
+ result
1226
+ end
1227
+ .,.,
1228
+
1229
+ module_eval(<<'.,.,', 'parser.y', 109)
1230
+ def _reduce_27(val, _values, result)
1231
+ result = Node.new(:class_selector, val[1], @current_position)
1232
+ result
1233
+ end
1234
+ .,.,
1235
+
1236
+ module_eval(<<'.,.,', 'parser.y', 114)
1237
+ def _reduce_28(val, _values, result)
1238
+ result = Node.new(:attribute_selector, val[1], @current_position)
1239
+ result
1240
+ end
1241
+ .,.,
1242
+
1243
+ module_eval(<<'.,.,', 'parser.y', 117)
1244
+ def _reduce_29(val, _values, result)
1245
+ result = Node.new(:attribute_selector, nil, @current_position)
1246
+ result.add_child(Node.new(:attribute, val[1], @current_position))
1247
+ result.add_child(val[2])
1248
+ result.add_child(Node.new(:value, val[3], @current_position))
1249
+
1250
+ result
1251
+ end
1252
+ .,.,
1253
+
1254
+ module_eval(<<'.,.,', 'parser.y', 124)
1255
+ def _reduce_30(val, _values, result)
1256
+ result = Node.new(:attribute_selector, nil, @current_position)
1257
+ result.add_child(Node.new(:attribute, val[1], @current_position))
1258
+ result.add_child(val[2])
1259
+ result.add_child(Node.new(:value, val[3], @current_position))
1260
+
1261
+ result
1262
+ end
1263
+ .,.,
1264
+
1265
+ module_eval(<<'.,.,', 'parser.y', 133)
1266
+ def _reduce_31(val, _values, result)
1267
+ result = Node.new(:equal_operator, '=', @current_position)
1268
+ result
1269
+ end
1270
+ .,.,
1271
+
1272
+ module_eval(<<'.,.,', 'parser.y', 135)
1273
+ def _reduce_32(val, _values, result)
1274
+ result = Node.new(:includes_operator, '~=', @current_position)
1275
+ result
1276
+ end
1277
+ .,.,
1278
+
1279
+ module_eval(<<'.,.,', 'parser.y', 137)
1280
+ def _reduce_33(val, _values, result)
1281
+ result = Node.new(:dashmatch_operator, '|=', @current_position)
1282
+ result
1283
+ end
1284
+ .,.,
1285
+
1286
+ module_eval(<<'.,.,', 'parser.y', 139)
1287
+ def _reduce_34(val, _values, result)
1288
+ result = Node.new(:prefixmatch_operator, '^=', @current_position)
1289
+ result
1290
+ end
1291
+ .,.,
1292
+
1293
+ module_eval(<<'.,.,', 'parser.y', 141)
1294
+ def _reduce_35(val, _values, result)
1295
+ result = Node.new(:suffixmatch_operator, '$=', @current_position)
1296
+ result
1297
+ end
1298
+ .,.,
1299
+
1300
+ module_eval(<<'.,.,', 'parser.y', 143)
1301
+ def _reduce_36(val, _values, result)
1302
+ result = Node.new(:substringmatch_operator, '*=', @current_position)
1303
+ result
1304
+ end
1305
+ .,.,
1306
+
1307
+ module_eval(<<'.,.,', 'parser.y', 148)
1308
+ def _reduce_37(val, _values, result)
1309
+ result = Node.new(:pseudo_class, val[1], @current_position)
1310
+ result
1311
+ end
1312
+ .,.,
1313
+
1314
+ module_eval(<<'.,.,', 'parser.y', 151)
1315
+ def _reduce_38(val, _values, result)
1316
+ fn = Node.new(:pseudo_function, val[1], @current_position)
1317
+ fn.add_child(val[3])
1318
+ result = fn
1319
+
1320
+ result
1321
+ end
1322
+ .,.,
1323
+
1324
+ module_eval(<<'.,.,', 'parser.y', 159)
1325
+ def _reduce_39(val, _values, result)
1326
+ result = Node.new(:pseudo_element, val[2], @current_position)
1327
+ result
1328
+ end
1329
+ .,.,
1330
+
1331
+ module_eval(<<'.,.,', 'parser.y', 164)
1332
+ def _reduce_40(val, _values, result)
1333
+ result = Node.new(:argument, val[0], @current_position)
1334
+ result
1335
+ end
1336
+ .,.,
1337
+
1338
+ module_eval(<<'.,.,', 'parser.y', 166)
1339
+ def _reduce_41(val, _values, result)
1340
+ result = val[0]
1341
+ result
1342
+ end
1343
+ .,.,
1344
+
1345
+ module_eval(<<'.,.,', 'parser.y', 168)
1346
+ def _reduce_42(val, _values, result)
1347
+ result = val[0]
1348
+ result
1349
+ end
1350
+ .,.,
1351
+
1352
+ module_eval(<<'.,.,', 'parser.y', 175)
1353
+ def _reduce_43(val, _values, result)
1354
+ # Handle 'An+B' like '2n+1'
1355
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}+#{val[3]}", @current_position)
1356
+
1357
+ result
1358
+ end
1359
+ .,.,
1360
+
1361
+ module_eval(<<'.,.,', 'parser.y', 180)
1362
+ def _reduce_44(val, _values, result)
1363
+ # Handle 'An-B' like '2n-1'
1364
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}-#{val[3]}", @current_position)
1365
+
1366
+ result
1367
+ end
1368
+ .,.,
1369
+
1370
+ module_eval(<<'.,.,', 'parser.y', 185)
1371
+ def _reduce_45(val, _values, result)
1372
+ # Handle 'An' like '2n' or composite like '2n-1' (when '-1' is part of IDENT)
1373
+ result = Node.new(:an_plus_b, "#{val[0]}#{val[1]}", @current_position)
1374
+
1375
+ result
1376
+ end
1377
+ .,.,
1378
+
1379
+ module_eval(<<'.,.,', 'parser.y', 190)
1380
+ def _reduce_46(val, _values, result)
1381
+ # Handle 'n+B' like 'n+5' or keywords followed by offset (rare but valid)
1382
+ result = Node.new(:an_plus_b, "#{val[0]}+#{val[2]}", @current_position)
1383
+
1384
+ result
1385
+ end
1386
+ .,.,
1387
+
1388
+ module_eval(<<'.,.,', 'parser.y', 195)
1389
+ def _reduce_47(val, _values, result)
1390
+ # Handle 'n-B' like 'n-3'
1391
+ result = Node.new(:an_plus_b, "#{val[0]}-#{val[2]}", @current_position)
1392
+
1393
+ result
1394
+ end
1395
+ .,.,
1396
+
1397
+ module_eval(<<'.,.,', 'parser.y', 201)
1398
+ def _reduce_48(val, _values, result)
1399
+ # Handle '-An+B' like '-2n+1'
1400
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}+#{val[4]}", @current_position)
1401
+
1402
+ result
1403
+ end
1404
+ .,.,
1405
+
1406
+ module_eval(<<'.,.,', 'parser.y', 206)
1407
+ def _reduce_49(val, _values, result)
1408
+ # Handle '-An-B' like '-2n-1'
1409
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}-#{val[4]}", @current_position)
1410
+
1411
+ result
1412
+ end
1413
+ .,.,
1414
+
1415
+ module_eval(<<'.,.,', 'parser.y', 211)
1416
+ def _reduce_50(val, _values, result)
1417
+ # Handle '-An' like '-2n' or composite like '-2n+1' (when '+1' is part of IDENT)
1418
+ result = Node.new(:an_plus_b, "-#{val[1]}#{val[2]}", @current_position)
1419
+
1420
+ result
1421
+ end
1422
+ .,.,
1423
+
1424
+ module_eval(<<'.,.,', 'parser.y', 216)
1425
+ def _reduce_51(val, _values, result)
1426
+ # Handle '-n+B' like '-n+3'
1427
+ result = Node.new(:an_plus_b, "-#{val[1]}+#{val[3]}", @current_position)
1428
+
1429
+ result
1430
+ end
1431
+ .,.,
1432
+
1433
+ module_eval(<<'.,.,', 'parser.y', 221)
1434
+ def _reduce_52(val, _values, result)
1435
+ # Handle '-n-B' like '-n-2'
1436
+ result = Node.new(:an_plus_b, "-#{val[1]}-#{val[3]}", @current_position)
1437
+
1438
+ result
1439
+ end
1440
+ .,.,
1441
+
1442
+ module_eval(<<'.,.,', 'parser.y', 226)
1443
+ def _reduce_53(val, _values, result)
1444
+ # Handle '-n' or composite like '-n+3' (when '+3' is part of IDENT)
1445
+ result = Node.new(:an_plus_b, "-#{val[1]}", @current_position)
1446
+
1447
+ result
1448
+ end
1449
+ .,.,
1450
+
1451
+ module_eval(<<'.,.,', 'parser.y', 232)
1452
+ def _reduce_54(val, _values, result)
1453
+ # Handle just a number like '3'
1454
+ result = Node.new(:an_plus_b, val[0].to_s, @current_position)
1455
+
1456
+ result
1457
+ end
1458
+ .,.,
1459
+
1460
+ module_eval(<<'.,.,', 'parser.y', 245)
1461
+ def _reduce_55(val, _values, result)
1462
+ result = val
1463
+ result
1464
+ end
1465
+ .,.,
1466
+
1467
+ module_eval(<<'.,.,', 'parser.y', 245)
1468
+ def _reduce_56(val, _values, result)
1469
+ result = val[1] ? val[1].unshift(val[0]) : val
1470
+ result
1471
+ end
1472
+ .,.,
1473
+
1474
+ module_eval(<<'.,.,', 'parser.y', 245)
1475
+ def _reduce_57(val, _values, result)
1476
+ result = val[1] ? val[1].unshift(val[0]) : val
1477
+ result
1478
+ end
1479
+ .,.,
1480
+
1481
+ module_eval(<<'.,.,', 'parser.y', 240)
1482
+ def _reduce_58(val, _values, result)
1483
+ result = Node.new(:selector_list, nil, @current_position)
1484
+ result.add_child(val[0])
1485
+ val[1].each { |pair| result.add_child(pair[1]) }
1486
+
1487
+ result
1488
+ end
1489
+ .,.,
1490
+
1491
+ module_eval(<<'.,.,', 'parser.y', 248)
1492
+ def _reduce_59(val, _values, result)
1493
+ result = val[0]
1494
+ result
1495
+ end
1496
+ .,.,
1497
+
1498
+ module_eval(<<'.,.,', 'parser.y', 251)
1499
+ def _reduce_60(val, _values, result)
1500
+ result = Node.new(:selector, nil, val[0].position)
1501
+ result.add_child(val[0])
1502
+ result.add_child(val[1])
1503
+
1504
+ result
1505
+ end
1506
+ .,.,
1507
+
1508
+ def _reduce_none(val, _values, result)
1509
+ val[0]
1510
+ end
1511
+
1512
+ end # class Parser
1513
+ end # module Parselly