racc 1.4.16 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/README.ja.rdoc +0 -1
  3. data/README.rdoc +8 -11
  4. data/bin/racc +37 -23
  5. data/{rdoc → doc}/en/NEWS.en.rdoc +0 -0
  6. data/{rdoc → doc}/en/grammar.en.rdoc +27 -31
  7. data/doc/en/grammar2.en.rdoc +219 -0
  8. data/{rdoc → doc}/ja/NEWS.ja.rdoc +0 -0
  9. data/{rdoc → doc}/ja/command.ja.html +1 -1
  10. data/{rdoc → doc}/ja/debug.ja.rdoc +0 -0
  11. data/{rdoc → doc}/ja/grammar.ja.rdoc +0 -0
  12. data/{rdoc → doc}/ja/index.ja.html +0 -0
  13. data/{rdoc → doc}/ja/parser.ja.rdoc +0 -0
  14. data/{rdoc → doc}/ja/usage.ja.html +0 -0
  15. data/ext/racc/cparse/cparse.c +19 -17
  16. data/ext/racc/cparse/extconf.rb +2 -1
  17. data/lib/racc/compat.rb +5 -4
  18. data/lib/racc/debugflags.rb +5 -4
  19. data/lib/racc/exception.rb +4 -1
  20. data/lib/racc/grammar.rb +22 -17
  21. data/lib/racc/grammarfileparser.rb +7 -6
  22. data/lib/racc/info.rb +5 -2
  23. data/lib/racc/iset.rb +5 -4
  24. data/lib/racc/logfilegenerator.rb +5 -4
  25. data/lib/racc/parser-text.rb +10 -16
  26. data/lib/racc/parser.rb +10 -16
  27. data/lib/racc/parserfilegenerator.rb +5 -47
  28. data/lib/racc/sourcetext.rb +5 -4
  29. data/lib/racc/state.rb +4 -1
  30. data/lib/racc/statetransitiontable.rb +9 -14
  31. metadata +22 -140
  32. data/DEPENDS +0 -4
  33. data/Manifest.txt +0 -146
  34. data/Rakefile +0 -58
  35. data/bin/racc2y +0 -195
  36. data/bin/y2racc +0 -339
  37. data/ext/racc/com/headius/racc/Cparse.java +0 -849
  38. data/fastcache/extconf.rb +0 -2
  39. data/fastcache/fastcache.c +0 -185
  40. data/lib/racc/pre-setup +0 -13
  41. data/misc/dist.sh +0 -31
  42. data/sample/array.y +0 -67
  43. data/sample/array2.y +0 -59
  44. data/sample/calc-ja.y +0 -66
  45. data/sample/calc.y +0 -65
  46. data/sample/conflict.y +0 -15
  47. data/sample/hash.y +0 -60
  48. data/sample/lalr.y +0 -17
  49. data/sample/lists.y +0 -57
  50. data/sample/syntax.y +0 -46
  51. data/sample/yyerr.y +0 -46
  52. data/setup.rb +0 -1587
  53. data/tasks/doc.rb +0 -12
  54. data/tasks/email.rb +0 -55
  55. data/test/assets/cadenza.y +0 -170
  56. data/test/assets/cast.y +0 -926
  57. data/test/assets/chk.y +0 -126
  58. data/test/assets/conf.y +0 -16
  59. data/test/assets/csspool.y +0 -729
  60. data/test/assets/digraph.y +0 -29
  61. data/test/assets/echk.y +0 -118
  62. data/test/assets/edtf.y +0 -583
  63. data/test/assets/err.y +0 -60
  64. data/test/assets/error_recovery.y +0 -35
  65. data/test/assets/expect.y +0 -7
  66. data/test/assets/firstline.y +0 -4
  67. data/test/assets/huia.y +0 -318
  68. data/test/assets/ichk.y +0 -102
  69. data/test/assets/intp.y +0 -546
  70. data/test/assets/journey.y +0 -47
  71. data/test/assets/liquor.y +0 -313
  72. data/test/assets/machete.y +0 -423
  73. data/test/assets/macruby.y +0 -2197
  74. data/test/assets/mailp.y +0 -437
  75. data/test/assets/mediacloth.y +0 -599
  76. data/test/assets/mof.y +0 -649
  77. data/test/assets/namae.y +0 -302
  78. data/test/assets/nasl.y +0 -626
  79. data/test/assets/newsyn.y +0 -25
  80. data/test/assets/noend.y +0 -4
  81. data/test/assets/nokogiri-css.y +0 -255
  82. data/test/assets/nonass.y +0 -41
  83. data/test/assets/normal.y +0 -27
  84. data/test/assets/norule.y +0 -4
  85. data/test/assets/nullbug1.y +0 -25
  86. data/test/assets/nullbug2.y +0 -15
  87. data/test/assets/opal.y +0 -1807
  88. data/test/assets/opt.y +0 -123
  89. data/test/assets/percent.y +0 -35
  90. data/test/assets/php_serialization.y +0 -98
  91. data/test/assets/recv.y +0 -97
  92. data/test/assets/riml.y +0 -665
  93. data/test/assets/rrconf.y +0 -14
  94. data/test/assets/ruby18.y +0 -1943
  95. data/test/assets/ruby19.y +0 -2174
  96. data/test/assets/ruby20.y +0 -2350
  97. data/test/assets/ruby21.y +0 -2359
  98. data/test/assets/ruby22.y +0 -2381
  99. data/test/assets/scan.y +0 -72
  100. data/test/assets/syntax.y +0 -50
  101. data/test/assets/tp_plus.y +0 -622
  102. data/test/assets/twowaysql.y +0 -278
  103. data/test/assets/unterm.y +0 -5
  104. data/test/assets/useless.y +0 -12
  105. data/test/assets/yyerr.y +0 -46
  106. data/test/bench.y +0 -36
  107. data/test/helper.rb +0 -115
  108. data/test/infini.y +0 -8
  109. data/test/regress/cadenza +0 -796
  110. data/test/regress/cast +0 -3425
  111. data/test/regress/csspool +0 -2318
  112. data/test/regress/edtf +0 -1794
  113. data/test/regress/huia +0 -1392
  114. data/test/regress/journey +0 -222
  115. data/test/regress/liquor +0 -885
  116. data/test/regress/machete +0 -833
  117. data/test/regress/mediacloth +0 -1463
  118. data/test/regress/mof +0 -1368
  119. data/test/regress/namae +0 -634
  120. data/test/regress/nasl +0 -2058
  121. data/test/regress/nokogiri-css +0 -836
  122. data/test/regress/opal +0 -6429
  123. data/test/regress/php_serialization +0 -336
  124. data/test/regress/riml +0 -3297
  125. data/test/regress/ruby18 +0 -6351
  126. data/test/regress/ruby22 +0 -7456
  127. data/test/regress/tp_plus +0 -1933
  128. data/test/regress/twowaysql +0 -556
  129. data/test/scandata/brace +0 -7
  130. data/test/scandata/gvar +0 -1
  131. data/test/scandata/normal +0 -4
  132. data/test/scandata/percent +0 -18
  133. data/test/scandata/slash +0 -10
  134. data/test/src.intp +0 -34
  135. data/test/start.y +0 -20
  136. data/test/test_chk_y.rb +0 -52
  137. data/test/test_grammar_file_parser.rb +0 -15
  138. data/test/test_racc_command.rb +0 -322
  139. data/test/test_scan_y.rb +0 -52
  140. data/test/testscanner.rb +0 -51
  141. data/web/racc.en.rhtml +0 -42
  142. data/web/racc.ja.rhtml +0 -51
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: racc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.16
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  - Aaron Patterson
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-10 00:00:00.000000000 Z
12
+ date: 2021-10-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: |-
14
+ description: |
15
15
  Racc is a LALR(1) parser generator.
16
16
  It is written in Ruby itself, and generates Ruby program.
17
17
 
@@ -19,42 +19,35 @@ description: |-
19
19
  can run your parsers generated by racc 1.4.x out of the
20
20
  box.
21
21
  email:
22
- -
22
+ -
23
23
  - aaron@tenderlovemaking.com
24
24
  executables:
25
25
  - racc
26
- - racc2y
27
- - y2racc
28
26
  extensions:
29
27
  - ext/racc/cparse/extconf.rb
30
28
  extra_rdoc_files:
31
- - Manifest.txt
32
29
  - README.ja.rdoc
33
30
  - README.rdoc
34
- - rdoc/en/NEWS.en.rdoc
35
- - rdoc/en/grammar.en.rdoc
36
- - rdoc/ja/NEWS.ja.rdoc
37
- - rdoc/ja/debug.ja.rdoc
38
- - rdoc/ja/grammar.ja.rdoc
39
- - rdoc/ja/parser.ja.rdoc
40
31
  files:
41
32
  - COPYING
42
33
  - ChangeLog
43
- - DEPENDS
44
- - Manifest.txt
45
34
  - README.ja.rdoc
46
35
  - README.rdoc
47
- - Rakefile
48
36
  - TODO
49
37
  - bin/racc
50
- - bin/racc2y
51
- - bin/y2racc
38
+ - doc/en/NEWS.en.rdoc
39
+ - doc/en/grammar.en.rdoc
40
+ - doc/en/grammar2.en.rdoc
41
+ - doc/ja/NEWS.ja.rdoc
42
+ - doc/ja/command.ja.html
43
+ - doc/ja/debug.ja.rdoc
44
+ - doc/ja/grammar.ja.rdoc
45
+ - doc/ja/index.ja.html
46
+ - doc/ja/parser.ja.rdoc
47
+ - doc/ja/usage.ja.html
52
48
  - ext/racc/MANIFEST
53
- - ext/racc/com/headius/racc/Cparse.java
54
49
  - ext/racc/cparse/cparse.c
55
50
  - ext/racc/cparse/extconf.rb
56
- - fastcache/extconf.rb
57
- - fastcache/fastcache.c
58
51
  - lib/racc.rb
59
52
  - lib/racc/compat.rb
60
53
  - lib/racc/debugflags.rb
@@ -67,127 +60,16 @@ files:
67
60
  - lib/racc/parser-text.rb
68
61
  - lib/racc/parser.rb
69
62
  - lib/racc/parserfilegenerator.rb
70
- - lib/racc/pre-setup
71
63
  - lib/racc/sourcetext.rb
72
64
  - lib/racc/state.rb
73
65
  - lib/racc/statetransitiontable.rb
74
66
  - lib/racc/static.rb
75
- - misc/dist.sh
76
- - rdoc/en/NEWS.en.rdoc
77
- - rdoc/en/grammar.en.rdoc
78
- - rdoc/ja/NEWS.ja.rdoc
79
- - rdoc/ja/command.ja.html
80
- - rdoc/ja/debug.ja.rdoc
81
- - rdoc/ja/grammar.ja.rdoc
82
- - rdoc/ja/index.ja.html
83
- - rdoc/ja/parser.ja.rdoc
84
- - rdoc/ja/usage.ja.html
85
- - sample/array.y
86
- - sample/array2.y
87
- - sample/calc-ja.y
88
- - sample/calc.y
89
- - sample/conflict.y
90
- - sample/hash.y
91
- - sample/lalr.y
92
- - sample/lists.y
93
- - sample/syntax.y
94
- - sample/yyerr.y
95
- - setup.rb
96
- - tasks/doc.rb
97
- - tasks/email.rb
98
- - test/assets/cadenza.y
99
- - test/assets/cast.y
100
- - test/assets/chk.y
101
- - test/assets/conf.y
102
- - test/assets/csspool.y
103
- - test/assets/digraph.y
104
- - test/assets/echk.y
105
- - test/assets/edtf.y
106
- - test/assets/err.y
107
- - test/assets/error_recovery.y
108
- - test/assets/expect.y
109
- - test/assets/firstline.y
110
- - test/assets/huia.y
111
- - test/assets/ichk.y
112
- - test/assets/intp.y
113
- - test/assets/journey.y
114
- - test/assets/liquor.y
115
- - test/assets/machete.y
116
- - test/assets/macruby.y
117
- - test/assets/mailp.y
118
- - test/assets/mediacloth.y
119
- - test/assets/mof.y
120
- - test/assets/namae.y
121
- - test/assets/nasl.y
122
- - test/assets/newsyn.y
123
- - test/assets/noend.y
124
- - test/assets/nokogiri-css.y
125
- - test/assets/nonass.y
126
- - test/assets/normal.y
127
- - test/assets/norule.y
128
- - test/assets/nullbug1.y
129
- - test/assets/nullbug2.y
130
- - test/assets/opal.y
131
- - test/assets/opt.y
132
- - test/assets/percent.y
133
- - test/assets/php_serialization.y
134
- - test/assets/recv.y
135
- - test/assets/riml.y
136
- - test/assets/rrconf.y
137
- - test/assets/ruby18.y
138
- - test/assets/ruby19.y
139
- - test/assets/ruby20.y
140
- - test/assets/ruby21.y
141
- - test/assets/ruby22.y
142
- - test/assets/scan.y
143
- - test/assets/syntax.y
144
- - test/assets/tp_plus.y
145
- - test/assets/twowaysql.y
146
- - test/assets/unterm.y
147
- - test/assets/useless.y
148
- - test/assets/yyerr.y
149
- - test/bench.y
150
- - test/helper.rb
151
- - test/infini.y
152
- - test/regress/cadenza
153
- - test/regress/cast
154
- - test/regress/csspool
155
- - test/regress/edtf
156
- - test/regress/huia
157
- - test/regress/journey
158
- - test/regress/liquor
159
- - test/regress/machete
160
- - test/regress/mediacloth
161
- - test/regress/mof
162
- - test/regress/namae
163
- - test/regress/nasl
164
- - test/regress/nokogiri-css
165
- - test/regress/opal
166
- - test/regress/php_serialization
167
- - test/regress/riml
168
- - test/regress/ruby18
169
- - test/regress/ruby22
170
- - test/regress/tp_plus
171
- - test/regress/twowaysql
172
- - test/scandata/brace
173
- - test/scandata/gvar
174
- - test/scandata/normal
175
- - test/scandata/percent
176
- - test/scandata/slash
177
- - test/src.intp
178
- - test/start.y
179
- - test/test_chk_y.rb
180
- - test/test_grammar_file_parser.rb
181
- - test/test_racc_command.rb
182
- - test/test_scan_y.rb
183
- - test/testscanner.rb
184
- - web/racc.en.rhtml
185
- - web/racc.ja.rhtml
186
- homepage: http://i.loveruby.net/en/projects/racc/
67
+ homepage: https://i.loveruby.net/en/projects/racc/
187
68
  licenses:
188
- - MIT
69
+ - Ruby
70
+ - BSD-2-Clause
189
71
  metadata: {}
190
- post_install_message:
72
+ post_install_message:
191
73
  rdoc_options:
192
74
  - "--main"
193
75
  - README.rdoc
@@ -197,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
79
  requirements:
198
80
  - - ">="
199
81
  - !ruby/object:Gem::Version
200
- version: '0'
82
+ version: '2.5'
201
83
  required_rubygems_version: !ruby/object:Gem::Requirement
202
84
  requirements:
203
85
  - - ">="
204
86
  - !ruby/object:Gem::Version
205
87
  version: '0'
206
88
  requirements: []
207
- rubygems_version: 3.1.0.pre3
208
- signing_key:
89
+ rubygems_version: 3.3.0.dev
90
+ signing_key:
209
91
  specification_version: 4
210
92
  summary: Racc is a LALR(1) parser generator
211
93
  test_files: []
data/DEPENDS DELETED
@@ -1,4 +0,0 @@
1
- racc: raccruntime
2
- raccruntime:
3
- y2racc: strscan
4
- racc2y: racc
data/Manifest.txt DELETED
@@ -1,146 +0,0 @@
1
- COPYING
2
- ChangeLog
3
- DEPENDS
4
- Manifest.txt
5
- README.ja.rdoc
6
- README.rdoc
7
- Rakefile
8
- TODO
9
- bin/racc
10
- bin/racc2y
11
- bin/y2racc
12
- ext/racc/MANIFEST
13
- ext/racc/cparse/cparse.c
14
- ext/racc/cparse/depend
15
- ext/racc/cparse/extconf.rb
16
- ext/racc/com/headius/racc/Cparse.java
17
- fastcache/extconf.rb
18
- fastcache/fastcache.c
19
- lib/racc.rb
20
- lib/racc/compat.rb
21
- lib/racc/debugflags.rb
22
- lib/racc/exception.rb
23
- lib/racc/grammar.rb
24
- lib/racc/grammarfileparser.rb
25
- lib/racc/info.rb
26
- lib/racc/iset.rb
27
- lib/racc/logfilegenerator.rb
28
- lib/racc/parser-text.rb
29
- lib/racc/parser.rb
30
- lib/racc/parserfilegenerator.rb
31
- lib/racc/pre-setup
32
- lib/racc/sourcetext.rb
33
- lib/racc/state.rb
34
- lib/racc/statetransitiontable.rb
35
- lib/racc/static.rb
36
- misc/dist.sh
37
- rdoc/en/NEWS.en.rdoc
38
- rdoc/en/grammar.en.rdoc
39
- rdoc/ja/NEWS.ja.rdoc
40
- rdoc/ja/command.ja.html
41
- rdoc/ja/debug.ja.rdoc
42
- rdoc/ja/grammar.ja.rdoc
43
- rdoc/ja/index.ja.html
44
- rdoc/ja/parser.ja.rdoc
45
- rdoc/ja/usage.ja.html
46
- sample/array.y
47
- sample/array2.y
48
- sample/calc-ja.y
49
- sample/calc.y
50
- sample/conflict.y
51
- sample/hash.y
52
- sample/lalr.y
53
- sample/lists.y
54
- sample/syntax.y
55
- sample/yyerr.y
56
- setup.rb
57
- tasks/doc.rb
58
- tasks/email.rb
59
- test/assets/cadenza.y
60
- test/assets/cast.y
61
- test/assets/chk.y
62
- test/assets/conf.y
63
- test/assets/csspool.y
64
- test/assets/digraph.y
65
- test/assets/echk.y
66
- test/assets/edtf.y
67
- test/assets/err.y
68
- test/assets/error_recovery.y
69
- test/assets/expect.y
70
- test/assets/firstline.y
71
- test/assets/huia.y
72
- test/assets/ichk.y
73
- test/assets/intp.y
74
- test/assets/journey.y
75
- test/assets/liquor.y
76
- test/assets/machete.y
77
- test/assets/macruby.y
78
- test/assets/mediacloth.y
79
- test/assets/mailp.y
80
- test/assets/mof.y
81
- test/assets/namae.y
82
- test/assets/nasl.y
83
- test/assets/newsyn.y
84
- test/assets/noend.y
85
- test/assets/nokogiri-css.y
86
- test/assets/nonass.y
87
- test/assets/normal.y
88
- test/assets/norule.y
89
- test/assets/nullbug1.y
90
- test/assets/nullbug2.y
91
- test/assets/opal.y
92
- test/assets/opt.y
93
- test/assets/percent.y
94
- test/assets/php_serialization.y
95
- test/assets/recv.y
96
- test/assets/riml.y
97
- test/assets/rrconf.y
98
- test/assets/ruby18.y
99
- test/assets/ruby19.y
100
- test/assets/ruby20.y
101
- test/assets/ruby21.y
102
- test/assets/ruby22.y
103
- test/assets/scan.y
104
- test/assets/syntax.y
105
- test/assets/tp_plus.y
106
- test/assets/twowaysql.y
107
- test/assets/unterm.y
108
- test/assets/useless.y
109
- test/assets/yyerr.y
110
- test/bench.y
111
- test/helper.rb
112
- test/infini.y
113
- test/regress/cadenza
114
- test/regress/cast
115
- test/regress/csspool
116
- test/regress/edtf
117
- test/regress/journey
118
- test/regress/huia
119
- test/regress/liquor
120
- test/regress/machete
121
- test/regress/mediacloth
122
- test/regress/mof
123
- test/regress/namae
124
- test/regress/nasl
125
- test/regress/nokogiri-css
126
- test/regress/opal
127
- test/regress/php_serialization
128
- test/regress/riml
129
- test/regress/ruby18
130
- test/regress/ruby22
131
- test/regress/tp_plus
132
- test/regress/twowaysql
133
- test/scandata/brace
134
- test/scandata/gvar
135
- test/scandata/normal
136
- test/scandata/percent
137
- test/scandata/slash
138
- test/src.intp
139
- test/start.y
140
- test/test_chk_y.rb
141
- test/test_grammar_file_parser.rb
142
- test/test_racc_command.rb
143
- test/test_scan_y.rb
144
- test/testscanner.rb
145
- web/racc.en.rhtml
146
- web/racc.ja.rhtml
data/Rakefile DELETED
@@ -1,58 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rake/testtask'
4
-
5
- Rake::TestTask.new(:test) do |t|
6
- t.test_files = FileList["test/**/test_*.rb"]
7
- end
8
- gem 'rake-compiler', '>= 0.4.1'
9
-
10
- def java?
11
- /java/ === RUBY_PLATFORM
12
- end
13
- def jruby?
14
- Object.const_defined?(:RUBY_ENGINE) and 'jruby' == RUBY_ENGINE
15
- end
16
-
17
- file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
18
- source = 'lib/racc/parser.rb'
19
-
20
- open(t.name, 'wb') { |io|
21
- io.write(<<-eorb)
22
- module Racc
23
- PARSER_TEXT = <<'__end_of_file__'
24
- #{File.read(source)}
25
- __end_of_file__
26
- end
27
- eorb
28
- }
29
- end
30
-
31
- if jruby?
32
- # JRUBY
33
- require "rake/javaextensiontask"
34
- Rake::JavaExtensionTask.new("cparse") do |ext|
35
- jruby_home = RbConfig::CONFIG['prefix']
36
- ext.lib_dir = File.join 'lib', 'racc'
37
- ext.ext_dir = File.join 'ext', 'racc'
38
- # source/target jvm
39
- ext.source_version = '1.6'
40
- ext.target_version = '1.6'
41
- jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
42
- ext.classpath = jars.map { |x| File.expand_path x }.join( ':' )
43
- ext.name = 'cparse-jruby'
44
- end
45
-
46
- task :compile => ['lib/racc/parser-text.rb']
47
- else
48
- # MRI
49
- require "rake/extensiontask"
50
- Rake::ExtensionTask.new "cparse" do |ext|
51
- ext.lib_dir = File.join 'lib', 'racc'
52
- ext.ext_dir = File.join 'ext', 'racc', 'cparse'
53
- end
54
-
55
- task :compile => 'lib/racc/parser-text.rb'
56
- end
57
-
58
- task :test => :compile
data/bin/racc2y DELETED
@@ -1,195 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- #
3
- # $Id$
4
- #
5
- # Copyright (c) 1999-2006 Minero Aoki
6
- #
7
- # This program is feee software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # For details of the LGPL, see the file "COPYING".
11
- #
12
-
13
- require 'racc/grammarfileparser'
14
- require 'racc/info'
15
- require 'optparse'
16
-
17
- def main
18
- @with_action = true
19
- with_header = false
20
- with_inner = false
21
- with_footer = false
22
- output = nil
23
- parser = OptionParser.new
24
- parser.banner = "Usage: #{File.basename($0)} [-AHIF] [-oFILENAME] GRAMMARFILE"
25
- parser.on('-o', '--output=FILENAME', 'output file name [<input>.yacc]') {|name|
26
- output = name
27
- }
28
- parser.on('-A', '--without-action', 'Does not include actions.') {
29
- @with_action = false
30
- }
31
- parser.on('-H', '--with-header', 'Includes header part.') {
32
- with_header = true
33
- }
34
- parser.on('-I', '--with-inner', 'Includes inner part.') {
35
- with_inner = true
36
- }
37
- parser.on('-F', '--with-footer', 'Includes footer part.') {
38
- with_footer = true
39
- }
40
- parser.on('--version', 'Prints version and quit.') {
41
- puts "racc2y version #{Racc::Version}"
42
- exit 0
43
- }
44
- parser.on('--copyright', 'Prints copyright and quit.') {
45
- puts Racc::Copyright
46
- exit 0
47
- }
48
- parser.on('--help', 'Prints this message and quit.') {
49
- puts parser.help
50
- exit 1
51
- }
52
- begin
53
- parser.parse!
54
- rescue OptionParser::ParseError => err
55
- $stderr.puts err.message
56
- $stderr.puts parser.help
57
- exit 1
58
- end
59
- if ARGV.empty?
60
- $stderr.puts "no input file"
61
- exit 1
62
- end
63
- unless ARGV.size == 1
64
- $stderr.puts "too many inputs"
65
- exit 1
66
- end
67
- input = ARGV[0]
68
-
69
- begin
70
- result = Racc::GrammarFileParser.parse_file(input)
71
- result.grammar.init
72
- File.open(output || "#{input}.yacc", 'w') {|f|
73
- f.puts "/* generated from #{input} */"
74
- if with_header
75
- f.puts
76
- f.puts '%{'
77
- print_user_codes f, result.params.header
78
- f.puts '%}'
79
- end
80
- f.puts
81
- print_terminals f, result.grammar
82
- f.puts
83
- print_precedence_table f, precedence_table(result.grammar)
84
- f.puts
85
- f.puts '%%'
86
- print_grammar f, result.grammar
87
- f.puts '%%'
88
- if with_inner
89
- f.puts '/*---- inner ----*/'
90
- print_user_codes f, result.params.inner
91
- end
92
- if with_footer
93
- f.puts '/*---- footer ----*/'
94
- print_user_codes f, result.params.footer
95
- end
96
- }
97
- rescue SystemCallError => err
98
- $stderr.puts err.message
99
- exit 1
100
- end
101
- end
102
-
103
- def print_terminals(f, grammar)
104
- init_indent = '%token'.size
105
- f.print '%token'
106
- columns = init_indent
107
- grammar.symboltable.each_terminal do |t|
108
- next unless t.terminal?
109
- next if t.dummy?
110
- next if t == grammar.symboltable.anchor
111
- next if t == grammar.symboltable.error
112
- unless t.value.kind_of?(String)
113
- if columns > 60
114
- f.puts
115
- f.print ' ' * init_indent
116
- columns = init_indent
117
- end
118
- columns += f.write(" #{yacc_symbol(t)}")
119
- end
120
- end
121
- f.puts
122
- end
123
-
124
- def precedence_table(grammar)
125
- table = []
126
- grammar.symboltable.select {|sym| sym.precedence }.each do |sym|
127
- (table[sym.prec] ||= [sym.assoc]).push sym
128
- end
129
- table.compact
130
- end
131
-
132
- def print_precedence_table(f, table)
133
- return if table.empty?
134
- f.puts '/* precedance table */'
135
- table.each do |syms|
136
- assoc = syms.shift
137
- f.printf '%%%-8s ', assoc.to_s.downcase
138
- f.puts syms.map {|s| yacc_symbol(s) }.join(' ')
139
- end
140
- f.puts
141
- end
142
-
143
- def print_grammar(f, grammar)
144
- prev_target = nil
145
- indent = 10
146
- embactions = []
147
- grammar.each do |rule|
148
- if rule.target.dummy?
149
- embactions.push rule.action unless rule.action.empty?
150
- next
151
- end
152
- if rule.target == prev_target
153
- f.print ' ' * indent, '|'
154
- else
155
- prev_target = rule.target
156
- f.printf "\n%-10s:", yacc_symbol(prev_target)
157
- end
158
- rule.symbols.each do |s|
159
- if s.dummy? # target of dummy rule for embedded action
160
- f.puts
161
- print_action f, embactions.shift, indent
162
- f.print ' ' * (indent + 1)
163
- else
164
- f.print ' ', yacc_symbol(s)
165
- end
166
- end
167
- if rule.specified_prec
168
- f.print ' %prec ', yacc_symbol(rule.specified_prec)
169
- end
170
- f.puts
171
- unless rule.action.empty?
172
- print_action f, rule.action, indent
173
- end
174
- end
175
- end
176
-
177
- def print_action(f, action, indent)
178
- return unless @with_action
179
- f.print ' ' * (indent + 4), "{\n"
180
- f.print ' ' * (indent + 6), action.source.text.strip, "\n"
181
- f.print ' ' * (indent + 4) , "}\n"
182
- end
183
-
184
- def print_user_codes(f, srcs)
185
- return if srcs.empty?
186
- srcs.each do |src|
187
- f.puts src.text
188
- end
189
- end
190
-
191
- def yacc_symbol(s)
192
- s.to_s.gsub('"', "'")
193
- end
194
-
195
- main