Skip to content

Commit

Permalink
Add test code for TestRaccCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jul 29, 2024
1 parent 6e3734f commit 7eccc64
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/assets/group.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MyParser
rule
stmt: ('a')
end
---- header
require 'strscan'
---- inner
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
15 changes: 15 additions & 0 deletions test/assets/many.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MyParser
rule
stmt: 'abc'*
end
---- header
require 'strscan'
---- inner
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
15 changes: 15 additions & 0 deletions test/assets/many1.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MyParser
rule
stmt: 'abc'+
end
---- header
require 'strscan'
---- inner
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
15 changes: 15 additions & 0 deletions test/assets/optional.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MyParser
rule
stmt: 'abc'?
end
---- header
require 'strscan'
---- inner
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
113 changes: 113 additions & 0 deletions test/regress/group
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.8.0
# from Racc grammar file "group.y".
#

require 'racc/parser.rb'

require 'strscan'
class MyParser < Racc::Parser

module_eval(<<'...end group.y/module_eval...', 'group.y', 8)
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
...end group.y/module_eval...
##### State transition tables begin ###

racc_action_table = [
2, 4, 5 ]

racc_action_check = [
0, 1, 4 ]

racc_action_pointer = [
-2, 1, nil, nil, 2, nil ]

racc_action_default = [
-3, -3, -1, -2, -3, 6 ]

racc_goto_table = [
1, 3 ]

racc_goto_check = [
1, 2 ]

racc_goto_pointer = [
nil, 0, 1 ]

racc_goto_default = [
nil, nil, nil ]

racc_reduce_table = [
0, 0, :racc_error,
1, 6, :_reduce_1,
1, 5, :_reduce_none ]

racc_reduce_n = 3

racc_shift_n = 6

racc_token_table = {
false => 0,
:error => 1,
"a" => 2,
"-temp-group" => 3 }

racc_nt_base = 4

racc_use_result_var = true

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 ]
Ractor.make_shareable(Racc_arg) if defined?(Ractor)

Racc_token_to_s_table = [
"$end",
"error",
"\"a\"",
"\"-temp-group\"",
"$start",
"stmt",
"\"-group@\\\"a\\\"\"" ]
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)

Racc_debug_parser = false

##### State transition tables end #####

# reduce 0 omitted

module_eval(<<'.,.,', 'group.y', 4)
def _reduce_1(val, _values, result)
result = val
result
end
.,.,

# reduce 2 omitted

def _reduce_none(val, _values, result)
val[0]
end

end # class MyParser
119 changes: 119 additions & 0 deletions test/regress/many
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.8.0
# from Racc grammar file "many.y".
#

require 'racc/parser.rb'

require 'strscan'
class MyParser < Racc::Parser

module_eval(<<'...end many.y/module_eval...', 'many.y', 8)
def parse(str)
@ss = StringScanner.new(str)
do_parse
end
def next_token
@ss.skip(/\\s+/)
token = @ss.scan(/\\S+/) and [token, token]
end
...end many.y/module_eval...
##### State transition tables begin ###

racc_action_table = [
2, 4, 2, 6 ]

racc_action_check = [
0, 1, 2, 4 ]

racc_action_pointer = [
-2, 1, 0, nil, 3, nil, nil ]

racc_action_default = [
-1, -4, -1, -3, -4, -2, 7 ]

racc_goto_table = [
3, 1, 5 ]

racc_goto_check = [
2, 1, 2 ]

racc_goto_pointer = [
nil, 1, 0 ]

racc_goto_default = [
nil, nil, nil ]

racc_reduce_table = [
0, 0, :racc_error,
0, 5, :_reduce_1,
2, 5, :_reduce_2,
1, 4, :_reduce_none ]

racc_reduce_n = 4

racc_shift_n = 7

racc_token_table = {
false => 0,
:error => 1,
"abc" => 2 }

racc_nt_base = 3

racc_use_result_var = true

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 ]
Ractor.make_shareable(Racc_arg) if defined?(Ractor)

Racc_token_to_s_table = [
"$end",
"error",
"\"abc\"",
"$start",
"stmt",
"\"-many@abc\"" ]
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)

Racc_debug_parser = false

##### State transition tables end #####

# reduce 0 omitted

module_eval(<<'.,.,', 'many.y', 4)
def _reduce_1(val, _values, result)
result = val[1] ? val[1].unshift(val[0]) : val
result
end
.,.,

module_eval(<<'.,.,', 'many.y', 4)
def _reduce_2(val, _values, result)
result = val[1] ? val[1].unshift(val[0]) : val
result
end
.,.,

# reduce 3 omitted

def _reduce_none(val, _values, result)
val[0]
end

end # class MyParser
Loading

0 comments on commit 7eccc64

Please sign in to comment.