racc 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1dc09f1fcbc04e87d099180c64c1566e34c7b1f59c734c60a3760b149bd1a99
4
- data.tar.gz: b74af200ad861ddad78ff850a15d7f1554c032c6e24e46841b40a212ee620a0f
3
+ metadata.gz: 5de182ad74eb075783ee57ec9f930c2d81a4d1465db436f6d5e42fb96eaa6a0f
4
+ data.tar.gz: 53cb977c27837bdf4df9cd1eae679e30a00ecb07b080e8481b59bfb66aec8bf8
5
5
  SHA512:
6
- metadata.gz: 18d137641877399ad7ca6f475405fee151af9975df5f04c894c62ed2cba11835b880da0399a69303f663f772ae2283fdd09ce4dce924463c1df8c739a3e30f29
7
- data.tar.gz: 5bec7de05bc72b35614140184f4619419b488f878206ed44d5e59405cf55045e90bd1b2eacef0501bd8195f9db035802e2f3e8d569812948cd944097a6f800f6
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 acccept a Compiler.
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 acccept a Compiler.
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/grammer.rb (once_writer): bug! needs argument.
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
- * http://i.loveruby.net/en/projects/racc/
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 1.8 以降
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
- * http://i.loveruby.net/en/projects/racc/
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 1.8.x or later.
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 'rdoc/en/'
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 email me. Your grammar file,
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
@@ -1,5 +1,5 @@
1
1
  * check 'error' token handling.
2
2
  * interactive transition table monitor.
3
3
  * support backtracking.
4
- * output Ruby extention library?
4
+ * output Ruby extension library?
5
5
  * LL(k)? (But it should not be called Racc)
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] <input>"
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 0
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
- sprintf('ruby core version %s',
98
- Racc::Parser::Racc_Runtime_Core_Version_R)
102
+ Racc::Parser::Racc_Runtime_Core_Version_R
99
103
  else
100
- sprintf('c core version %s',
101
- Racc::Parser::Racc_Runtime_Core_Version_C)
104
+ Racc::Parser::Racc_Runtime_Core_Version_C
102
105
  end
103
- exit 0
106
+ exit
104
107
  }
105
108
  parser.on('--copyright', 'Prints copyright and quit.') {
106
109
  puts Racc::Copyright
107
- exit 0
110
+ exit
108
111
  }
109
112
  parser.on('--help', 'Prints this message and quit.') {
110
113
  puts parser.help
111
- exit 1
114
+ exit
112
115
  }
113
116
  begin
114
117
  parser.parse!
115
118
  rescue OptionParser::ParseError => err
116
- $stderr.puts err.message
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
- $stderr.puts 'too many input'
126
- exit 1
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
- parser.parse(File.read(input), File.basename(input))
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 0
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
- $stderr.puts "#{File.basename $0}: #{input}:#{lineno} #{err.message.strip}"
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 = @class.times.utime
283
+ t1 = ::Process.times.utime
284
284
  result = yield
285
- t2 = @class.times.utime
285
+ t2 = ::Process.times.utime
286
286
  @log.push [name, t2 - t1]
287
287
  result
288
288
  else
@@ -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
- [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
- --
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 bellow:
34
- --
35
- module M
36
- class C
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
- | (token) (token) (token).... (action)
52
- | (token) (token) (token).... (action)
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
- puts val[1] }
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
- goal: definition rules source { result = val }
72
-
73
- definition: /* none */ { result = [] }
74
- | definition startdesig { result[0] = val[1] }
75
- | definition
76
- precrule # this line continue from upper line
77
- {
78
- result[1] = val[1]
79
- }
80
-
81
- startdesig: START TOKEN
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
- nonassoc '++'
105
- left '*' '/'
106
- left '+' '-'
107
- right '='
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
- nonassoc UMINUS
116
- left '*' '/'
117
- left '+' '-'
118
- preclow
119
-
120
- rule
121
- exp: exp '*' exp
122
- | exp '-' exp
123
- | '-' exp =UMINUS # equals to "%prec UMINUS"
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
- ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
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
- PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
185
- MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
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
- class '"cls"' # in code, "cls"
196
- PLUS '"plus\n"' # in code, "plus\n"
197
- MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
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
- ruby statement
219
- ruby statement
220
- ruby statement
221
-
222
- ---- inner
223
- ruby statement
224
- :
225
- :
226
- --
209
+
210
+ ---- header
211
+ ruby statement
212
+ ruby statement
213
+ ruby statement
214
+
215
+ ---- inner
216
+ ruby statement
217
+ :
218
+ :
@@ -127,8 +127,8 @@ Racc has bison's "expect" directive.
127
127
  # Example
128
128
 
129
129
  class MyParser
130
- rule
131
130
  expect 3
131
+ rule
132
132
  :
133
133
  :
134
134
 
@@ -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
  (文法ファイルの) 文法のチェックだけをして終了します。
@@ -173,7 +173,7 @@ target: TERM_A nonterm_a TERM_B nonterm_b
173
173
  --
174
174
  prechigh
175
175
  nonassoc PLUSPLUS
176
- left MULTI DEVIDE
176
+ left MULTI DIVIDE
177
177
  left PLUS MINUS
178
178
  right '='
179
179
  preclow
@@ -96,7 +96,7 @@ Object
96
96
  このメソッドから正常に戻った場合、パーサはエラー回復モード
97
97
  に移行します。
98
98
 
99
- error_token はパースエラーを起こした記号の内部表現 (整数) です。
99
+ error_token_id はパースエラーを起こした記号の内部表現 (整数) です。
100
100
  #token_to_str で文法ファイル上の文字列表現に直せます。
101
101
 
102
102
  error_value はその値です。