racc 1.4.6

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.
Files changed (109) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +7 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +846 -0
  5. data/DEPENDS +4 -0
  6. data/README.en.rdoc +86 -0
  7. data/README.ja.rdoc +96 -0
  8. data/Rakefile +15 -0
  9. data/TODO +5 -0
  10. data/bin/racc +308 -0
  11. data/bin/racc2y +195 -0
  12. data/bin/y2racc +339 -0
  13. data/doc/en/NEWS.en.rdoc +282 -0
  14. data/doc/en/command.en.html +78 -0
  15. data/doc/en/debug.en.rdoc +20 -0
  16. data/doc/en/grammar.en.rdoc +230 -0
  17. data/doc/en/index.en.html +10 -0
  18. data/doc/en/parser.en.rdoc +74 -0
  19. data/doc/en/usage.en.html +92 -0
  20. data/doc/ja/NEWS.ja.rdoc +307 -0
  21. data/doc/ja/command.ja.html +94 -0
  22. data/doc/ja/debug.ja.rdoc +36 -0
  23. data/doc/ja/grammar.ja.rdoc +348 -0
  24. data/doc/ja/index.ja.html +10 -0
  25. data/doc/ja/parser.ja.rdoc +125 -0
  26. data/doc/ja/usage.ja.html +414 -0
  27. data/ext/racc/cparse/MANIFEST +4 -0
  28. data/ext/racc/cparse/cparse.c +824 -0
  29. data/ext/racc/cparse/depend +1 -0
  30. data/ext/racc/cparse/extconf.rb +7 -0
  31. data/fastcache/extconf.rb +2 -0
  32. data/fastcache/fastcache.c +185 -0
  33. data/lib/racc.rb +6 -0
  34. data/lib/racc/compat.rb +40 -0
  35. data/lib/racc/debugflags.rb +59 -0
  36. data/lib/racc/exception.rb +15 -0
  37. data/lib/racc/grammar.rb +1115 -0
  38. data/lib/racc/grammarfileparser.rb +559 -0
  39. data/lib/racc/info.rb +16 -0
  40. data/lib/racc/iset.rb +91 -0
  41. data/lib/racc/logfilegenerator.rb +214 -0
  42. data/lib/racc/parser.rb +439 -0
  43. data/lib/racc/parserfilegenerator.rb +511 -0
  44. data/lib/racc/pre-setup +13 -0
  45. data/lib/racc/sourcetext.rb +34 -0
  46. data/lib/racc/state.rb +971 -0
  47. data/lib/racc/statetransitiontable.rb +316 -0
  48. data/lib/racc/static.rb +5 -0
  49. data/misc/dist.sh +31 -0
  50. data/sample/array.y +67 -0
  51. data/sample/array2.y +59 -0
  52. data/sample/calc-ja.y +66 -0
  53. data/sample/calc.y +65 -0
  54. data/sample/conflict.y +15 -0
  55. data/sample/hash.y +60 -0
  56. data/sample/lalr.y +17 -0
  57. data/sample/lists.y +57 -0
  58. data/sample/syntax.y +46 -0
  59. data/sample/yyerr.y +46 -0
  60. data/setup.rb +1587 -0
  61. data/tasks/doc.rb +12 -0
  62. data/tasks/email.rb +55 -0
  63. data/tasks/file.rb +37 -0
  64. data/tasks/gem.rb +37 -0
  65. data/tasks/test.rb +16 -0
  66. data/test/assets/chk.y +126 -0
  67. data/test/assets/conf.y +16 -0
  68. data/test/assets/digraph.y +29 -0
  69. data/test/assets/echk.y +118 -0
  70. data/test/assets/err.y +60 -0
  71. data/test/assets/expect.y +7 -0
  72. data/test/assets/firstline.y +4 -0
  73. data/test/assets/ichk.y +102 -0
  74. data/test/assets/intp.y +546 -0
  75. data/test/assets/mailp.y +437 -0
  76. data/test/assets/newsyn.y +25 -0
  77. data/test/assets/noend.y +4 -0
  78. data/test/assets/nonass.y +41 -0
  79. data/test/assets/normal.y +27 -0
  80. data/test/assets/norule.y +4 -0
  81. data/test/assets/nullbug1.y +25 -0
  82. data/test/assets/nullbug2.y +15 -0
  83. data/test/assets/opt.y +123 -0
  84. data/test/assets/percent.y +35 -0
  85. data/test/assets/recv.y +97 -0
  86. data/test/assets/rrconf.y +14 -0
  87. data/test/assets/scan.y +72 -0
  88. data/test/assets/syntax.y +50 -0
  89. data/test/assets/unterm.y +5 -0
  90. data/test/assets/useless.y +12 -0
  91. data/test/assets/yyerr.y +46 -0
  92. data/test/bench.y +36 -0
  93. data/test/helper.rb +88 -0
  94. data/test/infini.y +8 -0
  95. data/test/scandata/brace +7 -0
  96. data/test/scandata/gvar +1 -0
  97. data/test/scandata/normal +4 -0
  98. data/test/scandata/percent +18 -0
  99. data/test/scandata/slash +10 -0
  100. data/test/src.intp +34 -0
  101. data/test/start.y +20 -0
  102. data/test/test_chk_y.rb +51 -0
  103. data/test/test_grammar_file_parser.rb +15 -0
  104. data/test/test_racc_command.rb +155 -0
  105. data/test/test_scan_y.rb +51 -0
  106. data/test/testscanner.rb +51 -0
  107. data/web/racc.en.rhtml +42 -0
  108. data/web/racc.ja.rhtml +51 -0
  109. metadata +166 -0
@@ -0,0 +1,12 @@
1
+ require 'rake/rdoctask'
2
+
3
+ Rake::RDocTask.new(:docs) do |rd|
4
+ rd.main = "README.en.rdoc"
5
+ rd.rdoc_files.include(SPEC.files.find_all { |file_name|
6
+ file_name =~ /^(bin|lib|ext)/ || file_name !~ /\//
7
+ })
8
+
9
+ title = "#{SPEC.name}-#{SPEC.version} Documentation"
10
+
11
+ rd.options << "-t #{title}"
12
+ end
@@ -0,0 +1,55 @@
1
+ class EmailTask
2
+ def initialize language, readme, changelog
3
+ @language = language
4
+ @readme = readme
5
+ @changelog = changelog
6
+ @languages = {
7
+ :en => {
8
+ :release => 'release',
9
+ :released => 'has been released',
10
+ },
11
+ :ja => {
12
+ :release => 'リリース',
13
+ :released => 'はリリースしました',
14
+ }
15
+ }
16
+ define_tasks
17
+ end
18
+
19
+ private
20
+ def define_tasks
21
+ namespace :email do
22
+ task @language do
23
+ subject = "#{SPEC.name} #{SPEC.version} #{@languages[@language][:release]}"
24
+ title = "#{SPEC.name} #{SPEC.version} #{@languages[@language][:released]}!"
25
+ readme = Hash[*(File.read(@readme).split(/^(=+ .*)$/)[1..-1])]
26
+ description = readme[readme.keys.find { |x| x =~ /description/i }]
27
+ description = description.split(/\n\n+/).find { |x|
28
+ x.length > 0
29
+ }.gsub(/^\s*/, '')
30
+ urls = readme[readme.keys.find { |x| x =~ /#{SPEC.name}/i }]
31
+ urls = urls.strip.gsub(/\*\s/, '').split(/\n/).map { |s| "* <#{s}>" }
32
+ File.open("email.#{@language}.txt", "wb") { |file|
33
+ file.puts(<<-eomail)
34
+ Subject: [ANN] #{subject}
35
+
36
+ #{title}
37
+
38
+ #{urls.join("\n")}
39
+
40
+ #{description}
41
+
42
+ Changes:
43
+
44
+ #{File.read(@changelog).split(/^(===.*)/)[1..2].join.strip.gsub(/=/, '#')}
45
+
46
+ #{urls.join("\n")}
47
+ eomail
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ EmailTask.new(:en, 'README.en.rdoc', 'doc/en/NEWS.en.rdoc')
55
+ EmailTask.new(:ja, 'README.ja.rdoc', 'doc/ja/NEWS.ja.rdoc')
@@ -0,0 +1,37 @@
1
+ kind = Config::CONFIG['DLEXT']
2
+
3
+ EXT = "ext/racc/cparse/cparse.#{kind}"
4
+ [
5
+ EXT,
6
+ 'lib/racc/parser-text.rb',
7
+ 'ext/racc/cparse/Makefile',
8
+ 'ext/racc/cparse/*.o',
9
+ ].each { |f| Dir[f].each { |file| CLEAN << file } }
10
+
11
+ file 'lib/racc/parser.rb'
12
+
13
+ file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
14
+ File.open(t.name, 'wb') { |file|
15
+ file.write(<<-eorb)
16
+ module Racc
17
+ PARSER_TEXT = <<'__end_of_file__'
18
+ #{File.read(t.prerequisites.first)}
19
+ __end_of_file__
20
+ end
21
+ eorb
22
+ }
23
+ end
24
+
25
+ task 'ext/racc/cparse/Makefile' do
26
+ Dir.chdir('ext/racc/cparse') do
27
+ ruby "extconf.rb"
28
+ end
29
+ end
30
+
31
+ task EXT => 'ext/racc/cparse/Makefile' do
32
+ Dir.chdir('ext/racc/cparse') do
33
+ sh 'make'
34
+ end
35
+ end
36
+
37
+ task :build => ['lib/racc/parser-text.rb', EXT]
@@ -0,0 +1,37 @@
1
+ SPEC = Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.summary = "Racc is a LALR(1) parser generator."
4
+ s.name = 'racc'
5
+ s.authors << 'Aoki Minero'
6
+ s.authors << 'Aaron Patterson'
7
+ s.email = 'aaronp@rubyforge.org'
8
+ s.version = Racc::Parser::Racc_Runtime_Version
9
+ s.require_paths = Dir['{lib,ext}']
10
+ s.extensions = ['ext/racc/cparse/extconf.rb']
11
+ s.files = `git ls-files`.split("\n") + ['lib/racc/parser-text.rb']
12
+ s.homepage = 'http://racc.rubyforge.org/'
13
+ s.rdoc_options = ['--main', 'README.en.rdoc']
14
+ s.has_rdoc = true
15
+ s.rubyforge_project = s.name
16
+ s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
17
+ s.bindir = "bin"
18
+ s.description = <<EOF
19
+ Racc is a LALR(1) parser generator.
20
+ It is written in Ruby itself, and generates Ruby program.
21
+ EOF
22
+ end
23
+
24
+ namespace :gem do
25
+ namespace :dev do
26
+ task :spec => SPEC.files do
27
+ File.open("#{SPEC.name}.gemspec", 'w') do |f|
28
+ SPEC.version = "#{SPEC.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
29
+ f.write(SPEC.to_ruby)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Rake::GemPackageTask.new(SPEC) do |pkg|
36
+ pkg.need_tar = true
37
+ end
@@ -0,0 +1,16 @@
1
+ namespace :test do
2
+ task :multi do
3
+ sh 'multiruby -S rake clean test'
4
+ end
5
+ end
6
+
7
+ Rake::TestTask.new do |t|
8
+ %w[ ext lib ].each do |dir|
9
+ t.libs << dir
10
+ end
11
+
12
+ t.test_files = FileList['test/test_*.rb']
13
+ t.verbose = true
14
+ end
15
+
16
+ Rake::Task[:test].prerequisites << :build
@@ -0,0 +1,126 @@
1
+ #
2
+ # racc tester
3
+ #
4
+
5
+ class Calcp
6
+
7
+ prechigh
8
+ left '*' '/'
9
+ left '+' '-'
10
+ preclow
11
+
12
+ convert
13
+ NUMBER 'Number'
14
+ end
15
+
16
+ rule
17
+
18
+ target : exp | /* none */ { result = 0 } ;
19
+
20
+ exp : exp '+' exp { result += val[2]; @plus = 'plus' }
21
+ | exp '-' exp { result -= val[2]; @str = "string test" }
22
+ | exp '*' exp { result *= val[2] }
23
+ | exp '/' exp { result /= val[2] }
24
+ | '(' { $emb = true } exp ')'
25
+ {
26
+ raise 'must not happen' unless $emb
27
+ result = val[2]
28
+ }
29
+ | '-' NUMBER { result = -val[1] }
30
+ | NUMBER
31
+ ;
32
+
33
+ end
34
+
35
+ ----header
36
+
37
+ class Number; end
38
+
39
+ ----inner
40
+
41
+ def parse( src )
42
+ $emb = false
43
+ @plus = nil
44
+ @str = nil
45
+ @src = src
46
+ result = do_parse
47
+ if @plus
48
+ raise 'string parse failed' unless @plus == 'plus'
49
+ end
50
+ if @str
51
+ raise 'string parse failed' unless @str == 'string test'
52
+ end
53
+ result
54
+ end
55
+
56
+ def next_token
57
+ @src.shift
58
+ end
59
+
60
+ def initialize
61
+ @yydebug = true
62
+ end
63
+
64
+ ----footer
65
+
66
+ $parser = Calcp.new
67
+ $test_number = 1
68
+
69
+ def chk( src, ans )
70
+ result = $parser.parse(src)
71
+ raise "test #{$test_number} fail" unless result == ans
72
+ $test_number += 1
73
+ end
74
+
75
+ chk(
76
+ [ [Number, 9],
77
+ [false, false],
78
+ [false, false] ], 9
79
+ )
80
+
81
+ chk(
82
+ [ [Number, 5],
83
+ ['*', nil],
84
+ [Number, 1],
85
+ ['-', nil],
86
+ [Number, 1],
87
+ ['*', nil],
88
+ [Number, 8],
89
+ [false, false],
90
+ [false, false] ], -3
91
+ )
92
+
93
+ chk(
94
+ [ [Number, 5],
95
+ ['+', nil],
96
+ [Number, 2],
97
+ ['-', nil],
98
+ [Number, 5],
99
+ ['+', nil],
100
+ [Number, 2],
101
+ ['-', nil],
102
+ [Number, 5],
103
+ [false, false],
104
+ [false, false] ], -1
105
+ )
106
+
107
+ chk(
108
+ [ ['-', nil],
109
+ [Number, 4],
110
+ [false, false],
111
+ [false, false] ], -4
112
+ )
113
+
114
+ chk(
115
+ [ [Number, 7],
116
+ ['*', nil],
117
+ ['(', nil],
118
+ [Number, 4],
119
+ ['+', nil],
120
+ [Number, 3],
121
+ [')', nil],
122
+ ['-', nil],
123
+ [Number, 9],
124
+ [false, false],
125
+ [false, false] ], 40
126
+ )
@@ -0,0 +1,16 @@
1
+
2
+ class A
3
+ rule
4
+
5
+ a: A c C expr;
6
+
7
+ b: A B; # useless
8
+
9
+ c: A;
10
+ c: A;
11
+
12
+ expr: expr '+' expr
13
+ expr: expr '-' expr
14
+ expr: NUMBER
15
+
16
+ end
@@ -0,0 +1,29 @@
1
+ # ? detect digraph bug
2
+
3
+ class P
4
+ token A B C D
5
+ rule
6
+ target : a b c d
7
+ a : A
8
+ |
9
+ b : B
10
+ |
11
+ c : C
12
+ |
13
+ d : D
14
+ |
15
+ end
16
+
17
+ ---- inner
18
+
19
+ def parse
20
+ do_parse
21
+ end
22
+
23
+ def next_token
24
+ [false, '$']
25
+ end
26
+
27
+ ---- footer
28
+
29
+ P.new.parse
@@ -0,0 +1,118 @@
1
+ #
2
+ # racc tester
3
+ #
4
+
5
+ class Calcp
6
+
7
+ prechigh
8
+ left '*' '/'
9
+ left '+' '-'
10
+ preclow
11
+
12
+ convert
13
+ NUMBER 'Number'
14
+ end
15
+
16
+ rule
17
+
18
+ target : exp | /* none */ { result = 0 } ;
19
+
20
+ exp : exp '+' exp { result += val[2]; a = 'plus' }
21
+ | exp '-' exp { result -= val[2]; "string test" }
22
+ | exp '*' exp { result *= val[2] }
23
+ | exp '/' exp { result /= val[2] }
24
+ | '(' { $emb = true } exp ')'
25
+ {
26
+ raise 'must not happen' unless $emb
27
+ result = val[2]
28
+ }
29
+ | '-' NUMBER { result = -val[1] }
30
+ | NUMBER
31
+ ;
32
+
33
+ end
34
+
35
+ ----header
36
+
37
+ class Number ; end
38
+
39
+ ----inner
40
+
41
+ def parse( src )
42
+ @src = src
43
+ do_parse
44
+ end
45
+
46
+ def next_token
47
+ @src.shift
48
+ end
49
+
50
+ def initialize
51
+ @yydebug = true
52
+ end
53
+
54
+ ----footer
55
+
56
+ $parser = Calcp.new
57
+ $tidx = 1
58
+
59
+ def chk( src, ans )
60
+ ret = $parser.parse( src )
61
+ unless ret == ans then
62
+ bug! "test #{$tidx} fail"
63
+ end
64
+ $tidx += 1
65
+ end
66
+
67
+ chk(
68
+ [ [Number, 9],
69
+ [false, false],
70
+ [false, false] ], 9
71
+ )
72
+
73
+ chk(
74
+ [ [Number, 5],
75
+ ['*', nil],
76
+ [Number, 1],
77
+ ['-', nil],
78
+ [Number, 1],
79
+ ['*', nil],
80
+ [Number, 8],
81
+ [false, false],
82
+ [false, false] ], -3
83
+ )
84
+
85
+ chk(
86
+ [ [Number, 5],
87
+ ['+', nil],
88
+ [Number, 2],
89
+ ['-', nil],
90
+ [Number, 5],
91
+ ['+', nil],
92
+ [Number, 2],
93
+ ['-', nil],
94
+ [Number, 5],
95
+ [false, false],
96
+ [false, false] ], -1
97
+ )
98
+
99
+ chk(
100
+ [ ['-', nil],
101
+ [Number, 4],
102
+ [false, false],
103
+ [false, false] ], -4
104
+ )
105
+
106
+ chk(
107
+ [ [Number, 7],
108
+ ['*', nil],
109
+ ['(', nil],
110
+ [Number, 4],
111
+ ['+', nil],
112
+ [Number, 3],
113
+ [')', nil],
114
+ ['-', nil],
115
+ [Number, 9],
116
+ [false, false],
117
+ [false, false] ], 40
118
+ )