antelope 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +25 -25
- data/.rspec +3 -3
- data/.travis.yml +10 -10
- data/.yardopts +7 -7
- data/CONTRIBUTING.md +50 -38
- data/GENERATORS.md +180 -124
- data/Gemfile +7 -7
- data/LICENSE.txt +22 -22
- data/README.md +240 -104
- data/Rakefile +2 -2
- data/TODO.md +58 -58
- data/antelope.gemspec +29 -28
- data/bin/antelope +7 -7
- data/examples/deterministic.ace +35 -35
- data/examples/example.ace +52 -51
- data/examples/example.ace.err +192 -192
- data/examples/example.ace.inf +432 -432
- data/examples/example.ate +70 -70
- data/examples/example.ate.err +192 -192
- data/examples/example.ate.inf +432 -432
- data/examples/liquidscript.ace +233 -233
- data/examples/simple.ace +22 -22
- data/lib/antelope/ace/compiler.rb +334 -334
- data/lib/antelope/ace/errors.rb +30 -30
- data/lib/antelope/ace/scanner/argument.rb +57 -57
- data/lib/antelope/ace/scanner/first.rb +89 -89
- data/lib/antelope/ace/scanner/second.rb +178 -178
- data/lib/antelope/ace/scanner/third.rb +27 -27
- data/lib/antelope/ace/scanner.rb +144 -144
- data/lib/antelope/ace.rb +47 -47
- data/lib/antelope/cli.rb +60 -60
- data/lib/antelope/errors.rb +25 -25
- data/lib/antelope/generation/constructor/first.rb +86 -86
- data/lib/antelope/generation/constructor/follow.rb +105 -105
- data/lib/antelope/generation/constructor/nullable.rb +64 -64
- data/lib/antelope/generation/constructor.rb +127 -127
- data/lib/antelope/generation/errors.rb +17 -17
- data/lib/antelope/generation/null.rb +13 -13
- data/lib/antelope/generation/recognizer/rule.rb +216 -216
- data/lib/antelope/generation/recognizer/state.rb +129 -129
- data/lib/antelope/generation/recognizer.rb +177 -177
- data/lib/antelope/generation/tableizer.rb +176 -176
- data/lib/antelope/generation.rb +15 -15
- data/lib/antelope/generator/base/coerce.rb +115 -0
- data/lib/antelope/generator/base/extra.rb +50 -0
- data/lib/antelope/generator/base.rb +134 -264
- data/lib/antelope/generator/c.rb +11 -11
- data/lib/antelope/generator/c_header.rb +105 -105
- data/lib/antelope/generator/c_source.rb +39 -39
- data/lib/antelope/generator/error.rb +34 -34
- data/lib/antelope/generator/group.rb +60 -57
- data/lib/antelope/generator/html.rb +51 -51
- data/lib/antelope/generator/info.rb +47 -47
- data/lib/antelope/generator/null.rb +18 -18
- data/lib/antelope/generator/output.rb +17 -17
- data/lib/antelope/generator/ruby.rb +112 -79
- data/lib/antelope/generator/templates/c_header.ant +36 -36
- data/lib/antelope/generator/templates/c_source.ant +202 -202
- data/lib/antelope/generator/templates/error.erb +40 -0
- data/lib/antelope/generator/templates/html/antelope.css +53 -1
- data/lib/antelope/generator/templates/html/antelope.html +82 -1
- data/lib/antelope/generator/templates/html/antelope.js +9 -1
- data/lib/antelope/generator/templates/html/css.ant +53 -53
- data/lib/antelope/generator/templates/html/html.ant +82 -82
- data/lib/antelope/generator/templates/html/js.ant +9 -9
- data/lib/antelope/generator/templates/info.erb +61 -0
- data/lib/antelope/generator/templates/{ruby.ant → ruby.erb} +171 -178
- data/lib/antelope/generator.rb +62 -66
- data/lib/antelope/grammar/generation.rb +76 -76
- data/lib/antelope/grammar/loading.rb +84 -84
- data/lib/antelope/grammar/precedence.rb +59 -59
- data/lib/antelope/grammar/precedences.rb +64 -64
- data/lib/antelope/grammar/production.rb +56 -56
- data/lib/antelope/grammar/productions.rb +154 -154
- data/lib/antelope/grammar/symbols.rb +64 -64
- data/lib/antelope/grammar/token/epsilon.rb +23 -23
- data/lib/antelope/grammar/token/error.rb +24 -24
- data/lib/antelope/grammar/token/nonterminal.rb +15 -15
- data/lib/antelope/grammar/token/terminal.rb +15 -15
- data/lib/antelope/grammar/token.rb +231 -231
- data/lib/antelope/grammar.rb +68 -68
- data/lib/antelope/version.rb +6 -6
- data/lib/antelope.rb +18 -19
- data/optimizations.txt +42 -42
- data/spec/antelope/ace/compiler_spec.rb +60 -60
- data/spec/antelope/ace/scanner_spec.rb +27 -27
- data/spec/antelope/generation/constructor_spec.rb +131 -131
- data/spec/fixtures/simple.ace +22 -22
- data/spec/spec_helper.rb +39 -39
- data/spec/support/benchmark_helper.rb +5 -5
- data/spec/support/grammar_helper.rb +14 -14
- data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
- data/subl/Ace (Ruby).tmLanguage +153 -153
- metadata +22 -11
- data/lib/antelope/generator/templates/error.ant +0 -34
- data/lib/antelope/generator/templates/info.ant +0 -53
- data/lib/antelope/template/compiler.rb +0 -78
- data/lib/antelope/template/errors.rb +0 -9
- data/lib/antelope/template/scanner.rb +0 -109
- data/lib/antelope/template.rb +0 -64
- data/spec/antelope/template_spec.rb +0 -50
@@ -1,231 +1,231 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'antelope/grammar/token/nonterminal'
|
4
|
-
require 'antelope/grammar/token/terminal'
|
5
|
-
require 'antelope/grammar/token/epsilon'
|
6
|
-
require 'antelope/grammar/token/error'
|
7
|
-
|
8
|
-
module Antelope
|
9
|
-
class Grammar
|
10
|
-
# Defines a token type for productions/rules.
|
11
|
-
#
|
12
|
-
# @abstract This class should be inherited to define a real token.
|
13
|
-
# A base class does not match any token; however, any token can
|
14
|
-
# match the base class.
|
15
|
-
class Token
|
16
|
-
# The name of the token.
|
17
|
-
#
|
18
|
-
# @return [Symbol]
|
19
|
-
attr_reader :name
|
20
|
-
|
21
|
-
# The from state that this token is transitioned from. This is
|
22
|
-
# the _source_. This is used in the constructor in order to
|
23
|
-
# handle lookahead sets.
|
24
|
-
#
|
25
|
-
# @return [Recognizer::State]
|
26
|
-
attr_reader :from
|
27
|
-
|
28
|
-
# The to state that this token is transitioned to. This is the
|
29
|
-
# _destination_. This is used in the constructor in order to
|
30
|
-
# handle lookahead sets.
|
31
|
-
#
|
32
|
-
# @return [Recognizer::State]
|
33
|
-
attr_reader :to
|
34
|
-
|
35
|
-
# The type of the token. This is given by a caret argument to
|
36
|
-
# the grammar. This is primarily used for generators.
|
37
|
-
#
|
38
|
-
# @return [String]
|
39
|
-
attr_reader :type
|
40
|
-
|
41
|
-
attr_accessor :id
|
42
|
-
|
43
|
-
# Initialize.
|
44
|
-
#
|
45
|
-
# @param name [Symbol] the name of the token.
|
46
|
-
# @param type [String?] the type of the token. For definitions,
|
47
|
-
# this is the given type of the token (for typed language
|
48
|
-
# output).
|
49
|
-
# @param id [String?] the id of the token in the production.
|
50
|
-
# For some languages, this allows references to the token via
|
51
|
-
# the id.
|
52
|
-
# @param value [String?] the value of the token. This is only
|
53
|
-
# used in output representation to the developer.
|
54
|
-
def initialize(name, type = nil, id = nil, value = nil)
|
55
|
-
@name = name
|
56
|
-
@value = value
|
57
|
-
@type = type
|
58
|
-
@id = id
|
59
|
-
@from = nil
|
60
|
-
@to = nil
|
61
|
-
end
|
62
|
-
|
63
|
-
include Comparable
|
64
|
-
|
65
|
-
# Whether or not the token is a terminal.
|
66
|
-
#
|
67
|
-
# @abstract
|
68
|
-
# @return [Boolean]
|
69
|
-
def terminal?
|
70
|
-
false
|
71
|
-
end
|
72
|
-
|
73
|
-
# Whether or not the token is a nonterminal.
|
74
|
-
#
|
75
|
-
# @abstract
|
76
|
-
# @return [Boolean]
|
77
|
-
def nonterminal?
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
# Whether or not the token is an epsilon token.
|
82
|
-
#
|
83
|
-
# @abstract
|
84
|
-
# @return [Boolean]
|
85
|
-
def epsilon?
|
86
|
-
false
|
87
|
-
end
|
88
|
-
|
89
|
-
# Whether or not the token is an error token.
|
90
|
-
#
|
91
|
-
# @abstract
|
92
|
-
# @return [Boolean]
|
93
|
-
def error?
|
94
|
-
false
|
95
|
-
end
|
96
|
-
|
97
|
-
# Sets the from state of the token and invalidates the cache.
|
98
|
-
#
|
99
|
-
# @param state [Recognizer::State]
|
100
|
-
# @return [void]
|
101
|
-
def from=(state)
|
102
|
-
invalidate_cache!
|
103
|
-
@from = state
|
104
|
-
end
|
105
|
-
|
106
|
-
# Sets the to state of the token and invalidates the cache.
|
107
|
-
#
|
108
|
-
# @param state [Recognizer::State]
|
109
|
-
# @return [void]
|
110
|
-
def to=(state)
|
111
|
-
invalidate_cache!
|
112
|
-
@to = state
|
113
|
-
end
|
114
|
-
|
115
|
-
# Sets the type of the token and invalidates the cache.
|
116
|
-
#
|
117
|
-
# @param type [String]
|
118
|
-
# @return [void]
|
119
|
-
def type=(type)
|
120
|
-
invalidate_cache!
|
121
|
-
@type = type
|
122
|
-
end
|
123
|
-
|
124
|
-
# Gives a string representation of the token. The output is
|
125
|
-
# formatted like so: `<data>["(" [<from_id>][:<to_id>] ")"]`,
|
126
|
-
# where `<data>` is either the value (if it's non-nil) or the
|
127
|
-
# name, `<from_id>` is the from state id, and `<to_id>` is the
|
128
|
-
# to state id. The last part of the format is optional; if
|
129
|
-
# neither the from state or to state is non-nil, it's non-
|
130
|
-
# existant.
|
131
|
-
#
|
132
|
-
# @return [String] the string representation.
|
133
|
-
# @see #from
|
134
|
-
# @see #to
|
135
|
-
# @see #name
|
136
|
-
def to_s
|
137
|
-
buf = if @value
|
138
|
-
@value.inspect
|
139
|
-
else
|
140
|
-
@name.to_s
|
141
|
-
end
|
142
|
-
|
143
|
-
if from || to
|
144
|
-
buf << '('
|
145
|
-
buf << "#{from.id}" if from
|
146
|
-
buf << ":#{to.id}" if to
|
147
|
-
buf << ')'
|
148
|
-
end
|
149
|
-
|
150
|
-
buf
|
151
|
-
end
|
152
|
-
|
153
|
-
# Returns a nice inspect.
|
154
|
-
#
|
155
|
-
# @return [String]
|
156
|
-
def inspect
|
157
|
-
"#<#{self.class} from=#{from.id if from} to=#{to.id if to} " \
|
158
|
-
"name=#{name.inspect} value=#{@value.inspect}>"
|
159
|
-
end
|
160
|
-
|
161
|
-
# Compares this class to any other object. If the other object
|
162
|
-
# is a token, it converts both this class and the other object
|
163
|
-
# to an array and compares the array. Otherwise, it delegates
|
164
|
-
# the comparison.
|
165
|
-
#
|
166
|
-
# @param other [Object] the other object to compare.
|
167
|
-
# @return [Numeric]
|
168
|
-
def <=>(other)
|
169
|
-
if other.is_a? Token
|
170
|
-
to_a <=> other.to_a
|
171
|
-
else
|
172
|
-
super
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
alias_method :eql?, :==
|
177
|
-
|
178
|
-
# Compares this class and another object, fuzzily. If the other
|
179
|
-
# object is a token, it removes the transitions (to and from)
|
180
|
-
# on both objects and compares them like that. Otherwise, it
|
181
|
-
# delegates the comparison.
|
182
|
-
#
|
183
|
-
# @param other [Object] the other object to compare.
|
184
|
-
# @return [Boolean] if they are equal.
|
185
|
-
def ===(other)
|
186
|
-
if other.is_a? Token
|
187
|
-
without_transitions == other.without_transitions
|
188
|
-
else
|
189
|
-
super
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# Creates a new token without to or from states.
|
194
|
-
#
|
195
|
-
# @return [Token]
|
196
|
-
def without_transitions
|
197
|
-
self.class.new(name, @type, @id, @value)
|
198
|
-
end
|
199
|
-
|
200
|
-
# Invalidates the cache.
|
201
|
-
#
|
202
|
-
# @return [void]
|
203
|
-
def invalidate_cache!
|
204
|
-
@_hash = nil
|
205
|
-
@_array = nil
|
206
|
-
end
|
207
|
-
|
208
|
-
# Generates a hash for this class.
|
209
|
-
#
|
210
|
-
# @note This is not intended for use. It is only defined to be
|
211
|
-
# compatible with Hashs (and by extension, Sets).
|
212
|
-
# @private
|
213
|
-
# @return [Object]
|
214
|
-
def hash
|
215
|
-
@_hash ||= to_a.hash
|
216
|
-
end
|
217
|
-
|
218
|
-
alias_method :eql?, :==
|
219
|
-
|
220
|
-
# Creates an array representation of this class.
|
221
|
-
#
|
222
|
-
# @note This is not intended for use. It is only defined to
|
223
|
-
# make equality checking easier, and to create a hash.
|
224
|
-
# @private
|
225
|
-
# @return [Array<(Recognizer::State, Recognizer::State, Class, Symbol, String?)>]
|
226
|
-
def to_a
|
227
|
-
@_array ||= [to, from, self.class, name, @value]
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'antelope/grammar/token/nonterminal'
|
4
|
+
require 'antelope/grammar/token/terminal'
|
5
|
+
require 'antelope/grammar/token/epsilon'
|
6
|
+
require 'antelope/grammar/token/error'
|
7
|
+
|
8
|
+
module Antelope
|
9
|
+
class Grammar
|
10
|
+
# Defines a token type for productions/rules.
|
11
|
+
#
|
12
|
+
# @abstract This class should be inherited to define a real token.
|
13
|
+
# A base class does not match any token; however, any token can
|
14
|
+
# match the base class.
|
15
|
+
class Token
|
16
|
+
# The name of the token.
|
17
|
+
#
|
18
|
+
# @return [Symbol]
|
19
|
+
attr_reader :name
|
20
|
+
|
21
|
+
# The from state that this token is transitioned from. This is
|
22
|
+
# the _source_. This is used in the constructor in order to
|
23
|
+
# handle lookahead sets.
|
24
|
+
#
|
25
|
+
# @return [Recognizer::State]
|
26
|
+
attr_reader :from
|
27
|
+
|
28
|
+
# The to state that this token is transitioned to. This is the
|
29
|
+
# _destination_. This is used in the constructor in order to
|
30
|
+
# handle lookahead sets.
|
31
|
+
#
|
32
|
+
# @return [Recognizer::State]
|
33
|
+
attr_reader :to
|
34
|
+
|
35
|
+
# The type of the token. This is given by a caret argument to
|
36
|
+
# the grammar. This is primarily used for generators.
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
attr_reader :type
|
40
|
+
|
41
|
+
attr_accessor :id
|
42
|
+
|
43
|
+
# Initialize.
|
44
|
+
#
|
45
|
+
# @param name [Symbol] the name of the token.
|
46
|
+
# @param type [String?] the type of the token. For definitions,
|
47
|
+
# this is the given type of the token (for typed language
|
48
|
+
# output).
|
49
|
+
# @param id [String?] the id of the token in the production.
|
50
|
+
# For some languages, this allows references to the token via
|
51
|
+
# the id.
|
52
|
+
# @param value [String?] the value of the token. This is only
|
53
|
+
# used in output representation to the developer.
|
54
|
+
def initialize(name, type = nil, id = nil, value = nil)
|
55
|
+
@name = name
|
56
|
+
@value = value
|
57
|
+
@type = type
|
58
|
+
@id = id
|
59
|
+
@from = nil
|
60
|
+
@to = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
include Comparable
|
64
|
+
|
65
|
+
# Whether or not the token is a terminal.
|
66
|
+
#
|
67
|
+
# @abstract
|
68
|
+
# @return [Boolean]
|
69
|
+
def terminal?
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
# Whether or not the token is a nonterminal.
|
74
|
+
#
|
75
|
+
# @abstract
|
76
|
+
# @return [Boolean]
|
77
|
+
def nonterminal?
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
81
|
+
# Whether or not the token is an epsilon token.
|
82
|
+
#
|
83
|
+
# @abstract
|
84
|
+
# @return [Boolean]
|
85
|
+
def epsilon?
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
# Whether or not the token is an error token.
|
90
|
+
#
|
91
|
+
# @abstract
|
92
|
+
# @return [Boolean]
|
93
|
+
def error?
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
97
|
+
# Sets the from state of the token and invalidates the cache.
|
98
|
+
#
|
99
|
+
# @param state [Recognizer::State]
|
100
|
+
# @return [void]
|
101
|
+
def from=(state)
|
102
|
+
invalidate_cache!
|
103
|
+
@from = state
|
104
|
+
end
|
105
|
+
|
106
|
+
# Sets the to state of the token and invalidates the cache.
|
107
|
+
#
|
108
|
+
# @param state [Recognizer::State]
|
109
|
+
# @return [void]
|
110
|
+
def to=(state)
|
111
|
+
invalidate_cache!
|
112
|
+
@to = state
|
113
|
+
end
|
114
|
+
|
115
|
+
# Sets the type of the token and invalidates the cache.
|
116
|
+
#
|
117
|
+
# @param type [String]
|
118
|
+
# @return [void]
|
119
|
+
def type=(type)
|
120
|
+
invalidate_cache!
|
121
|
+
@type = type
|
122
|
+
end
|
123
|
+
|
124
|
+
# Gives a string representation of the token. The output is
|
125
|
+
# formatted like so: `<data>["(" [<from_id>][:<to_id>] ")"]`,
|
126
|
+
# where `<data>` is either the value (if it's non-nil) or the
|
127
|
+
# name, `<from_id>` is the from state id, and `<to_id>` is the
|
128
|
+
# to state id. The last part of the format is optional; if
|
129
|
+
# neither the from state or to state is non-nil, it's non-
|
130
|
+
# existant.
|
131
|
+
#
|
132
|
+
# @return [String] the string representation.
|
133
|
+
# @see #from
|
134
|
+
# @see #to
|
135
|
+
# @see #name
|
136
|
+
def to_s
|
137
|
+
buf = if @value
|
138
|
+
@value.inspect
|
139
|
+
else
|
140
|
+
@name.to_s
|
141
|
+
end
|
142
|
+
|
143
|
+
if from || to
|
144
|
+
buf << '('
|
145
|
+
buf << "#{from.id}" if from
|
146
|
+
buf << ":#{to.id}" if to
|
147
|
+
buf << ')'
|
148
|
+
end
|
149
|
+
|
150
|
+
buf
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns a nice inspect.
|
154
|
+
#
|
155
|
+
# @return [String]
|
156
|
+
def inspect
|
157
|
+
"#<#{self.class} from=#{from.id if from} to=#{to.id if to} " \
|
158
|
+
"name=#{name.inspect} value=#{@value.inspect}>"
|
159
|
+
end
|
160
|
+
|
161
|
+
# Compares this class to any other object. If the other object
|
162
|
+
# is a token, it converts both this class and the other object
|
163
|
+
# to an array and compares the array. Otherwise, it delegates
|
164
|
+
# the comparison.
|
165
|
+
#
|
166
|
+
# @param other [Object] the other object to compare.
|
167
|
+
# @return [Numeric]
|
168
|
+
def <=>(other)
|
169
|
+
if other.is_a? Token
|
170
|
+
to_a <=> other.to_a
|
171
|
+
else
|
172
|
+
super
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
alias_method :eql?, :==
|
177
|
+
|
178
|
+
# Compares this class and another object, fuzzily. If the other
|
179
|
+
# object is a token, it removes the transitions (to and from)
|
180
|
+
# on both objects and compares them like that. Otherwise, it
|
181
|
+
# delegates the comparison.
|
182
|
+
#
|
183
|
+
# @param other [Object] the other object to compare.
|
184
|
+
# @return [Boolean] if they are equal.
|
185
|
+
def ===(other)
|
186
|
+
if other.is_a? Token
|
187
|
+
without_transitions == other.without_transitions
|
188
|
+
else
|
189
|
+
super
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# Creates a new token without to or from states.
|
194
|
+
#
|
195
|
+
# @return [Token]
|
196
|
+
def without_transitions
|
197
|
+
self.class.new(name, @type, @id, @value)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Invalidates the cache.
|
201
|
+
#
|
202
|
+
# @return [void]
|
203
|
+
def invalidate_cache!
|
204
|
+
@_hash = nil
|
205
|
+
@_array = nil
|
206
|
+
end
|
207
|
+
|
208
|
+
# Generates a hash for this class.
|
209
|
+
#
|
210
|
+
# @note This is not intended for use. It is only defined to be
|
211
|
+
# compatible with Hashs (and by extension, Sets).
|
212
|
+
# @private
|
213
|
+
# @return [Object]
|
214
|
+
def hash
|
215
|
+
@_hash ||= to_a.hash
|
216
|
+
end
|
217
|
+
|
218
|
+
alias_method :eql?, :==
|
219
|
+
|
220
|
+
# Creates an array representation of this class.
|
221
|
+
#
|
222
|
+
# @note This is not intended for use. It is only defined to
|
223
|
+
# make equality checking easier, and to create a hash.
|
224
|
+
# @private
|
225
|
+
# @return [Array<(Recognizer::State, Recognizer::State, Class, Symbol, String?)>]
|
226
|
+
def to_a
|
227
|
+
@_array ||= [to, from, self.class, name, @value]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
data/lib/antelope/grammar.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'hashie'
|
4
|
-
require 'antelope/grammar/symbols'
|
5
|
-
require 'antelope/grammar/productions'
|
6
|
-
require 'antelope/grammar/production'
|
7
|
-
require 'antelope/grammar/precedences'
|
8
|
-
require 'antelope/grammar/precedence'
|
9
|
-
require 'antelope/grammar/loading'
|
10
|
-
require 'antelope/grammar/generation'
|
11
|
-
require 'antelope/grammar/token'
|
12
|
-
|
13
|
-
module Antelope
|
14
|
-
# Defines a grammar from an Ace file. This handles setting up
|
15
|
-
# productions, loading from files, symbols, precedence, and
|
16
|
-
# generation.
|
17
|
-
class Grammar
|
18
|
-
include Symbols
|
19
|
-
include Productions
|
20
|
-
include Precedences
|
21
|
-
include Loading
|
22
|
-
include Grammar::Generation
|
23
|
-
|
24
|
-
# Used by a generation class; this is all the generated states
|
25
|
-
# of the grammar.
|
26
|
-
#
|
27
|
-
# @return [Set<Generation::Recognizer::State>]
|
28
|
-
# @see Generation::Recognizer
|
29
|
-
attr_accessor :states
|
30
|
-
|
31
|
-
# The name of the grammar. This is normally assumed from a file
|
32
|
-
# name.
|
33
|
-
#
|
34
|
-
# @return [String]
|
35
|
-
attr_accessor :name
|
36
|
-
|
37
|
-
# The output directory for the grammar. This is normally the
|
38
|
-
# same directory as the Ace file.
|
39
|
-
#
|
40
|
-
# @return [Pathname]
|
41
|
-
attr_accessor :output
|
42
|
-
|
43
|
-
# The compiler for the Ace file.
|
44
|
-
#
|
45
|
-
# @return [Compiler]
|
46
|
-
attr_reader :compiler
|
47
|
-
|
48
|
-
# Initialize.
|
49
|
-
#
|
50
|
-
# @param name [String]
|
51
|
-
# @param output [String] the output directory. Automagically
|
52
|
-
# turned into a Pathname.
|
53
|
-
# @param compiler [Compiler]
|
54
|
-
def initialize(name, output, compiler)
|
55
|
-
@name = name
|
56
|
-
@output = Pathname.new(output)
|
57
|
-
@compiler = compiler
|
58
|
-
end
|
59
|
-
|
60
|
-
# Extra options from the compiler. This can be used by
|
61
|
-
# generators for output information.
|
62
|
-
#
|
63
|
-
# @return [Hash]
|
64
|
-
def options
|
65
|
-
compiler.options[:extra]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
require 'antelope/grammar/symbols'
|
5
|
+
require 'antelope/grammar/productions'
|
6
|
+
require 'antelope/grammar/production'
|
7
|
+
require 'antelope/grammar/precedences'
|
8
|
+
require 'antelope/grammar/precedence'
|
9
|
+
require 'antelope/grammar/loading'
|
10
|
+
require 'antelope/grammar/generation'
|
11
|
+
require 'antelope/grammar/token'
|
12
|
+
|
13
|
+
module Antelope
|
14
|
+
# Defines a grammar from an Ace file. This handles setting up
|
15
|
+
# productions, loading from files, symbols, precedence, and
|
16
|
+
# generation.
|
17
|
+
class Grammar
|
18
|
+
include Symbols
|
19
|
+
include Productions
|
20
|
+
include Precedences
|
21
|
+
include Loading
|
22
|
+
include Grammar::Generation
|
23
|
+
|
24
|
+
# Used by a generation class; this is all the generated states
|
25
|
+
# of the grammar.
|
26
|
+
#
|
27
|
+
# @return [Set<Generation::Recognizer::State>]
|
28
|
+
# @see Generation::Recognizer
|
29
|
+
attr_accessor :states
|
30
|
+
|
31
|
+
# The name of the grammar. This is normally assumed from a file
|
32
|
+
# name.
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
attr_accessor :name
|
36
|
+
|
37
|
+
# The output directory for the grammar. This is normally the
|
38
|
+
# same directory as the Ace file.
|
39
|
+
#
|
40
|
+
# @return [Pathname]
|
41
|
+
attr_accessor :output
|
42
|
+
|
43
|
+
# The compiler for the Ace file.
|
44
|
+
#
|
45
|
+
# @return [Compiler]
|
46
|
+
attr_reader :compiler
|
47
|
+
|
48
|
+
# Initialize.
|
49
|
+
#
|
50
|
+
# @param name [String]
|
51
|
+
# @param output [String] the output directory. Automagically
|
52
|
+
# turned into a Pathname.
|
53
|
+
# @param compiler [Compiler]
|
54
|
+
def initialize(name, output, compiler)
|
55
|
+
@name = name
|
56
|
+
@output = Pathname.new(output)
|
57
|
+
@compiler = compiler
|
58
|
+
end
|
59
|
+
|
60
|
+
# Extra options from the compiler. This can be used by
|
61
|
+
# generators for output information.
|
62
|
+
#
|
63
|
+
# @return [Hash]
|
64
|
+
def options
|
65
|
+
compiler.options[:extra]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/antelope/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Antelope
|
4
|
-
# The current running version of antelope.
|
5
|
-
VERSION = '0.
|
6
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Antelope
|
4
|
+
# The current running version of antelope.
|
5
|
+
VERSION = '0.4.0'.freeze
|
6
|
+
end
|
data/lib/antelope.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'antelope/errors'
|
4
|
-
require 'antelope/generation'
|
5
|
-
require 'antelope/generator'
|
6
|
-
require 'antelope/version'
|
7
|
-
require 'antelope/grammar'
|
8
|
-
require 'antelope/ace'
|
9
|
-
require 'antelope/dsl'
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'antelope/errors'
|
4
|
+
require 'antelope/generation'
|
5
|
+
require 'antelope/generator'
|
6
|
+
require 'antelope/version'
|
7
|
+
require 'antelope/grammar'
|
8
|
+
require 'antelope/ace'
|
9
|
+
require 'antelope/dsl'
|
10
|
+
|
11
|
+
# Antelope, the compiler compiler.
|
12
|
+
module Antelope
|
13
|
+
def self.define(name, options = {}, &block)
|
14
|
+
@grammar = [name, options, block]
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self; attr_reader :grammar; end
|
18
|
+
end
|