racc 1.6.0 → 1.8.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.
- checksums.yaml +4 -4
- data/ChangeLog +3 -3
- data/README.ja.rdoc +2 -38
- data/README.rdoc +12 -35
- data/TODO +1 -1
- data/bin/racc +32 -32
- data/doc/en/grammar.en.rdoc +99 -107
- data/doc/en/grammar2.en.rdoc +1 -1
- data/doc/ja/command.ja.html +5 -0
- data/doc/ja/grammar.ja.rdoc +1 -1
- data/doc/ja/parser.ja.rdoc +1 -1
- data/ext/racc/cparse/cparse.c +26 -49
- data/ext/racc/cparse/extconf.rb +3 -4
- data/lib/racc/grammar.rb +80 -7
- data/lib/racc/grammarfileparser.rb +116 -10
- data/lib/racc/info.rb +2 -1
- data/lib/racc/parser-text.rb +18 -11
- data/lib/racc/parser.rb +10 -12
- data/lib/racc/parserfilegenerator.rb +7 -2
- data/lib/racc/state.rb +4 -0
- data/lib/racc/statetransitiontable.rb +1 -1
- metadata +4 -7
- data/doc/en/NEWS.en.rdoc +0 -282
- data/doc/ja/NEWS.ja.rdoc +0 -307
- data/ext/racc/MANIFEST +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5de182ad74eb075783ee57ec9f930c2d81a4d1465db436f6d5e42fb96eaa6a0f
|
4
|
+
data.tar.gz: 53cb977c27837bdf4df9cd1eae679e30a00ecb07b080e8481b59bfb66aec8bf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf79f910341f5fa146fb6f798ebfa08ad3e0379b1f322e80a004ea1b1285c4ce8bfa239f59cc078eb152d020a012d5d4f0646e2ad16a3ad55665db7d9521be1e
|
7
|
+
data.tar.gz: a317170a03d5355324b1d35cecc0edcd06fd4622eee4dd5cbc48ec0c4d53631054b37798f65b90ba0b4eabce1eb281e172554139854b63bad7bc3b8bdef3b811
|
data/ChangeLog
CHANGED
@@ -253,7 +253,7 @@ Mon Jul 3 04:34:32 2006 Minero Aoki <aamine@loveruby.net>
|
|
253
253
|
|
254
254
|
* lib/racc/grammar.rb: class RuleTable -> Grammar.
|
255
255
|
|
256
|
-
* lib/racc/grammar.rb: Grammar.new does not
|
256
|
+
* lib/racc/grammar.rb: Grammar.new does not accept a Compiler.
|
257
257
|
|
258
258
|
* lib/racc/grammar.rb: refactoring.
|
259
259
|
|
@@ -285,7 +285,7 @@ Mon Jul 3 04:34:32 2006 Minero Aoki <aamine@loveruby.net>
|
|
285
285
|
|
286
286
|
* lib/racc/state.rb: class StateTable -> States.
|
287
287
|
|
288
|
-
* lib/racc/state.rb: States.new does not
|
288
|
+
* lib/racc/state.rb: States.new does not accept a Compiler.
|
289
289
|
|
290
290
|
* lib/racc/state.rb: refactoring.
|
291
291
|
|
@@ -418,7 +418,7 @@ Tue Jul 26 23:37:46 2005 Minero Aoki <aamine@loveruby.net>
|
|
418
418
|
|
419
419
|
Sun Jan 2 11:48:19 2005 Minero Aoki <aamine@loveruby.net>
|
420
420
|
|
421
|
-
* lib/racc/
|
421
|
+
* lib/racc/grammar.rb (once_writer): bug! needs argument.
|
422
422
|
|
423
423
|
Mon Feb 16 16:14:16 2004 Minero Aoki <aamine@loveruby.net>
|
424
424
|
|
data/README.ja.rdoc
CHANGED
@@ -1,23 +1,15 @@
|
|
1
1
|
= Racc
|
2
2
|
|
3
|
-
*
|
3
|
+
* https://github.com/ruby/racc
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
Racc は LALR(1) パーサジェネレータです。
|
8
8
|
yacc の Ruby 版に相当します。
|
9
9
|
|
10
|
-
NOTE:
|
11
|
-
Ruby 1.8.0 からは Racc のランタイムが標準添付されているので、
|
12
|
-
Racc で生成したパーサを安心して配布できます。また Ruby 1.6 系に
|
13
|
-
対応させたい場合は racc -E で生成してください。
|
14
|
-
|
15
|
-
|
16
10
|
== 必要環境
|
17
11
|
|
18
|
-
* Ruby
|
19
|
-
(*) C コンパイラと make
|
20
|
-
|
12
|
+
* Ruby 2.5 以降
|
21
13
|
|
22
14
|
== インストール
|
23
15
|
|
@@ -25,34 +17,6 @@
|
|
25
17
|
|
26
18
|
$ gem install racc
|
27
19
|
|
28
|
-
setup.rb インストル:
|
29
|
-
|
30
|
-
パッケージのトップディレクトリで次のように入力してください。
|
31
|
-
($ は通常ユーザ、# はルートのプロンプトです)
|
32
|
-
|
33
|
-
$ ruby setup.rb config
|
34
|
-
$ ruby setup.rb setup
|
35
|
-
($ su)
|
36
|
-
# ruby setup.rb install
|
37
|
-
|
38
|
-
これで通常のパスに Racc がインストールされます。自分の好き
|
39
|
-
なディレクトリにインストールしたいときは、setup.rb config に
|
40
|
-
各種オプションをつけて実行してください。オプションのリストは
|
41
|
-
|
42
|
-
$ ruby setup.rb --help
|
43
|
-
|
44
|
-
で見られます。
|
45
|
-
|
46
|
-
|
47
|
-
コンパイラがない場合
|
48
|
-
--------------------
|
49
|
-
|
50
|
-
config を以下のようにすれば、拡張モジュールなしで
|
51
|
-
インストールできます。
|
52
|
-
|
53
|
-
$ ruby setup.rb config --without-ext
|
54
|
-
|
55
|
-
|
56
20
|
== テスト
|
57
21
|
|
58
22
|
sample/ 以下にいくつか Racc の文法ファイルのサンプルが用意
|
data/README.rdoc
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
= Racc
|
2
2
|
|
3
|
-
*
|
3
|
+
* https://github.com/ruby/racc
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
Racc is a LALR(1) parser generator.
|
8
8
|
It is written in Ruby itself, and generates Ruby program.
|
9
9
|
|
10
|
-
NOTE: Ruby 1.8.x comes with Racc runtime module. You
|
11
|
-
can run your parsers generated by racc 1.4.x out of the
|
12
|
-
box.
|
13
|
-
|
14
|
-
|
15
10
|
== Requirement
|
16
11
|
|
17
|
-
* Ruby
|
12
|
+
* Ruby 2.5 or later.
|
18
13
|
|
19
14
|
== Installation
|
20
15
|
|
@@ -22,32 +17,6 @@
|
|
22
17
|
|
23
18
|
$ gem install racc
|
24
19
|
|
25
|
-
setup.rb install:
|
26
|
-
|
27
|
-
Type this in the top directory of the extracted archive:
|
28
|
-
|
29
|
-
$ ruby setup.rb config
|
30
|
-
$ ruby setup.rb setup
|
31
|
-
($ su)
|
32
|
-
# ruby setup.rb install
|
33
|
-
|
34
|
-
You can install Racc into your favorite directory by giving
|
35
|
-
options to setup.rb. e.g.
|
36
|
-
|
37
|
-
$ ruby setup.rb config --prefix=/usr
|
38
|
-
|
39
|
-
For details, try "ruby setup.rb --help".
|
40
|
-
|
41
|
-
|
42
|
-
If you don't have C Compiler
|
43
|
-
----------------------------
|
44
|
-
|
45
|
-
You can install Racc without C compilers. Type following
|
46
|
-
command in config phase.
|
47
|
-
|
48
|
-
$ ruby setup.rb config --without-ext
|
49
|
-
|
50
|
-
|
51
20
|
== Testing Racc
|
52
21
|
|
53
22
|
Racc comes with simple calculator. To compile this, on shell:
|
@@ -59,9 +28,16 @@
|
|
59
28
|
$ ruby calc
|
60
29
|
|
61
30
|
... Does it work?
|
62
|
-
For details of Racc, see HTML documents placed under '
|
31
|
+
For details of Racc, see HTML documents placed under 'doc/en/'
|
63
32
|
and sample grammar files under 'sample/'.
|
64
33
|
|
34
|
+
== Release flow
|
35
|
+
|
36
|
+
* Update VERSION number of these files
|
37
|
+
* <code>RACC_VERSION</code> in "ext/racc/com/headius/racc/Cparse.java"
|
38
|
+
* <code>VERSION</code> in "lib/racc/info.rb"
|
39
|
+
* Release as a gem by <code>rake release</code> with CRuby and JRuby because Racc gem provides 2 packages
|
40
|
+
* Create new release on {GitHub}[https://github.com/ruby/racc/releases]
|
65
41
|
|
66
42
|
== License
|
67
43
|
|
@@ -74,7 +50,8 @@
|
|
74
50
|
== Bug Reports
|
75
51
|
|
76
52
|
Any kind of bug report is welcome.
|
77
|
-
If you find a bug of Racc, please
|
53
|
+
If you find a bug of Racc, please report an issue at
|
54
|
+
https://github.com/ruby/racc/issues. Your grammar file,
|
78
55
|
debug output generated by "racc -g", are helpful.
|
79
56
|
|
80
57
|
|
data/TODO
CHANGED
data/bin/racc
CHANGED
@@ -19,6 +19,7 @@ def main
|
|
19
19
|
make_executable = false
|
20
20
|
rubypath = nil
|
21
21
|
embed_runtime = false
|
22
|
+
frozen_strings = false
|
22
23
|
debug_flags = Racc::DebugFlags.new
|
23
24
|
line_convert = true
|
24
25
|
line_convert_all = false
|
@@ -29,7 +30,7 @@ def main
|
|
29
30
|
profiler = RaccProfiler.new(false)
|
30
31
|
|
31
32
|
parser = OptionParser.new
|
32
|
-
parser.banner = "Usage: #{File.basename($0)} [options]
|
33
|
+
parser.banner = "Usage: #{File.basename($0)} [options] [input]"
|
33
34
|
parser.on('-o', '--output-file=PATH',
|
34
35
|
'output file name [<input>.tab.rb]') {|name|
|
35
36
|
output = name
|
@@ -57,6 +58,9 @@ def main
|
|
57
58
|
parser.on('-E', '--embedded', "Embeds Racc runtime in output.") {
|
58
59
|
embed_runtime = true
|
59
60
|
}
|
61
|
+
parser.on('-F', '--frozen', "Add frozen_string_literals: true.") {
|
62
|
+
frozen_strings = true
|
63
|
+
}
|
60
64
|
parser.on('--line-convert-all', 'Converts line numbers of user codes.') {
|
61
65
|
line_convert_all = true
|
62
66
|
}
|
@@ -88,54 +92,52 @@ def main
|
|
88
92
|
#}
|
89
93
|
parser.on('--version', 'Prints version and quit.') {
|
90
94
|
puts "racc version #{Racc::Version}"
|
91
|
-
exit
|
95
|
+
exit
|
92
96
|
}
|
93
97
|
parser.on('--runtime-version', 'Prints runtime version and quit.') {
|
94
|
-
printf "racc runtime version %s; %s\n",
|
98
|
+
printf "racc runtime version %s; %s core version %s\n",
|
95
99
|
Racc::Parser::Racc_Runtime_Version,
|
100
|
+
Racc::Parser.racc_runtime_type,
|
96
101
|
if Racc::Parser.racc_runtime_type == 'ruby'
|
97
|
-
|
98
|
-
Racc::Parser::Racc_Runtime_Core_Version_R)
|
102
|
+
Racc::Parser::Racc_Runtime_Core_Version_R
|
99
103
|
else
|
100
|
-
|
101
|
-
Racc::Parser::Racc_Runtime_Core_Version_C)
|
104
|
+
Racc::Parser::Racc_Runtime_Core_Version_C
|
102
105
|
end
|
103
|
-
exit
|
106
|
+
exit
|
104
107
|
}
|
105
108
|
parser.on('--copyright', 'Prints copyright and quit.') {
|
106
109
|
puts Racc::Copyright
|
107
|
-
exit
|
110
|
+
exit
|
108
111
|
}
|
109
112
|
parser.on('--help', 'Prints this message and quit.') {
|
110
113
|
puts parser.help
|
111
|
-
exit
|
114
|
+
exit
|
112
115
|
}
|
113
116
|
begin
|
114
117
|
parser.parse!
|
115
118
|
rescue OptionParser::ParseError => err
|
116
|
-
|
117
|
-
$stderr.puts parser.help
|
118
|
-
exit 1
|
119
|
-
end
|
120
|
-
if ARGV.empty?
|
121
|
-
$stderr.puts 'no input'
|
122
|
-
exit 1
|
119
|
+
abort [err.message, parser.help].join("\n")
|
123
120
|
end
|
124
121
|
if ARGV.size > 1
|
125
|
-
|
126
|
-
|
122
|
+
abort 'too many input'
|
123
|
+
end
|
124
|
+
|
125
|
+
input = ARGV[0] || "stdin"
|
126
|
+
|
127
|
+
if input == "stdin" && !output then
|
128
|
+
abort 'You must specify a path to read or use -o <path> for output.'
|
127
129
|
end
|
128
|
-
input = ARGV[0]
|
129
130
|
|
130
131
|
begin
|
131
132
|
$stderr.puts 'Parsing grammar file...' if verbose
|
132
133
|
result = profiler.section('parse') {
|
133
134
|
parser = Racc::GrammarFileParser.new(debug_flags)
|
134
|
-
|
135
|
+
content = input == "stdin" ? ARGF.read : File.read(input)
|
136
|
+
parser.parse(content, File.basename(input))
|
135
137
|
}
|
136
138
|
if check_only
|
137
139
|
$stderr.puts 'syntax ok'
|
138
|
-
exit
|
140
|
+
exit
|
139
141
|
end
|
140
142
|
|
141
143
|
$stderr.puts 'Generating LALR states...' if verbose
|
@@ -150,6 +152,7 @@ def main
|
|
150
152
|
|
151
153
|
$stderr.puts 'Creating parser file...' if verbose
|
152
154
|
params = result.params.dup
|
155
|
+
params.filename = File.basename(input)
|
153
156
|
# Overwrites parameters given by a grammar file with command line options.
|
154
157
|
params.superclass = superclass if superclass
|
155
158
|
params.omit_action_call = true if omit_action_call
|
@@ -162,6 +165,7 @@ def main
|
|
162
165
|
params.convert_line = line_convert
|
163
166
|
params.convert_line_all = line_convert_all
|
164
167
|
params.embed_runtime = embed_runtime
|
168
|
+
params.frozen_strings = frozen_strings
|
165
169
|
profiler.section('generation') {
|
166
170
|
generator = Racc::ParserFileGenerator.new(states, params)
|
167
171
|
generator.generate_parser_file(output || make_filename(input, '.tab.rb'))
|
@@ -189,11 +193,13 @@ def main
|
|
189
193
|
end
|
190
194
|
|
191
195
|
profiler.report
|
196
|
+
if states.should_error_on_expect_mismatch?
|
197
|
+
raise Racc::CompileError, "#{states.grammar.n_expected_srconflicts} shift/reduce conflicts are expected but #{states.n_srconflicts} shift/reduce conflicts exist"
|
198
|
+
end
|
192
199
|
rescue Racc::Error, Errno::ENOENT, Errno::EPERM => err
|
193
200
|
raise if $DEBUG or debug_flags.any?
|
194
201
|
lineno = err.message.slice(/\A\d+:/).to_s
|
195
|
-
|
196
|
-
exit 1
|
202
|
+
abort "#{File.basename $0}: #{input}:#{lineno} #{err.message.strip}"
|
197
203
|
end
|
198
204
|
end
|
199
205
|
|
@@ -270,19 +276,13 @@ class RaccProfiler
|
|
270
276
|
def initialize(really)
|
271
277
|
@really = really
|
272
278
|
@log = []
|
273
|
-
unless ::Process.respond_to?(:times)
|
274
|
-
# Ruby 1.6
|
275
|
-
@class = ::Time
|
276
|
-
else
|
277
|
-
@class = ::Process
|
278
|
-
end
|
279
279
|
end
|
280
280
|
|
281
281
|
def section(name)
|
282
282
|
if @really
|
283
|
-
t1 =
|
283
|
+
t1 = ::Process.times.utime
|
284
284
|
result = yield
|
285
|
-
t2 =
|
285
|
+
t2 = ::Process.times.utime
|
286
286
|
@log.push [name, t2 - t1]
|
287
287
|
result
|
288
288
|
else
|
data/doc/en/grammar.en.rdoc
CHANGED
@@ -15,48 +15,47 @@ supported: Ruby style (`# ...`) and C style (`/* ... */`).
|
|
15
15
|
== Class Block
|
16
16
|
|
17
17
|
The class block is formed like this:
|
18
|
-
|
19
|
-
class CLASS_NAME
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rule
|
27
|
-
|
28
|
-
|
18
|
+
|
19
|
+
class CLASS_NAME
|
20
|
+
[precedence table]
|
21
|
+
[token declarations]
|
22
|
+
[expected number of S/R conflict]
|
23
|
+
[options]
|
24
|
+
[semantic value conversion]
|
25
|
+
[start rule]
|
26
|
+
rule
|
27
|
+
GRAMMARS
|
28
|
+
|
29
29
|
CLASS_NAME is a name of parser class.
|
30
30
|
This is the name of generating parser class.
|
31
31
|
|
32
32
|
If CLASS_NAME includes '::', Racc outputs module clause.
|
33
|
-
For example, writing "class M::C" causes creating the code
|
34
|
-
|
35
|
-
module M
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
For example, writing "class M::C" causes creating the code below:
|
34
|
+
|
35
|
+
module M
|
36
|
+
class C
|
37
|
+
:
|
38
|
+
:
|
39
|
+
end
|
39
40
|
end
|
40
|
-
end
|
41
|
-
--
|
42
41
|
|
43
42
|
== Grammar Block
|
44
43
|
|
45
44
|
The grammar block describes the grammar
|
46
45
|
to be understood by parser. Syntax is:
|
47
|
-
--
|
48
|
-
(token): (token) (token) (token).... (action)
|
49
46
|
|
50
|
-
(token): (token) (token) (token).... (action)
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
(token): (token) (token) (token).... (action)
|
48
|
+
|
49
|
+
(token): (token) (token) (token).... (action)
|
50
|
+
| (token) (token) (token).... (action)
|
51
|
+
| (token) (token) (token).... (action)
|
52
|
+
|
54
53
|
(action) is an action which is executed when its (token)s are found.
|
55
54
|
(action) is a ruby code block, which is surrounded by braces:
|
56
|
-
|
57
|
-
{ print val[0]
|
58
|
-
|
59
|
-
|
55
|
+
|
56
|
+
{ print val[0]
|
57
|
+
puts val[1] }
|
58
|
+
|
60
59
|
Note that you cannot use '%' string, here document, '%r' regexp in action.
|
61
60
|
|
62
61
|
Actions can be omitted.
|
@@ -66,20 +65,20 @@ A return value of action is a value of left side value ($$).
|
|
66
65
|
It is value of result, or returned value by "return" statement.
|
67
66
|
|
68
67
|
Here is an example of whole grammar block.
|
69
|
-
|
70
|
-
rule
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
68
|
+
|
69
|
+
rule
|
70
|
+
goal: definition rules source { result = val }
|
71
|
+
|
72
|
+
definition: /* none */ { result = [] }
|
73
|
+
| definition startdesig { result[0] = val[1] }
|
74
|
+
| definition
|
75
|
+
precrule # this line continue from upper line
|
76
|
+
{
|
77
|
+
result[1] = val[1]
|
78
|
+
}
|
79
|
+
|
80
|
+
startdesig: START TOKEN
|
81
|
+
|
83
82
|
You can use following special local variables in action.
|
84
83
|
|
85
84
|
* result ($$)
|
@@ -99,45 +98,43 @@ DO NOT MODIFY this stack unless you know what you are doing.
|
|
99
98
|
|
100
99
|
This function is equal to '%prec' in yacc.
|
101
100
|
To designate this block:
|
102
|
-
|
103
|
-
prechigh
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
preclow
|
109
|
-
|
101
|
+
|
102
|
+
prechigh
|
103
|
+
nonassoc '++'
|
104
|
+
left '*' '/'
|
105
|
+
left '+' '-'
|
106
|
+
right '='
|
107
|
+
preclow
|
108
|
+
|
110
109
|
`right' is yacc's %right, `left' is yacc's %left.
|
111
110
|
|
112
111
|
`=' + (symbol) means yacc's %prec:
|
113
|
-
|
114
|
-
prechigh
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
preclow
|
119
|
-
|
120
|
-
rule
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
--
|
112
|
+
|
113
|
+
prechigh
|
114
|
+
nonassoc UMINUS
|
115
|
+
left '*' '/'
|
116
|
+
left '+' '-'
|
117
|
+
preclow
|
118
|
+
|
119
|
+
rule
|
120
|
+
exp: exp '*' exp
|
121
|
+
| exp '-' exp
|
122
|
+
| '-' exp =UMINUS # equals to "%prec UMINUS"
|
123
|
+
:
|
124
|
+
:
|
127
125
|
|
128
126
|
== expect
|
129
127
|
|
130
128
|
Racc supports Bison's "expect" directive to declare the expected
|
131
129
|
number of shift/reduce conflicts.
|
132
|
-
--
|
133
|
-
class MyParser
|
134
|
-
rule
|
135
|
-
expect 3
|
136
|
-
:
|
137
|
-
:
|
138
|
-
--
|
139
|
-
Then warnings are issued only when the effective number of conflicts differs.
|
140
130
|
|
131
|
+
class MyParser
|
132
|
+
expect 3
|
133
|
+
rule
|
134
|
+
:
|
135
|
+
:
|
136
|
+
|
137
|
+
Then warnings are issued only when the effective number of conflicts differs.
|
141
138
|
|
142
139
|
== Declaring Tokens
|
143
140
|
|
@@ -145,17 +142,16 @@ Declaring tokens avoids many bugs.
|
|
145
142
|
|
146
143
|
Racc outputs warnings for declared tokens that do not exist, or existing tokens not declared.
|
147
144
|
The syntax is:
|
148
|
-
|
149
|
-
token TOKEN_NAME AND_IS_THIS
|
150
|
-
|
151
|
-
--
|
145
|
+
|
146
|
+
token TOKEN_NAME AND_IS_THIS
|
147
|
+
ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
|
152
148
|
|
153
149
|
== Options
|
154
150
|
|
155
151
|
You can write options for racc command in your racc file.
|
156
|
-
|
157
|
-
options OPTION OPTION ...
|
158
|
-
|
152
|
+
|
153
|
+
options OPTION OPTION ...
|
154
|
+
|
159
155
|
Options are:
|
160
156
|
|
161
157
|
* omit_action_call
|
@@ -179,32 +175,29 @@ Token symbols are, as default,
|
|
179
175
|
|
180
176
|
You can change this default using a "convert" block.
|
181
177
|
Here is an example:
|
182
|
-
|
183
|
-
convert
|
184
|
-
|
185
|
-
|
186
|
-
end
|
187
|
-
|
178
|
+
|
179
|
+
convert
|
180
|
+
PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
|
181
|
+
MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
|
182
|
+
end
|
183
|
+
|
188
184
|
We can use almost all ruby value can be used by token symbol,
|
189
185
|
except 'false' and 'nil'. These are causes unexpected parse error.
|
190
186
|
|
191
187
|
If you want to use String as token symbol, special care is required.
|
192
188
|
For example:
|
193
|
-
|
194
|
-
convert
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
--
|
189
|
+
|
190
|
+
convert
|
191
|
+
class '"cls"' # in code, "cls"
|
192
|
+
PLUS '"plus\n"' # in code, "plus\n"
|
193
|
+
MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
|
194
|
+
end
|
200
195
|
|
201
196
|
== Start Rule
|
202
197
|
|
203
198
|
'%start' in yacc. This changes the start symbol.
|
204
|
-
--
|
205
|
-
start real_target
|
206
|
-
--
|
207
199
|
|
200
|
+
start real_target
|
208
201
|
|
209
202
|
== User Code Block
|
210
203
|
|
@@ -213,14 +206,13 @@ There are three user code blocks, "header" "inner" and "footer".
|
|
213
206
|
|
214
207
|
User code blocks are introduced by four '-' at the beginning of a line,
|
215
208
|
followed by a single-word name:
|
216
|
-
|
217
|
-
---- header
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
---- inner
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
--
|
209
|
+
|
210
|
+
---- header
|
211
|
+
ruby statement
|
212
|
+
ruby statement
|
213
|
+
ruby statement
|
214
|
+
|
215
|
+
---- inner
|
216
|
+
ruby statement
|
217
|
+
:
|
218
|
+
:
|
data/doc/en/grammar2.en.rdoc
CHANGED
data/doc/ja/command.ja.html
CHANGED
@@ -6,6 +6,7 @@ racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
|
|
6
6
|
[-O<var>filename</var>] [--log-file=<var>filename</var>]
|
7
7
|
[-g] [--debug]
|
8
8
|
[-E] [--embedded]
|
9
|
+
[-F] [--frozen]
|
9
10
|
[-l] [--no-line-convert]
|
10
11
|
[-c] [--line-convert-all]
|
11
12
|
[-a] [--no-omit-actions]
|
@@ -50,6 +51,10 @@ Ruby のパスを使用します。
|
|
50
51
|
ランタイムルーチンをすべて含んだコードを生成します。
|
51
52
|
つまり、このオプションをつけて生成したコードは Ruby さえあれば動きます。
|
52
53
|
</dd>
|
54
|
+
<dt>-F, --frozen
|
55
|
+
<dd>
|
56
|
+
Add frozen_string_literals: true.
|
57
|
+
</dd>
|
53
58
|
<dt>-C, --check-only
|
54
59
|
<dd>
|
55
60
|
(文法ファイルの) 文法のチェックだけをして終了します。
|
data/doc/ja/grammar.ja.rdoc
CHANGED