antelope 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/antelope +1 -1
- data/lib/antelope/ace/grammar/productions.rb +1 -1
- data/lib/antelope/ace/scanner/first.rb +1 -1
- data/lib/antelope/ace/scanner/second.rb +3 -2
- data/lib/antelope/ace/scanner.rb +10 -0
- data/lib/antelope/ace/token.rb +0 -4
- data/lib/antelope/cli.rb +5 -0
- data/lib/antelope/generation/constructor/follow.rb +12 -10
- data/lib/antelope/generation/constructor.rb +2 -1
- data/lib/antelope/generation/tableizer.rb +4 -3
- data/lib/antelope/generator/templates/error.ant +10 -9
- data/lib/antelope/generator/templates/info.ant +5 -5
- data/lib/antelope/template.rb +0 -1
- data/lib/antelope/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60074794e65864ae5447727e4984cde3a504f0a2
|
4
|
+
data.tar.gz: 30f5789883e6d9ed457f39cfbe9bb2e403e73e94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0f05690c5a8cf167e2eac1dade2394b5d0e74c23b457c5aed225ad8416c9fd5aec77bb3ec60e9b6ac6c1d9bfcf62604accff5f1ed8d94f06b5cc746d10ca14
|
7
|
+
data.tar.gz: 8773be8140d656cbada7cd82dcf601577a3bbc0ec335d9bb07a0200ca2cafc538b19609c2c83ca98ae1b51e8945b04cb49616f9dc1a9f09fb409c224088fa852
|
data/bin/antelope
CHANGED
@@ -99,7 +99,7 @@ module Antelope
|
|
99
99
|
left = Token::Nonterminal.new(rule[:label])
|
100
100
|
items = rule[:set].map { |_| find_token(_[0]) }
|
101
101
|
prec = if rule[:prec].empty?
|
102
|
-
items.select(&:terminal?).
|
102
|
+
items.select(&:terminal?).first
|
103
103
|
else
|
104
104
|
rule[:prec].intern
|
105
105
|
end
|
@@ -32,7 +32,8 @@ module Antelope
|
|
32
32
|
tokens << [:second]
|
33
33
|
|
34
34
|
until @scanner.check(CONTENT_BOUNDRY)
|
35
|
-
scan_second_rule || scan_whitespace ||
|
35
|
+
scan_second_rule || scan_whitespace || scan_comment ||
|
36
|
+
error!
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -77,7 +78,7 @@ module Antelope
|
|
77
78
|
while body
|
78
79
|
scan_second_rule_prec || scan_second_rule_part ||
|
79
80
|
scan_second_rule_or || scan_second_rule_block ||
|
80
|
-
scan_whitespace || (body = false)
|
81
|
+
scan_whitespace || scan_comment || (body = false)
|
81
82
|
end
|
82
83
|
@scanner.scan(/;/)
|
83
84
|
end
|
data/lib/antelope/ace/scanner.rb
CHANGED
@@ -120,6 +120,16 @@ module Antelope
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
# Scans for a comment. If the next token is a number sign (#),
|
124
|
+
# it will consume all characters until the next newline.
|
125
|
+
#
|
126
|
+
# @return [Boolean] if a comment was matched.
|
127
|
+
def scan_comment
|
128
|
+
if @scanner.scan(/\#(.*)\n/)
|
129
|
+
@line += 1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
123
133
|
private
|
124
134
|
|
125
135
|
# Raises an error.
|
data/lib/antelope/ace/token.rb
CHANGED
data/lib/antelope/cli.rb
CHANGED
@@ -68,29 +68,31 @@ module Antelope
|
|
68
68
|
# @see Nullable#nullable?
|
69
69
|
def generate_follow_set(token)
|
70
70
|
# Set it to the empty set so we don't end up recursing.
|
71
|
-
|
71
|
+
@follows[token] = Set.new
|
72
|
+
set = Set.new
|
72
73
|
|
73
74
|
productions.each do |rule|
|
74
75
|
items = rule.items
|
76
|
+
i = 0
|
75
77
|
|
76
78
|
# Find all of the positions within the rule that our token
|
77
79
|
# occurs, and then increment that position by one.
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
while i < items.size
|
81
|
+
next i += 1 unless items[i] == token
|
82
|
+
position = i.succ
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
inject(set, :merge)
|
84
|
+
# Find the FIRST set of every item after our token, and
|
85
|
+
# put that in our set.
|
86
|
+
set.merge first(items[position..-1])
|
86
87
|
|
87
|
-
positions.each do |pos|
|
88
88
|
# If we're at the end of the rule...
|
89
|
-
if
|
89
|
+
if position == items.size || nullable?(items[position..-1])
|
90
90
|
# Then add the FOLLOW set of the left-hand side to our
|
91
91
|
# set.
|
92
92
|
set.merge follow(rule.label)
|
93
93
|
end
|
94
|
+
|
95
|
+
i += 1
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -97,7 +97,8 @@ module Antelope
|
|
97
97
|
# @return [void]
|
98
98
|
# @see Follow#follow
|
99
99
|
def augment_rules(state)
|
100
|
-
state.rules.
|
100
|
+
state.rules.each do |rule|
|
101
|
+
next unless rule.position.zero?
|
101
102
|
current_state = state
|
102
103
|
|
103
104
|
label = rule.left.dup
|
@@ -95,7 +95,10 @@ module Antelope
|
|
95
95
|
next
|
96
96
|
end
|
97
97
|
|
98
|
-
terminal =
|
98
|
+
terminal = if states[state].transitions.key?(on)
|
99
|
+
states[state].rules.
|
100
|
+
detect { |rule| rule.active.name == on }.precedence
|
101
|
+
end
|
99
102
|
rule_part, other_part = data.sort_by { |(t, _)| t }
|
100
103
|
|
101
104
|
conflict = proc do |result|
|
@@ -118,8 +121,6 @@ module Antelope
|
|
118
121
|
detect { |rule| rule.active.name == on }
|
119
122
|
})
|
120
123
|
|
121
|
-
#conflicts[state][on] = [result, rule_part, other_part,
|
122
|
-
# terminal, @rules[rule_part[1]].prec]
|
123
124
|
conflicts[state][on] = hash
|
124
125
|
end
|
125
126
|
|
@@ -1,17 +1,16 @@
|
|
1
1
|
Productions:
|
2
2
|
%len = grammar.all_productions.size.to_s.size
|
3
|
-
%productions =
|
4
|
-
% map { |x| [
|
5
|
-
%body = productions.map { |_| _.
|
6
|
-
%productions.
|
7
|
-
{{= sprintf("
|
3
|
+
%productions = recognizer.states.map(&:rules).inject(:merge).
|
4
|
+
% select(&:final?).map { |x| [x.to_s(false), x.production.block] }
|
5
|
+
%body = productions.map { |_| _[0].size }.max
|
6
|
+
%productions.each do |prod|
|
7
|
+
{{= sprintf("%-#{body}s", prod[0]) }} %{prod[1]}
|
8
8
|
%end
|
9
9
|
|
10
|
-
%if table.any? { |_, i| tableizer.conflicts[i].
|
11
|
-
|
12
|
-
%else
|
10
|
+
% if table.each_with_index.any? { |_, i| tableizer.conflicts[i].each.
|
11
|
+
% select { |(_, v)| v[:result] == 0 || directives.output.verbose }.any? }
|
13
12
|
Error:
|
14
|
-
% table.each_with_index do |
|
13
|
+
% table.each_with_index do |_, i|
|
15
14
|
% conflicts = tableizer.conflicts[i].each.
|
16
15
|
% select { |(_, v)| v[:result] == 0 || directives.output.verbose }
|
17
16
|
% next unless conflicts.any?
|
@@ -30,4 +29,6 @@ Error:
|
|
30
29
|
% end
|
31
30
|
% end
|
32
31
|
% end
|
32
|
+
%else
|
33
|
+
No errors :)
|
33
34
|
%end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Productions:
|
2
2
|
%len = grammar.all_productions.size.to_s.size
|
3
|
-
%productions =
|
4
|
-
% map { |x| [
|
5
|
-
%body = productions.map { |_| _.
|
6
|
-
%productions.
|
7
|
-
{{= sprintf("
|
3
|
+
%productions = recognizer.states.map(&:rules).inject(:merge).
|
4
|
+
% select(&:final?).map { |x| [x.to_s(false), x.production.block] }
|
5
|
+
%body = productions.map { |_| _[0].size }.max
|
6
|
+
%productions.each do |prod|
|
7
|
+
{{= sprintf("%-#{body}s", prod[0]) }} %{prod[1]}
|
8
8
|
%end
|
9
9
|
|
10
10
|
%if unused_symbols.any?
|
data/lib/antelope/template.rb
CHANGED
data/lib/antelope/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|