antelope 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -0
  3. data/bin/antelope +3 -3
  4. data/examples/{example.err → example.ace.err} +9 -9
  5. data/examples/{example.inf → example.ace.inf} +57 -9
  6. data/examples/example.ate +70 -0
  7. data/examples/example.ate.err +192 -0
  8. data/examples/example.ate.inf +432 -0
  9. data/lib/antelope/ace/compiler.rb +4 -4
  10. data/lib/antelope/ace/errors.rb +0 -18
  11. data/lib/antelope/ace.rb +6 -12
  12. data/lib/antelope/cli.rb +1 -1
  13. data/lib/antelope/dsl/compiler.rb +117 -0
  14. data/lib/antelope/dsl/contexts/base.rb +29 -0
  15. data/lib/antelope/dsl/contexts/main.rb +63 -0
  16. data/lib/antelope/dsl/contexts/match.rb +24 -0
  17. data/lib/antelope/dsl/contexts/precedence.rb +20 -0
  18. data/lib/antelope/dsl/contexts/production.rb +24 -0
  19. data/lib/antelope/dsl/contexts/terminal.rb +28 -0
  20. data/lib/antelope/dsl/contexts.rb +16 -0
  21. data/lib/antelope/dsl.rb +9 -0
  22. data/lib/antelope/errors.rb +18 -1
  23. data/lib/antelope/generation/constructor/first.rb +10 -12
  24. data/lib/antelope/generation/constructor/follow.rb +6 -6
  25. data/lib/antelope/generation/constructor/nullable.rb +6 -6
  26. data/lib/antelope/generation/constructor.rb +4 -4
  27. data/lib/antelope/generation/recognizer/rule.rb +17 -17
  28. data/lib/antelope/generation/recognizer/state.rb +9 -10
  29. data/lib/antelope/generation/recognizer.rb +8 -11
  30. data/lib/antelope/generation/tableizer.rb +2 -2
  31. data/lib/antelope/generator/base.rb +7 -7
  32. data/lib/antelope/generator/ruby.rb +1 -1
  33. data/lib/antelope/grammar/generation.rb +77 -0
  34. data/lib/antelope/grammar/loading.rb +84 -0
  35. data/lib/antelope/{ace → grammar}/precedence.rb +2 -4
  36. data/lib/antelope/grammar/precedences.rb +64 -0
  37. data/lib/antelope/{ace → grammar}/production.rb +11 -12
  38. data/lib/antelope/grammar/productions.rb +154 -0
  39. data/lib/antelope/grammar/symbols.rb +64 -0
  40. data/lib/antelope/{ace → grammar}/token/epsilon.rb +1 -2
  41. data/lib/antelope/{ace → grammar}/token/error.rb +1 -3
  42. data/lib/antelope/{ace → grammar}/token/nonterminal.rb +1 -3
  43. data/lib/antelope/{ace → grammar}/token/terminal.rb +1 -3
  44. data/lib/antelope/{ace → grammar}/token.rb +12 -15
  45. data/lib/antelope/grammar.rb +68 -0
  46. data/lib/antelope/version.rb +1 -1
  47. data/lib/antelope.rb +12 -6
  48. data/spec/antelope/ace/compiler_spec.rb +6 -6
  49. data/spec/antelope/ace/scanner_spec.rb +7 -7
  50. data/spec/antelope/generation/constructor_spec.rb +131 -0
  51. data/spec/support/grammar_helper.rb +2 -3
  52. metadata +32 -19
  53. data/lib/antelope/ace/grammar/generation.rb +0 -80
  54. data/lib/antelope/ace/grammar/loading.rb +0 -53
  55. data/lib/antelope/ace/grammar/precedences.rb +0 -68
  56. data/lib/antelope/ace/grammar/productions.rb +0 -156
  57. data/lib/antelope/ace/grammar/symbols.rb +0 -66
  58. data/lib/antelope/ace/grammar.rb +0 -69
  59. data/spec/antelope/constructor_spec.rb +0 -133
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20413ba53b4e683f49ea9740d5d336b0c530cbe4
4
- data.tar.gz: af70d6ff17e5ac4b04c41fc617855c7c087b4d3c
3
+ metadata.gz: b105a775c988ea360d76ff423672de3f08292c8a
4
+ data.tar.gz: fdb3bf76bd98071f22a514656daf4501c382f96d
5
5
  SHA512:
6
- metadata.gz: e6a9ee21ab0df5f465023e5afcdefa6d28d0ed0e3b982198af6c01a6c677b5d1df5c4ffa0bcb2d2ac4155ccadf9c08aa263d0929ea11f4952de42855b57e788b
7
- data.tar.gz: ed2503bd3fba8372cd815d45eb4646b9365d54e34632a8593de784971cbe419455a05793bd971e601c31a94831031cd1a66171d7a69f4560b668b3d03f8edb25
6
+ metadata.gz: faafcddcc85dac20ed2ca352c54254b5c66db2e318d3ca0f5ab8aa3088285b5d97b5e4c96b15eb8095fab763ceb272c7448b35c4f76c3dfc0454fcb6bd419074
7
+ data.tar.gz: 212594fc5006c2fc4880e311b47c9545cb006d85326de48bab240372dc1758a4446dbb6a93251ed6dab53d0e8fdda41ec9c2c843624de396335408436ec7fec2
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'lib/salt/parser.rb'
6
+
7
+ Style/AlignParameters:
8
+ EnforcedStyle: with_fixed_indentation
9
+
10
+ Style/SignalException:
11
+ EnforcedStyle: only_raise
data/bin/antelope CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << File.expand_path("../../lib", __FILE__)
4
- require "antelope"
5
- require "antelope/cli"
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'antelope'
5
+ require 'antelope/cli'
6
6
 
7
7
  Antelope::CLI.start
@@ -1,13 +1,13 @@
1
1
  Productions:
2
- 0 $startexpression $end
3
- 1 expressionNUMBER { |a| a[1] }
4
- 2 expression → expression "^" expression { |a, _, b| a** b }
5
- 3 expression → expression "+" expression { |a, _, b| a + b }
6
- 4 expression → expression "-" expression { |a, _, b| a - b }
7
- 5 expression → expression "*" expression { |a, _, b| a * b }
8
- 6 expression → expression "/" expression { |a, _, b| a / b }
9
- 7 expression → "(" expression ")" { |_, a, _| a }
10
- 8 expression → "(" $error ")" { |_, e, _| e[1] }
2
+ 15/n1: expressionNUMBER { |a| a[1] }
3
+ 26/n0: $startexpression $end
4
+ 79/r4: expression → expression "^" expression { |a, _, b| a** b }
5
+ 85/l2: expression → expression "+" expression { |a, _, b| a + b }
6
+ 91/l2: expression → expression "-" expression { |a, _, b| a - b }
7
+ 97/l3: expression → expression "*" expression { |a, _, b| a * b }
8
+ 103/l3: expression → expression "/" expression { |a, _, b| a / b }
9
+ 109/n1: expression → "(" expression ")" { |_, a, _| a }
10
+ 110/n1: expression → "(" $error ")" { |_, e, _| e[1] }
11
11
 
12
12
  Error:
13
13
  Conflicts in State 12:
@@ -1,13 +1,13 @@
1
1
  Productions:
2
- 0 $startexpression $end
3
- 1 expressionNUMBER { |a| a[1] }
4
- 2 expression → expression "^" expression { |a, _, b| a** b }
5
- 3 expression → expression "+" expression { |a, _, b| a + b }
6
- 4 expression → expression "-" expression { |a, _, b| a - b }
7
- 5 expression → expression "*" expression { |a, _, b| a * b }
8
- 6 expression → expression "/" expression { |a, _, b| a / b }
9
- 7 expression → "(" expression ")" { |_, a, _| a }
10
- 8 expression → "(" $error ")" { |_, e, _| e[1] }
2
+ 15/n1: expressionNUMBER { |a| a[1] }
3
+ 26/n0: $startexpression $end
4
+ 79/r4: expression → expression "^" expression { |a, _, b| a** b }
5
+ 85/l2: expression → expression "+" expression { |a, _, b| a + b }
6
+ 91/l2: expression → expression "-" expression { |a, _, b| a - b }
7
+ 97/l3: expression → expression "*" expression { |a, _, b| a * b }
8
+ 103/l3: expression → expression "/" expression { |a, _, b| a / b }
9
+ 109/n1: expression → "(" expression ")" { |_, a, _| a }
10
+ 110/n1: expression → "(" $error ")" { |_, e, _| e[1] }
11
11
 
12
12
 
13
13
  Precedence:
@@ -43,6 +43,54 @@ Precedence:
43
43
  {}
44
44
  8/n1: expression → • "(" $error ")"
45
45
  {}
46
+ 9/n0: $start → expression • $end
47
+ {}
48
+ 10/r4: expression → expression • "^" expression
49
+ {}
50
+ 11/l2: expression → expression • "+" expression
51
+ {}
52
+ 12/l2: expression → expression • "-" expression
53
+ {}
54
+ 13/l3: expression → expression • "*" expression
55
+ {}
56
+ 14/l3: expression → expression • "/" expression
57
+ {}
58
+ 15/n1: expression → NUMBER •
59
+ {$end, "^", "+", "-", "*", "/", ")"}
60
+ 16/n1: expression → "(" • expression ")"
61
+ {}
62
+ 17/n1: expression → "(" • $error ")"
63
+ {}
64
+ 26/n0: $start → expression $end •
65
+ {}
66
+ 27/r4: expression → expression "^" • expression
67
+ {}
68
+ 36/l2: expression → expression "+" • expression
69
+ {}
70
+ 45/l2: expression → expression "-" • expression
71
+ {}
72
+ 54/l3: expression → expression "*" • expression
73
+ {}
74
+ 63/l3: expression → expression "/" • expression
75
+ {}
76
+ 72/n1: expression → "(" expression • ")"
77
+ {}
78
+ 78/n1: expression → "(" $error • ")"
79
+ {}
80
+ 79/r4: expression → expression "^" expression •
81
+ {$end, "^", "+", "-", "*", "/", ")"}
82
+ 85/l2: expression → expression "+" expression •
83
+ {$end, "^", "+", "-", "*", "/", ")"}
84
+ 91/l2: expression → expression "-" expression •
85
+ {$end, "^", "+", "-", "*", "/", ")"}
86
+ 97/l3: expression → expression "*" expression •
87
+ {$end, "^", "+", "-", "*", "/", ")"}
88
+ 103/l3: expression → expression "/" expression •
89
+ {$end, "^", "+", "-", "*", "/", ")"}
90
+ 109/n1: expression → "(" expression ")" •
91
+ {$end, "^", "+", "-", "*", "/", ")"}
92
+ 110/n1: expression → "(" $error ")" •
93
+ {$end, "^", "+", "-", "*", "/", ")"}
46
94
  transitions:
47
95
  expression: State 1
48
96
  NUMBER: State 2
@@ -0,0 +1,70 @@
1
+ Antelope.define :example, version: "0.0.1", require: "~> 0.3",
2
+ output: :ruby do
3
+ define "output.verbose" => true,
4
+ "output.panic-mode" => true,
5
+ "ruby.error-class" => "SyntaxError",
6
+ "ruby.indent" => 2,
7
+ "salt.variant" => "normal"
8
+
9
+ terminals do
10
+ # We set the value to true, because the default value in a hash
11
+ # is nil.
12
+ terminal NUMBER: true,
13
+ MULTIPLY: "*",
14
+ EXPONENTIATE: "^",
15
+ DIVIDE: "/",
16
+ ADD: "+",
17
+ SUBTRACT: "-",
18
+ LPAREN: "(",
19
+ RPAREN: ")"
20
+ end
21
+
22
+ precedences do
23
+ precedence :right, [:EXPONENTIATE]
24
+ precedence :left, [:MULTIPLY, :DIVIDE]
25
+ precedence :left, [:ADD, :SUBTRACT]
26
+ end
27
+
28
+ productions do
29
+ production :expression do
30
+ match body: [:NUMBER],
31
+ action: %{ match[0][1] }
32
+ match body: [:expression, :EXPONENTIATE, :expression],
33
+ action: %{ match[0] ** match[2] }
34
+ match body: [:expression, :ADD, :expression],
35
+ action: %{ match[0] + match[2] }
36
+ match body: [:expression, :SUBTRACT, :expression],
37
+ action: %{ match[0] - match[2] }
38
+ match body: [:expression, :MULTIPLY, :expression],
39
+ action: %{ match[0] * match[2] }
40
+ match body: [:expression, :DIVIDE, :expression],
41
+ action: %{ match[0] / match[2] }
42
+ match body: [:LPAREN, :expression, :RPAREN],
43
+ action: %{ match[1] }
44
+ match body: [:LPAREN, :$error, :RPAREN],
45
+ action: %{ match[1] }
46
+ end
47
+ end
48
+
49
+ template <<-RUBY
50
+ class ExampleParser
51
+ %{write}
52
+
53
+ def type(token)
54
+ token[0]
55
+ end
56
+ end
57
+
58
+ input = [
59
+ [:LPAREN],
60
+ [:NUMBER, 2],
61
+ [:ADD],
62
+ [:ADD, 2],
63
+ [:RPAREN],
64
+ [:MULTIPLY],
65
+ [:NUMBER, 3]
66
+ ]
67
+
68
+ p ExampleParser.new.parse(input)
69
+ RUBY
70
+ end
@@ -0,0 +1,192 @@
1
+ Productions:
2
+ 15/n1: expression → NUMBER { match[0][1] }
3
+ 26/n0: $start → expression $end
4
+ 79/r4: expression → expression "^" expression { match[0] ** match[2] }
5
+ 85/l2: expression → expression "+" expression { match[0] + match[2] }
6
+ 91/l2: expression → expression "-" expression { match[0] - match[2] }
7
+ 97/l3: expression → expression "*" expression { match[0] * match[2] }
8
+ 103/l3: expression → expression "/" expression { match[0] / match[2] }
9
+ 109/n1: expression → "(" expression ")" { match[1] }
10
+ 110/n1: expression → "(" $error ")" { match[1] }
11
+
12
+ Error:
13
+ Conflicts in State 12:
14
+ On EXPONENTIATE (resolved):
15
+ state 5/reduce 2 (r4 vs r4, -1)
16
+ Rules:
17
+ 79/r4: expression → expression "^" expression •
18
+ {$end, "^", "+", "-", "*", "/", ")"}
19
+ Transitions:
20
+ 80/r4: expression → expression • "^" expression
21
+ On ADD (resolved):
22
+ state 6/reduce 2 (r4 vs l2, 1)
23
+ Rules:
24
+ 79/r4: expression → expression "^" expression •
25
+ {$end, "^", "+", "-", "*", "/", ")"}
26
+ Transitions:
27
+ 81/l2: expression → expression • "+" expression
28
+ On SUBTRACT (resolved):
29
+ state 7/reduce 2 (r4 vs l2, 1)
30
+ Rules:
31
+ 79/r4: expression → expression "^" expression •
32
+ {$end, "^", "+", "-", "*", "/", ")"}
33
+ Transitions:
34
+ 82/l2: expression → expression • "-" expression
35
+ On MULTIPLY (resolved):
36
+ state 8/reduce 2 (r4 vs l3, 1)
37
+ Rules:
38
+ 79/r4: expression → expression "^" expression •
39
+ {$end, "^", "+", "-", "*", "/", ")"}
40
+ Transitions:
41
+ 83/l3: expression → expression • "*" expression
42
+ On DIVIDE (resolved):
43
+ state 9/reduce 2 (r4 vs l3, 1)
44
+ Rules:
45
+ 79/r4: expression → expression "^" expression •
46
+ {$end, "^", "+", "-", "*", "/", ")"}
47
+ Transitions:
48
+ 84/l3: expression → expression • "/" expression
49
+ Conflicts in State 13:
50
+ On EXPONENTIATE (resolved):
51
+ state 5/reduce 3 (l2 vs r4, -1)
52
+ Rules:
53
+ 85/l2: expression → expression "+" expression •
54
+ {$end, "^", "+", "-", "*", "/", ")"}
55
+ Transitions:
56
+ 86/r4: expression → expression • "^" expression
57
+ On ADD (resolved):
58
+ state 6/reduce 3 (l2 vs l2, 1)
59
+ Rules:
60
+ 85/l2: expression → expression "+" expression •
61
+ {$end, "^", "+", "-", "*", "/", ")"}
62
+ Transitions:
63
+ 87/l2: expression → expression • "+" expression
64
+ On SUBTRACT (resolved):
65
+ state 7/reduce 3 (l2 vs l2, 1)
66
+ Rules:
67
+ 85/l2: expression → expression "+" expression •
68
+ {$end, "^", "+", "-", "*", "/", ")"}
69
+ Transitions:
70
+ 88/l2: expression → expression • "-" expression
71
+ On MULTIPLY (resolved):
72
+ state 8/reduce 3 (l2 vs l3, -1)
73
+ Rules:
74
+ 85/l2: expression → expression "+" expression •
75
+ {$end, "^", "+", "-", "*", "/", ")"}
76
+ Transitions:
77
+ 89/l3: expression → expression • "*" expression
78
+ On DIVIDE (resolved):
79
+ state 9/reduce 3 (l2 vs l3, -1)
80
+ Rules:
81
+ 85/l2: expression → expression "+" expression •
82
+ {$end, "^", "+", "-", "*", "/", ")"}
83
+ Transitions:
84
+ 90/l3: expression → expression • "/" expression
85
+ Conflicts in State 14:
86
+ On EXPONENTIATE (resolved):
87
+ state 5/reduce 4 (l2 vs r4, -1)
88
+ Rules:
89
+ 91/l2: expression → expression "-" expression •
90
+ {$end, "^", "+", "-", "*", "/", ")"}
91
+ Transitions:
92
+ 92/r4: expression → expression • "^" expression
93
+ On ADD (resolved):
94
+ state 6/reduce 4 (l2 vs l2, 1)
95
+ Rules:
96
+ 91/l2: expression → expression "-" expression •
97
+ {$end, "^", "+", "-", "*", "/", ")"}
98
+ Transitions:
99
+ 93/l2: expression → expression • "+" expression
100
+ On SUBTRACT (resolved):
101
+ state 7/reduce 4 (l2 vs l2, 1)
102
+ Rules:
103
+ 91/l2: expression → expression "-" expression •
104
+ {$end, "^", "+", "-", "*", "/", ")"}
105
+ Transitions:
106
+ 94/l2: expression → expression • "-" expression
107
+ On MULTIPLY (resolved):
108
+ state 8/reduce 4 (l2 vs l3, -1)
109
+ Rules:
110
+ 91/l2: expression → expression "-" expression •
111
+ {$end, "^", "+", "-", "*", "/", ")"}
112
+ Transitions:
113
+ 95/l3: expression → expression • "*" expression
114
+ On DIVIDE (resolved):
115
+ state 9/reduce 4 (l2 vs l3, -1)
116
+ Rules:
117
+ 91/l2: expression → expression "-" expression •
118
+ {$end, "^", "+", "-", "*", "/", ")"}
119
+ Transitions:
120
+ 96/l3: expression → expression • "/" expression
121
+ Conflicts in State 15:
122
+ On EXPONENTIATE (resolved):
123
+ state 5/reduce 5 (l3 vs r4, -1)
124
+ Rules:
125
+ 97/l3: expression → expression "*" expression •
126
+ {$end, "^", "+", "-", "*", "/", ")"}
127
+ Transitions:
128
+ 98/r4: expression → expression • "^" expression
129
+ On ADD (resolved):
130
+ state 6/reduce 5 (l3 vs l2, 1)
131
+ Rules:
132
+ 97/l3: expression → expression "*" expression •
133
+ {$end, "^", "+", "-", "*", "/", ")"}
134
+ Transitions:
135
+ 99/l2: expression → expression • "+" expression
136
+ On SUBTRACT (resolved):
137
+ state 7/reduce 5 (l3 vs l2, 1)
138
+ Rules:
139
+ 97/l3: expression → expression "*" expression •
140
+ {$end, "^", "+", "-", "*", "/", ")"}
141
+ Transitions:
142
+ 100/l2: expression → expression • "-" expression
143
+ On MULTIPLY (resolved):
144
+ state 8/reduce 5 (l3 vs l3, 1)
145
+ Rules:
146
+ 97/l3: expression → expression "*" expression •
147
+ {$end, "^", "+", "-", "*", "/", ")"}
148
+ Transitions:
149
+ 101/l3: expression → expression • "*" expression
150
+ On DIVIDE (resolved):
151
+ state 9/reduce 5 (l3 vs l3, 1)
152
+ Rules:
153
+ 97/l3: expression → expression "*" expression •
154
+ {$end, "^", "+", "-", "*", "/", ")"}
155
+ Transitions:
156
+ 102/l3: expression → expression • "/" expression
157
+ Conflicts in State 16:
158
+ On EXPONENTIATE (resolved):
159
+ state 5/reduce 6 (l3 vs r4, -1)
160
+ Rules:
161
+ 103/l3: expression → expression "/" expression •
162
+ {$end, "^", "+", "-", "*", "/", ")"}
163
+ Transitions:
164
+ 104/r4: expression → expression • "^" expression
165
+ On ADD (resolved):
166
+ state 6/reduce 6 (l3 vs l2, 1)
167
+ Rules:
168
+ 103/l3: expression → expression "/" expression •
169
+ {$end, "^", "+", "-", "*", "/", ")"}
170
+ Transitions:
171
+ 105/l2: expression → expression • "+" expression
172
+ On SUBTRACT (resolved):
173
+ state 7/reduce 6 (l3 vs l2, 1)
174
+ Rules:
175
+ 103/l3: expression → expression "/" expression •
176
+ {$end, "^", "+", "-", "*", "/", ")"}
177
+ Transitions:
178
+ 106/l2: expression → expression • "-" expression
179
+ On MULTIPLY (resolved):
180
+ state 8/reduce 6 (l3 vs l3, 1)
181
+ Rules:
182
+ 103/l3: expression → expression "/" expression •
183
+ {$end, "^", "+", "-", "*", "/", ")"}
184
+ Transitions:
185
+ 107/l3: expression → expression • "*" expression
186
+ On DIVIDE (resolved):
187
+ state 9/reduce 6 (l3 vs l3, 1)
188
+ Rules:
189
+ 103/l3: expression → expression "/" expression •
190
+ {$end, "^", "+", "-", "*", "/", ")"}
191
+ Transitions:
192
+ 108/l3: expression → expression • "/" expression