antelope 0.1.11 → 0.2.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
  SHA1:
3
- metadata.gz: e756559116af74788e49931a9ad0dd6c854e7b54
4
- data.tar.gz: 8197695fe868552cea974c23745a1691429cc49b
3
+ metadata.gz: 516fa3871c9dac6ede9010e5dce27e6427e54c0a
4
+ data.tar.gz: 05950417e688f1e91bd72533a6fba22e5b4f0c39
5
5
  SHA512:
6
- metadata.gz: 96a4da9fa6114fc0eaf54da4cc8e8476c915ff309e5814b2d21dc6a5ef6b242ee44f5788cbc930030279e549c8b5796f7357cc08b99a569198da96cc79cabd58
7
- data.tar.gz: 2f9cc8c84095e049b4dfbf26f5ed851bca8f835e4fe2b2b2e1d1c90473f37eae05d963d72280fadb7abc38c73992e4d5a58e4d42560d5358a6de9f4a3cc46ba5
6
+ metadata.gz: 5f798c4757105920b7b552891c481587654bbbf3df69fb0ab5eff2e0c6a927ddf6b5f746fa548bdf71970aebda029c249e0d1ea82d418dc88d22d6c4b378f7a1
7
+ data.tar.gz: 1a800f78ea7ba51e36a3d4e24bd905dd49b7f7b37bc4eccebbc6872230d44653252b4b288b6988e6c3470e37face35e89ffb427e7d6e73553b221c1e4cc419be
@@ -0,0 +1,162 @@
1
+ %require "~> 0.1"
2
+ %generator "ruby"
3
+
4
+ %define api.push-pull pull
5
+ %define panic-mode true
6
+ %define ruby.error-class {SyntaxError}
7
+
8
+ %terminal REGEX
9
+ %terminal DIRECTIVE
10
+ %terminal IDENTIFIER
11
+ %terminal KEYWORD
12
+ %terminal NUMBER
13
+ %terminal SSTRING
14
+ %terminal ACTION
15
+ %terminal BINOP
16
+ %terminal PREUNOP
17
+ %terminal UNOP
18
+ %terminal HEREDOC
19
+ %terminal HEREDOC_REF
20
+ %terminal IHEREDOC
21
+ %terminal IHEREDOC_REF
22
+ %terminal IHEREDOC_BEGIN
23
+ %terminal ISTRING
24
+ %terminal ISTRING_BEGIN
25
+ %terminal CLASS "class"
26
+ %terminal MODULE "module"
27
+ %terminal IF "if"
28
+ %terminal UNLESS "unless"
29
+ %terminal ELSIF "elsif"
30
+ %terminal ELSE "else"
31
+ %terminal FOR "for"
32
+ %terminal WHILE "while"
33
+ %terminal TRY "try"
34
+ %terminal CATCH "catch"
35
+ %terminal FINALLY "finally"
36
+ %terminal RETURN "return"
37
+ %terminal IN "in"
38
+ %terminal ARROW "->"
39
+ %terminal EQUAL "="
40
+ %terminal LBRACE "{"
41
+ %terminal LPAREN "("
42
+ %terminal LBRACK "["
43
+ %terminal RBRACE "}"
44
+ %terminal RPAREN ")"
45
+ %terminal RBRACK "]"
46
+ %terminal COLON ":"
47
+ %terminal RANGE ".."
48
+ %terminal ERANGE "..."
49
+ %terminal PROP "."
50
+ %terminal COMMA ","
51
+ %terminal MINUS "-"
52
+ %terminal PLUS "+"
53
+ %terminal NEWLINE "\n"
54
+
55
+ %null.data left LPAREN LBRACK BINOP MINUS PLUS
56
+ %null.data right EQUAL PROP RANGE ERANGE UNOP
57
+
58
+ %%
59
+
60
+ main: expressions.maybe
61
+
62
+ expressions.maybe: expressions
63
+ | nothing
64
+
65
+ expressions: expressions block
66
+ | block
67
+
68
+ block: LBRACE expressions RBRACE
69
+ | expression
70
+
71
+ expression: conditional
72
+ | class
73
+ | module
74
+ | loop
75
+ | action
76
+ | exception
77
+ | directive
78
+ | vexpression
79
+
80
+ vexpression: NUMBER
81
+ | IDENTIFIER
82
+ | ISTRING
83
+ | SSTRING
84
+ | KEYWORD
85
+ | REGEX
86
+ | NEWLINE
87
+ | interpolation
88
+ | PLUS vexpression
89
+ | MINUS vexpression
90
+ | object
91
+ | array
92
+ | function
93
+ | PREUNOP vexpression
94
+ | UNOP vexpression
95
+ | HEREDOC_REF
96
+ | IHEREDOC_REF
97
+ | heredoc
98
+ | vexpression LPAREN vexpression.parameters.maybe RPAREN
99
+ | vexpression EQUAL vexpression
100
+ | vexpression PROP IDENTIFIER
101
+ | vexpression LBRACK vexpression RBRACK
102
+ | vexpression RANGE vexpression
103
+ | vexpression ERANGE vexpression
104
+ | vexpression BINOP vexpression
105
+ | vexpression MINUS vexpression
106
+ | vexpression PLUS vexpression
107
+ | vexpression UNOP
108
+
109
+ vexpression.parameters.maybe: vexpression.parameters
110
+ | nothing
111
+
112
+ vexpression.parameters: vexpression.parameters COMMA vexpression
113
+ | vexpression
114
+
115
+ object: LBRACE RBRACE
116
+ array: LBRACK RBRACK
117
+ function: LPAREN RPAREN ARROW
118
+ heredoc: HEREDOC
119
+ | IHEREDOC
120
+
121
+ interpolation: interpolation.string
122
+ | interpolation.heredoc
123
+
124
+ interpolation.heredoc: IHEREDOC_BEGIN vexpression interpolation.heredoc.finish
125
+ interpolation.heredoc.finish: interpolation.heredoc
126
+ | IHEREDOC
127
+
128
+ interpolation.string: ISTRING_BEGIN vexpression interpolation.string.finish
129
+ interpolation.string.finish: interpolation.string
130
+ | ISTRING
131
+
132
+ conditional: IF LPAREN vexpression RPAREN block conditional.continue
133
+ | UNLESS LPAREN vexpression RPAREN block
134
+
135
+ conditional.continue: ELSIF LPAREN vexpression RPAREN block conditional.continue
136
+ | ELSE block
137
+
138
+ class: CLASS IDENTIFIER RBRACE LBRACE
139
+ module: MODULE IDENTIFIER RBRACE LBRACE
140
+
141
+ loop: WHILE LPAREN vexpression RPAREN block
142
+ | FOR LPAREN IDENTIFIER IN vexpression RPAREN block
143
+ | FOR LPAREN vexpression RPAREN block
144
+
145
+ action: RETURN
146
+ | ACTION
147
+
148
+ exception: TRY block exception.catch.maybe exception.finally.maybe
149
+ exception.catch.maybe: exception.catch
150
+ | nothing
151
+ exception.finally.maybe: exception.finally
152
+ | nothing
153
+ exception.catch: CATCH exception.catch.possible block
154
+ exception.catch.possible: LPAREN IDENTIFIER RPAREN
155
+ | LPAREN RPAREN
156
+ | nothing
157
+
158
+ exception.finally: FINALLY block
159
+
160
+ directive: COLON LBRACK expressions RBRACK
161
+
162
+ %%
@@ -26,20 +26,20 @@ module Antelope
26
26
  # handle lookahead sets.
27
27
  #
28
28
  # @return [Recognizer::State]
29
- attr_accessor :from
29
+ attr_reader :from
30
30
 
31
31
  # The to state that this token is transitioned to. This is the
32
32
  # _destination_. This is used in the constructor in order to
33
33
  # handle lookahead sets.
34
34
  #
35
35
  # @return [Recognizer::State]
36
- attr_accessor :to
36
+ attr_reader :to
37
37
 
38
38
  # The type of the token. This is given by a caret argument to
39
39
  # the grammar. This is primarily used for generators.
40
40
  #
41
41
  # @return [String]
42
- attr_accessor :type
42
+ attr_reader :type
43
43
 
44
44
  attr_accessor :id
45
45
 
@@ -97,6 +97,33 @@ module Antelope
97
97
  false
98
98
  end
99
99
 
100
+ # Sets the from state of the token and invalidates the cache.
101
+ #
102
+ # @param state [Recognizer::State]
103
+ # @return [void]
104
+ def from=(state)
105
+ invalidate_cache!
106
+ @from = state
107
+ end
108
+
109
+ # Sets the to state of the token and invalidates the cache.
110
+ #
111
+ # @param state [Recognizer::State]
112
+ # @return [void]
113
+ def to=(state)
114
+ invalidate_cache!
115
+ @to = state
116
+ end
117
+
118
+ # Sets the type of the token and invalidates the cache.
119
+ #
120
+ # @param type [String]
121
+ # @return [void]
122
+ def type=(type)
123
+ invalidate_cache!
124
+ @type = type
125
+ end
126
+
100
127
  # Gives a string representation of the token. The output is
101
128
  # formatted like so: `<data>["(" [<from_id>][:<to_id>] ")"]`,
102
129
  # where `<data>` is either the value (if it's non-nil) or the
@@ -149,6 +176,12 @@ module Antelope
149
176
  end
150
177
  end
151
178
 
179
+ def ==(other)
180
+ hash == other.hash if other.respond_to?(:hash)
181
+ end
182
+
183
+ alias_method :eql?, :==
184
+
152
185
  # Compares this class and another object, fuzzily. If the other
153
186
  # object is a token, it removes the transitions (to and from)
154
187
  # on both objects and compares them like that. Otherwise, it
@@ -171,6 +204,14 @@ module Antelope
171
204
  self.class.new(name, @type, @id, @value)
172
205
  end
173
206
 
207
+ # Invalidates the cache.
208
+ #
209
+ # @return [void]
210
+ def invalidate_cache!
211
+ @_hash = nil
212
+ @_array = nil
213
+ end
214
+
174
215
  # Generates a hash for this class.
175
216
  #
176
217
  # @note This is not intended for use. It is only defined to be
@@ -178,7 +219,7 @@ module Antelope
178
219
  # @private
179
220
  # @return [Object]
180
221
  def hash
181
- to_a.hash
222
+ @_hash ||= to_a.hash
182
223
  end
183
224
 
184
225
  alias_method :eql?, :==
@@ -190,7 +231,7 @@ module Antelope
190
231
  # @private
191
232
  # @return [Array<(Recognizer::State, Recognizer::State, Class, Symbol, String?)>]
192
233
  def to_a
193
- [to, from, self.class, name, @value]
234
+ @_array ||= [to, from, self.class, name, @value]
194
235
  end
195
236
  end
196
237
  end
@@ -19,7 +19,7 @@ module Antelope
19
19
  # The right-hand side of the rule.
20
20
  #
21
21
  # @return [Array<Ace::Token>]
22
- attr_accessor :right
22
+ attr_reader :right
23
23
 
24
24
  # The current position inside of the rule.
25
25
  #
@@ -160,6 +160,12 @@ module Antelope
160
160
  end
161
161
  end
162
162
 
163
+ def ==(other)
164
+ hash == other.hash if other.respond_to?(:hash)
165
+ end
166
+
167
+ alias_method :eql?, :==
168
+
163
169
  # Fuzzily compares this object to another object. If the
164
170
  # other object is not a rule, it delegates the comparison.
165
171
  # Otherwise, it fuzzily compares the left and right sides.
@@ -192,11 +198,9 @@ module Antelope
192
198
  # @private
193
199
  # @return [Object]
194
200
  def hash
195
- to_a.hash
201
+ @_hash ||= to_a.hash
196
202
  end
197
203
 
198
- alias_method :eql?, :==
199
-
200
204
  # Creates an array representation of this class.
201
205
  #
202
206
  # @note This is not intended for use. It is only defined to
@@ -204,7 +208,7 @@ module Antelope
204
208
  # @private
205
209
  # @return [Array<(Ace::Token::Nonterminal, Array<Ace::Token>, Numeric)>]
206
210
  def to_a
207
- [left, right, position]
211
+ @_array ||= [left, right, position]
208
212
  end
209
213
  end
210
214
  end
@@ -90,13 +90,13 @@ module Antelope
90
90
  when State
91
91
  rule.rules.map(&:clone).each { |r| self << r }
92
92
  when Rule
93
- rules << rule unless rules.include? rule
93
+ rules << rule #unless rules.include? rule
94
94
  when Array, Set
95
95
  rule.each do |part|
96
96
  self << part
97
97
  end
98
98
  else
99
- raise ArgumentError, "Expected #{State} or #{Rule}, " \
99
+ raise ArgumentError, "Expected State or Rule, " \
100
100
  "got #{rule.class}"
101
101
  end
102
102
 
@@ -111,7 +111,7 @@ module Antelope
111
111
  end
112
112
 
113
113
  def compute_gotos(state)
114
- actives = state.rules.map(&:active).select(&:name).to_set
114
+ actives = state.rules.map(&:active).select(&:name)
115
115
 
116
116
  actives.each do |active|
117
117
  next if state.transitions[active.name]
@@ -36,7 +36,8 @@ module Antelope
36
36
  # @param name [String, Symbol] a name to associate the generator
37
37
  # with.
38
38
  def register_generator(generator, *names)
39
- names = [names].flatten raise ArgumentError,
39
+ names = [names].flatten
40
+ raise ArgumentError,
40
41
  "Requires at least one name" unless names.any?
41
42
  raise ArgumentError,
42
43
  "All name values must be a Symbol or string" unless names.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Antelope
4
4
  # The current running version of antelope.
5
- VERSION = "0.1.11".freeze
5
+ VERSION = "0.2.0".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antelope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -118,6 +118,7 @@ files:
118
118
  - examples/deterministic.ace
119
119
  - examples/example.ace
120
120
  - examples/example.output
121
+ - examples/liquidscript.ace
121
122
  - examples/simple.ace
122
123
  - lib/antelope.rb
123
124
  - lib/antelope/ace.rb
@@ -215,3 +216,4 @@ test_files:
215
216
  - spec/spec_helper.rb
216
217
  - spec/support/benchmark_helper.rb
217
218
  - spec/support/grammar_helper.rb
219
+ has_rdoc: