antelope 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +25 -25
  3. data/.rspec +3 -3
  4. data/.travis.yml +10 -10
  5. data/.yardopts +7 -7
  6. data/CONTRIBUTING.md +50 -38
  7. data/GENERATORS.md +180 -124
  8. data/Gemfile +7 -7
  9. data/LICENSE.txt +22 -22
  10. data/README.md +240 -104
  11. data/Rakefile +2 -2
  12. data/TODO.md +58 -58
  13. data/antelope.gemspec +29 -28
  14. data/bin/antelope +7 -7
  15. data/examples/deterministic.ace +35 -35
  16. data/examples/example.ace +52 -51
  17. data/examples/example.ace.err +192 -192
  18. data/examples/example.ace.inf +432 -432
  19. data/examples/example.ate +70 -70
  20. data/examples/example.ate.err +192 -192
  21. data/examples/example.ate.inf +432 -432
  22. data/examples/liquidscript.ace +233 -233
  23. data/examples/simple.ace +22 -22
  24. data/lib/antelope/ace/compiler.rb +334 -334
  25. data/lib/antelope/ace/errors.rb +30 -30
  26. data/lib/antelope/ace/scanner/argument.rb +57 -57
  27. data/lib/antelope/ace/scanner/first.rb +89 -89
  28. data/lib/antelope/ace/scanner/second.rb +178 -178
  29. data/lib/antelope/ace/scanner/third.rb +27 -27
  30. data/lib/antelope/ace/scanner.rb +144 -144
  31. data/lib/antelope/ace.rb +47 -47
  32. data/lib/antelope/cli.rb +60 -60
  33. data/lib/antelope/errors.rb +25 -25
  34. data/lib/antelope/generation/constructor/first.rb +86 -86
  35. data/lib/antelope/generation/constructor/follow.rb +105 -105
  36. data/lib/antelope/generation/constructor/nullable.rb +64 -64
  37. data/lib/antelope/generation/constructor.rb +127 -127
  38. data/lib/antelope/generation/errors.rb +17 -17
  39. data/lib/antelope/generation/null.rb +13 -13
  40. data/lib/antelope/generation/recognizer/rule.rb +216 -216
  41. data/lib/antelope/generation/recognizer/state.rb +129 -129
  42. data/lib/antelope/generation/recognizer.rb +177 -177
  43. data/lib/antelope/generation/tableizer.rb +176 -176
  44. data/lib/antelope/generation.rb +15 -15
  45. data/lib/antelope/generator/base/coerce.rb +115 -0
  46. data/lib/antelope/generator/base/extra.rb +50 -0
  47. data/lib/antelope/generator/base.rb +134 -264
  48. data/lib/antelope/generator/c.rb +11 -11
  49. data/lib/antelope/generator/c_header.rb +105 -105
  50. data/lib/antelope/generator/c_source.rb +39 -39
  51. data/lib/antelope/generator/error.rb +34 -34
  52. data/lib/antelope/generator/group.rb +60 -57
  53. data/lib/antelope/generator/html.rb +51 -51
  54. data/lib/antelope/generator/info.rb +47 -47
  55. data/lib/antelope/generator/null.rb +18 -18
  56. data/lib/antelope/generator/output.rb +17 -17
  57. data/lib/antelope/generator/ruby.rb +112 -79
  58. data/lib/antelope/generator/templates/c_header.ant +36 -36
  59. data/lib/antelope/generator/templates/c_source.ant +202 -202
  60. data/lib/antelope/generator/templates/error.erb +40 -0
  61. data/lib/antelope/generator/templates/html/antelope.css +53 -1
  62. data/lib/antelope/generator/templates/html/antelope.html +82 -1
  63. data/lib/antelope/generator/templates/html/antelope.js +9 -1
  64. data/lib/antelope/generator/templates/html/css.ant +53 -53
  65. data/lib/antelope/generator/templates/html/html.ant +82 -82
  66. data/lib/antelope/generator/templates/html/js.ant +9 -9
  67. data/lib/antelope/generator/templates/info.erb +61 -0
  68. data/lib/antelope/generator/templates/{ruby.ant → ruby.erb} +171 -178
  69. data/lib/antelope/generator.rb +62 -66
  70. data/lib/antelope/grammar/generation.rb +76 -76
  71. data/lib/antelope/grammar/loading.rb +84 -84
  72. data/lib/antelope/grammar/precedence.rb +59 -59
  73. data/lib/antelope/grammar/precedences.rb +64 -64
  74. data/lib/antelope/grammar/production.rb +56 -56
  75. data/lib/antelope/grammar/productions.rb +154 -154
  76. data/lib/antelope/grammar/symbols.rb +64 -64
  77. data/lib/antelope/grammar/token/epsilon.rb +23 -23
  78. data/lib/antelope/grammar/token/error.rb +24 -24
  79. data/lib/antelope/grammar/token/nonterminal.rb +15 -15
  80. data/lib/antelope/grammar/token/terminal.rb +15 -15
  81. data/lib/antelope/grammar/token.rb +231 -231
  82. data/lib/antelope/grammar.rb +68 -68
  83. data/lib/antelope/version.rb +6 -6
  84. data/lib/antelope.rb +18 -19
  85. data/optimizations.txt +42 -42
  86. data/spec/antelope/ace/compiler_spec.rb +60 -60
  87. data/spec/antelope/ace/scanner_spec.rb +27 -27
  88. data/spec/antelope/generation/constructor_spec.rb +131 -131
  89. data/spec/fixtures/simple.ace +22 -22
  90. data/spec/spec_helper.rb +39 -39
  91. data/spec/support/benchmark_helper.rb +5 -5
  92. data/spec/support/grammar_helper.rb +14 -14
  93. data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
  94. data/subl/Ace (Ruby).tmLanguage +153 -153
  95. metadata +22 -11
  96. data/lib/antelope/generator/templates/error.ant +0 -34
  97. data/lib/antelope/generator/templates/info.ant +0 -53
  98. data/lib/antelope/template/compiler.rb +0 -78
  99. data/lib/antelope/template/errors.rb +0 -9
  100. data/lib/antelope/template/scanner.rb +0 -109
  101. data/lib/antelope/template.rb +0 -64
  102. data/spec/antelope/template_spec.rb +0 -50
@@ -1,39 +1,39 @@
1
- module Antelope
2
- module Generator
3
- class CSource < CHeader
4
-
5
- def action_for(state)
6
- out = ""
7
-
8
- grammar.terminals.each do |terminal|
9
- action = state[terminal.name]
10
-
11
- if action.size == 2 && action[0] == :state
12
- out << "#{action[1] + 1}, "
13
- elsif action.size == 2 &&
14
- [:reduce, :accept].include?(action[0])
15
- if $DEBUG
16
- out << "#{prefix.upcase}STATES + #{action[1] + 1}, "
17
- else
18
- out << "#{table.size + action[1] + 1}, "
19
- end
20
- else
21
- out << "0, "
22
- end
23
-
24
- end
25
-
26
- out.chomp(", ")
27
- end
28
-
29
- def cify_block(block)
30
- block.gsub(/\$([0-9]+)/, "#{prefix}vals[\\1]")
31
- .gsub(/\$\$/, "#{prefix}out")
32
- end
33
-
34
- def generate
35
- template "c_source", "#{file}.c"
36
- end
37
- end
38
- end
39
- end
1
+ module Antelope
2
+ module Generator
3
+ class CSource < CHeader
4
+
5
+ def action_for(state)
6
+ out = ""
7
+
8
+ grammar.terminals.each do |terminal|
9
+ action = state[terminal.name]
10
+
11
+ if action.size == 2 && action[0] == :state
12
+ out << "#{action[1] + 1}, "
13
+ elsif action.size == 2 &&
14
+ [:reduce, :accept].include?(action[0])
15
+ if $DEBUG
16
+ out << "#{prefix.upcase}STATES + #{action[1] + 1}, "
17
+ else
18
+ out << "#{table.size + action[1] + 1}, "
19
+ end
20
+ else
21
+ out << "0, "
22
+ end
23
+
24
+ end
25
+
26
+ out.chomp(", ")
27
+ end
28
+
29
+ def cify_block(block)
30
+ block.gsub(/\$([0-9]+)/, "#{prefix}vals[\\1]")
31
+ .gsub(/\$\$/, "#{prefix}out")
32
+ end
33
+
34
+ def generate
35
+ template "c_source", "#{file}.c"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,34 +1,34 @@
1
- # encoding: utf-8
2
-
3
- module Antelope
4
- module Generator
5
-
6
- # Generates an output file, mainly for debugging. Included always
7
- # as a generator for a grammar.
8
- class Error < Base
9
-
10
- register_as "error"
11
-
12
- has_directive "output.verbose", Boolean
13
-
14
- # Defines singleton method for every mod that the grammar passed
15
- # to the generator.
16
- #
17
- # @see Generator#initialize
18
- def initialize(*)
19
- super
20
- mods.each do |k, v|
21
- define_singleton_method (k) { v }
22
- end
23
- end
24
-
25
- # Actually performs the generation. Uses the template in
26
- # output.erb, and generates the file `<file>.output`.
27
- #
28
- # @return [void]
29
- def generate
30
- template "error", "#{file}.err"
31
- end
32
- end
33
- end
34
- end
1
+ # encoding: utf-8
2
+
3
+ module Antelope
4
+ module Generator
5
+
6
+ # Generates an output file, mainly for debugging. Included always
7
+ # as a generator for a grammar.
8
+ class Error < Base
9
+
10
+ register_as "error"
11
+
12
+ has_directive "output.verbose", Boolean
13
+
14
+ # Defines singleton method for every mod that the grammar passed
15
+ # to the generator.
16
+ #
17
+ # @see Generator#initialize
18
+ def initialize(*)
19
+ super
20
+ mods.each do |k, v|
21
+ define_singleton_method (k) { v }
22
+ end
23
+ end
24
+
25
+ # Actually performs the generation. Uses the template in
26
+ # output.erb, and generates the file `<file>.output`.
27
+ #
28
+ # @return [void]
29
+ def generate
30
+ template "error", "#{file}.err"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,57 +1,60 @@
1
- module Antelope
2
- module Generator
3
-
4
- # For use to use multiple generators as a bundle. Works exactly
5
- # like a normal generator, i.e. responds to both {.register_as}
6
- # and {#generate}, but also responds to {.register_generator},
7
- # like {Generator}. Any generators registered to the group are
8
- # used to generate the files.
9
- #
10
- # @abtract Subclass and use {.register_generator} to create a
11
- # group generator.
12
- class Group < Base
13
-
14
- extend Generator
15
-
16
- # Initialize the group generator. Calls {Base#initialize}, and
17
- # then instantizes all of the generators in the group.
18
- def initialize(*_)
19
- super
20
-
21
- generators.map! do |gen|
22
- gen.new(*_)
23
- end
24
- end
25
-
26
- # Generates files using the generators contained within this
27
- # group. If it encounters an error in one of the generators, it
28
- # will continue to try to generate the rest of the generators.
29
- # It will then raise the last error given at the end.
30
- #
31
- # @return [void]
32
- def generate
33
- error = nil
34
- generators.map do |gen|
35
- begin
36
- gen.generate
37
- rescue => e
38
- $stderr.puts "Error running #{gen.class}: #{e.message}"
39
- error = e
40
- end
41
- end
42
-
43
- raise error if error
44
- end
45
-
46
- private
47
-
48
- # Retrieve a list of all of the generators that are contained
49
- # within this group.
50
- #
51
- # @return [Array<Generator::Base>]
52
- def generators
53
- @_generators ||= self.class.generators.values
54
- end
55
- end
56
- end
57
- end
1
+ module Antelope
2
+ module Generator
3
+
4
+ # For use to use multiple generators as a bundle. Works exactly
5
+ # like a normal generator, i.e. responds to both {.register_as}
6
+ # and {#generate}, but also responds to {.register_generator},
7
+ # like {Generator}. Any generators registered to the group are
8
+ # used to generate the files.
9
+ #
10
+ # @abtract Subclass and use {.register_generator} to create a
11
+ # group generator.
12
+ class Group < Base
13
+
14
+ extend Generator
15
+
16
+ # Initialize the group generator. Calls {Base#initialize}, and
17
+ # then instantizes all of the generators in the group.
18
+ def initialize(*_)
19
+ super
20
+
21
+ generators.map! do |gen|
22
+ gen.new(*_)
23
+ end
24
+ end
25
+
26
+ # Generates files using the generators contained within this
27
+ # group. If it encounters an error in one of the generators, it
28
+ # will continue to try to generate the rest of the generators.
29
+ # It will then raise the last error given at the end.
30
+ #
31
+ # @return [void]
32
+ def generate
33
+ error = nil
34
+ generators.map do |gen|
35
+ begin
36
+ gen.generate
37
+ rescue => e
38
+ puts "Error running #{gen.class}: #{e.message}"
39
+ error = e
40
+ rescue SyntaxError => e
41
+ puts "Error running #{gen.class}: #{e.message}"
42
+ error = e
43
+ end
44
+ end
45
+
46
+ raise error if error
47
+ end
48
+
49
+ private
50
+
51
+ # Retrieve a list of all of the generators that are contained
52
+ # within this group.
53
+ #
54
+ # @return [Array<Generator::Base>]
55
+ def generators
56
+ @_generators ||= self.class.generators.values
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,51 +1,51 @@
1
- # encoding: utf-8
2
-
3
- module Antelope
4
- module Generator
5
-
6
- # Generates an output file, mainly for debugging. Included always
7
- # as a generator for a grammar.
8
- class HTML < Base
9
-
10
- register_as "html"
11
-
12
- has_directive "html.show-lookahead", Boolean
13
-
14
- # Defines singleton method for every mod that the grammar passed
15
- # to the generator.
16
- #
17
- # @see Generator#initialize
18
- def initialize(*)
19
- super
20
- mods.each do |k, v|
21
- define_singleton_method (k) { v }
22
- end
23
- end
24
-
25
- def unused_symbols
26
- @_unused_symbols ||= begin
27
- used = grammar.all_productions.map(&:items).flatten.uniq
28
- all = grammar.symbols.map do |s|
29
- if Symbol === s
30
- grammar.find_token(s)
31
- else
32
- s
33
- end
34
- end
35
-
36
- all - used - [grammar.find_token(:"$start")]
37
- end
38
- end
39
-
40
- # Actually performs the generation. Uses the template in
41
- # output.erb, and generates the file `<file>.output`.
42
- #
43
- # @return [void]
44
- def generate
45
- template "html/html", "#{file}.html"
46
- template "html/css", "#{file}.css"
47
- template "html/js", "#{file}.js"
48
- end
49
- end
50
- end
51
- end
1
+ # encoding: utf-8
2
+
3
+ module Antelope
4
+ module Generator
5
+
6
+ # Generates an output file, mainly for debugging. Included always
7
+ # as a generator for a grammar.
8
+ class HTML < Base
9
+
10
+ register_as "html"
11
+
12
+ has_directive "html.show-lookahead", Boolean
13
+
14
+ # Defines singleton method for every mod that the grammar passed
15
+ # to the generator.
16
+ #
17
+ # @see Generator#initialize
18
+ def initialize(*)
19
+ super
20
+ mods.each do |k, v|
21
+ define_singleton_method (k) { v }
22
+ end
23
+ end
24
+
25
+ def unused_symbols
26
+ @_unused_symbols ||= begin
27
+ used = grammar.all_productions.map(&:items).flatten.uniq
28
+ all = grammar.symbols.map do |s|
29
+ if Symbol === s
30
+ grammar.find_token(s)
31
+ else
32
+ s
33
+ end
34
+ end
35
+
36
+ all - used - [grammar.find_token(:"$start")]
37
+ end
38
+ end
39
+
40
+ # Actually performs the generation. Uses the template in
41
+ # output.erb, and generates the file `<file>.output`.
42
+ #
43
+ # @return [void]
44
+ def generate
45
+ template "html/html", "#{file}.html"
46
+ template "html/css", "#{file}.css"
47
+ template "html/js", "#{file}.js"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,47 +1,47 @@
1
- # encoding: utf-8
2
-
3
- module Antelope
4
- module Generator
5
-
6
- # Generates an output file, mainly for debugging. Included always
7
- # as a generator for a grammar.
8
- class Info < Base
9
-
10
- register_as "info"
11
-
12
- # Defines singleton method for every mod that the grammar passed
13
- # to the generator.
14
- #
15
- # @see Generator#initialize
16
- def initialize(*)
17
- super
18
- mods.each do |k, v|
19
- define_singleton_method (k) { v }
20
- end
21
- end
22
-
23
- def unused_symbols
24
- @_unused_symbols ||= begin
25
- used = grammar.all_productions.map(&:items).flatten.uniq
26
- all = grammar.symbols.map do |s|
27
- if Symbol === s
28
- grammar.find_token(s)
29
- else
30
- s
31
- end
32
- end
33
-
34
- all - used - [grammar.find_token(:"$start")]
35
- end
36
- end
37
-
38
- # Actually performs the generation. Uses the template in
39
- # output.erb, and generates the file `<file>.output`.
40
- #
41
- # @return [void]
42
- def generate
43
- template "info", "#{file}.inf"
44
- end
45
- end
46
- end
47
- end
1
+ # encoding: utf-8
2
+
3
+ module Antelope
4
+ module Generator
5
+
6
+ # Generates an output file, mainly for debugging. Included always
7
+ # as a generator for a grammar.
8
+ class Info < Base
9
+
10
+ register_as "info"
11
+
12
+ # Defines singleton method for every mod that the grammar passed
13
+ # to the generator.
14
+ #
15
+ # @see Generator#initialize
16
+ def initialize(*)
17
+ super
18
+ mods.each do |k, v|
19
+ define_singleton_method (k) { v }
20
+ end
21
+ end
22
+
23
+ def unused_symbols
24
+ @_unused_symbols ||= begin
25
+ used = grammar.all_productions.map(&:items).flatten.uniq
26
+ all = grammar.symbols.map do |s|
27
+ if Symbol === s
28
+ grammar.find_token(s)
29
+ else
30
+ s
31
+ end
32
+ end
33
+
34
+ all - used - [grammar.find_token(:"$start")]
35
+ end
36
+ end
37
+
38
+ # Actually performs the generation. Uses the template in
39
+ # output.erb, and generates the file `<file>.output`.
40
+ #
41
+ # @return [void]
42
+ def generate
43
+ template "info", "#{file}.inf"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,18 +1,18 @@
1
- module Antelope
2
- module Generator
3
-
4
- # Represents a generator that does not generate anything.
5
- class Null < Base
6
-
7
- register_as "null"
8
-
9
- has_directive "null.data"
10
- has_directive "comment"
11
-
12
- # Does nothing.
13
- #
14
- # @return [void]
15
- def generate; end
16
- end
17
- end
18
- end
1
+ module Antelope
2
+ module Generator
3
+
4
+ # Represents a generator that does not generate anything.
5
+ class Null < Base
6
+
7
+ register_as "null"
8
+
9
+ has_directive "null.data"
10
+ has_directive "comment"
11
+
12
+ # Does nothing.
13
+ #
14
+ # @return [void]
15
+ def generate; end
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,17 @@
1
- # encoding: utf-8
2
-
3
- module Antelope
4
- module Generator
5
-
6
- # Generates an output file, mainly for debugging. Included always
7
- # as a generator for a grammar.
8
- class Output < Group
9
-
10
- register_as "output"
11
-
12
- register_generator Info, "info"
13
- register_generator Error, "error"
14
-
15
- end
16
- end
17
- end
1
+ # encoding: utf-8
2
+
3
+ module Antelope
4
+ module Generator
5
+
6
+ # Generates an output file, mainly for debugging. Included always
7
+ # as a generator for a grammar.
8
+ class Output < Group
9
+
10
+ register_as "output"
11
+
12
+ register_generator Info, "info"
13
+ register_generator Error, "error"
14
+
15
+ end
16
+ end
17
+ end