racc 1.6.2 → 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: 7f818fe943a0bd022e4bc6d58e4c014ecd53fabef972ae98822b155b8d3c24b0
4
- data.tar.gz: 649c807b04a435eff16318026ee39d4fa24d3422afc2ffe38fdc0737eb1c30eb
3
+ metadata.gz: 5de182ad74eb075783ee57ec9f930c2d81a4d1465db436f6d5e42fb96eaa6a0f
4
+ data.tar.gz: 53cb977c27837bdf4df9cd1eae679e30a00ecb07b080e8481b59bfb66aec8bf8
5
5
  SHA512:
6
- metadata.gz: db8d75ac8360c95552ecffd24eaa96e1f2252771fd715a8fed8f2fcfca7d8bfb3e51211089d05464ff42eacac7a063944cfe64fce571ccb6e4eca84e6391a5de
7
- data.tar.gz: '04971d555f03bfd242a4f5d75d810c5917d528b647e60fa8197d472aa9b1d3cf44b318406730e3a87427f4adad6c37b1b8427174e3480efaf237f97dc5fbac6e'
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
@@ -17,32 +17,6 @@
17
17
 
18
18
  $ gem install racc
19
19
 
20
- setup.rb install:
21
-
22
- Type this in the top directory of the extracted archive:
23
-
24
- $ ruby setup.rb config
25
- $ ruby setup.rb setup
26
- ($ su)
27
- # ruby setup.rb install
28
-
29
- You can install Racc into your favorite directory by giving
30
- options to setup.rb. e.g.
31
-
32
- $ ruby setup.rb config --prefix=/usr
33
-
34
- For details, try "ruby setup.rb --help".
35
-
36
-
37
- If you don't have C Compiler
38
- ----------------------------
39
-
40
- You can install Racc without C compilers. Type following
41
- command in config phase.
42
-
43
- $ ruby setup.rb config --without-ext
44
-
45
-
46
20
  == Testing Racc
47
21
 
48
22
  Racc comes with simple calculator. To compile this, on shell:
@@ -57,6 +31,13 @@
57
31
  For details of Racc, see HTML documents placed under 'doc/en/'
58
32
  and sample grammar files under 'sample/'.
59
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]
60
41
 
61
42
  == License
62
43
 
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 はその値です。