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,127 +1,127 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "set"
|
4
|
-
require "antelope/generation/constructor/nullable"
|
5
|
-
require "antelope/generation/constructor/first"
|
6
|
-
require "antelope/generation/constructor/follow"
|
7
|
-
|
8
|
-
module Antelope
|
9
|
-
module Generation
|
10
|
-
|
11
|
-
# Constructs the lookahead sets for all of the rules in the
|
12
|
-
# grammar.
|
13
|
-
class Constructor
|
14
|
-
|
15
|
-
include Nullable
|
16
|
-
include First
|
17
|
-
include Follow
|
18
|
-
|
19
|
-
# The grammar.
|
20
|
-
#
|
21
|
-
# @return [Grammar::Grammar]
|
22
|
-
attr_reader :grammar
|
23
|
-
|
24
|
-
# The augmented productions generated by the constructor.
|
25
|
-
#
|
26
|
-
# @return [Set<Grammar::Production>]
|
27
|
-
attr_reader :productions
|
28
|
-
|
29
|
-
# Initialize.
|
30
|
-
#
|
31
|
-
# @param grammar [Grammar::Grammar] the grammar.
|
32
|
-
def initialize(grammar)
|
33
|
-
@productions = Set.new
|
34
|
-
@grammar = grammar
|
35
|
-
super()
|
36
|
-
end
|
37
|
-
|
38
|
-
# Performs the construction. First, it goes through every state
|
39
|
-
# and augments the state. It then goes through every rule and
|
40
|
-
# augments it.
|
41
|
-
#
|
42
|
-
# @return [void]
|
43
|
-
# @see #augment_state
|
44
|
-
# @see #augment_rule
|
45
|
-
def call
|
46
|
-
grammar.states.each do |state|
|
47
|
-
augment_state(state)
|
48
|
-
end.each do |state|
|
49
|
-
augment_rules(state)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Augments the given state. On every rule within that state
|
54
|
-
# that has a position of zero, it follows the rule throughout
|
55
|
-
# the DFA until the end; it marks every nonterminal it
|
56
|
-
# encounters with the transitions it took on that nonterminal.
|
57
|
-
#
|
58
|
-
# @param state [Recognizer::State] the state to augment.
|
59
|
-
# @return [void]
|
60
|
-
def augment_state(state)
|
61
|
-
state.rules.select { |x| x.position.zero? }.each do |rule|
|
62
|
-
production = rule.production.clone
|
63
|
-
production.items = []
|
64
|
-
|
65
|
-
current_state = state
|
66
|
-
old_state = state
|
67
|
-
|
68
|
-
production.label.from = state
|
69
|
-
production.label.to = state.transitions[rule.left.name]
|
70
|
-
|
71
|
-
rule.right.each_with_index do |part, pos|
|
72
|
-
transition = current_state.transitions[part.name]
|
73
|
-
new_item = part.dup
|
74
|
-
|
75
|
-
if part.nonterminal?
|
76
|
-
new_item.from = current_state
|
77
|
-
new_item.to = transition
|
78
|
-
end
|
79
|
-
|
80
|
-
production.items << new_item
|
81
|
-
|
82
|
-
old_state = current_state
|
83
|
-
current_state = transition
|
84
|
-
end
|
85
|
-
|
86
|
-
productions << production
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Augments every final rule. For every rule in the current
|
91
|
-
# state that has a position of zero, it follows the rule through
|
92
|
-
# the DFA until the ending state; it then modifies the ending
|
93
|
-
# state's lookahead set to be the FOLLOW set of the nonterminal
|
94
|
-
# it reduces to.
|
95
|
-
#
|
96
|
-
# @param state [Recognizer::State]
|
97
|
-
# @return [void]
|
98
|
-
# @see Follow#follow
|
99
|
-
def augment_rules(state)
|
100
|
-
state.rules.each do |rule|
|
101
|
-
next unless rule.position.zero?
|
102
|
-
current_state = state
|
103
|
-
|
104
|
-
label = rule.left.dup
|
105
|
-
label.from = state
|
106
|
-
label.to = state.transitions[label.name]
|
107
|
-
|
108
|
-
rule.right.each do |part|
|
109
|
-
transition = current_state.transitions[part.name]
|
110
|
-
current_state = transition
|
111
|
-
end
|
112
|
-
|
113
|
-
final = current_state.rule_for(rule)
|
114
|
-
|
115
|
-
final.lookahead = Set.new unless final.lookahead
|
116
|
-
final.lookahead.merge follow(label)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
private
|
121
|
-
|
122
|
-
def incorrect_argument!(arg, *types)
|
123
|
-
raise ArgumentError, "Expected one of #{types.join(', ')}, got #{arg.class}"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "antelope/generation/constructor/nullable"
|
5
|
+
require "antelope/generation/constructor/first"
|
6
|
+
require "antelope/generation/constructor/follow"
|
7
|
+
|
8
|
+
module Antelope
|
9
|
+
module Generation
|
10
|
+
|
11
|
+
# Constructs the lookahead sets for all of the rules in the
|
12
|
+
# grammar.
|
13
|
+
class Constructor
|
14
|
+
|
15
|
+
include Nullable
|
16
|
+
include First
|
17
|
+
include Follow
|
18
|
+
|
19
|
+
# The grammar.
|
20
|
+
#
|
21
|
+
# @return [Grammar::Grammar]
|
22
|
+
attr_reader :grammar
|
23
|
+
|
24
|
+
# The augmented productions generated by the constructor.
|
25
|
+
#
|
26
|
+
# @return [Set<Grammar::Production>]
|
27
|
+
attr_reader :productions
|
28
|
+
|
29
|
+
# Initialize.
|
30
|
+
#
|
31
|
+
# @param grammar [Grammar::Grammar] the grammar.
|
32
|
+
def initialize(grammar)
|
33
|
+
@productions = Set.new
|
34
|
+
@grammar = grammar
|
35
|
+
super()
|
36
|
+
end
|
37
|
+
|
38
|
+
# Performs the construction. First, it goes through every state
|
39
|
+
# and augments the state. It then goes through every rule and
|
40
|
+
# augments it.
|
41
|
+
#
|
42
|
+
# @return [void]
|
43
|
+
# @see #augment_state
|
44
|
+
# @see #augment_rule
|
45
|
+
def call
|
46
|
+
grammar.states.each do |state|
|
47
|
+
augment_state(state)
|
48
|
+
end.each do |state|
|
49
|
+
augment_rules(state)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Augments the given state. On every rule within that state
|
54
|
+
# that has a position of zero, it follows the rule throughout
|
55
|
+
# the DFA until the end; it marks every nonterminal it
|
56
|
+
# encounters with the transitions it took on that nonterminal.
|
57
|
+
#
|
58
|
+
# @param state [Recognizer::State] the state to augment.
|
59
|
+
# @return [void]
|
60
|
+
def augment_state(state)
|
61
|
+
state.rules.select { |x| x.position.zero? }.each do |rule|
|
62
|
+
production = rule.production.clone
|
63
|
+
production.items = []
|
64
|
+
|
65
|
+
current_state = state
|
66
|
+
old_state = state
|
67
|
+
|
68
|
+
production.label.from = state
|
69
|
+
production.label.to = state.transitions[rule.left.name]
|
70
|
+
|
71
|
+
rule.right.each_with_index do |part, pos|
|
72
|
+
transition = current_state.transitions[part.name]
|
73
|
+
new_item = part.dup
|
74
|
+
|
75
|
+
if part.nonterminal?
|
76
|
+
new_item.from = current_state
|
77
|
+
new_item.to = transition
|
78
|
+
end
|
79
|
+
|
80
|
+
production.items << new_item
|
81
|
+
|
82
|
+
old_state = current_state
|
83
|
+
current_state = transition
|
84
|
+
end
|
85
|
+
|
86
|
+
productions << production
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Augments every final rule. For every rule in the current
|
91
|
+
# state that has a position of zero, it follows the rule through
|
92
|
+
# the DFA until the ending state; it then modifies the ending
|
93
|
+
# state's lookahead set to be the FOLLOW set of the nonterminal
|
94
|
+
# it reduces to.
|
95
|
+
#
|
96
|
+
# @param state [Recognizer::State]
|
97
|
+
# @return [void]
|
98
|
+
# @see Follow#follow
|
99
|
+
def augment_rules(state)
|
100
|
+
state.rules.each do |rule|
|
101
|
+
next unless rule.position.zero?
|
102
|
+
current_state = state
|
103
|
+
|
104
|
+
label = rule.left.dup
|
105
|
+
label.from = state
|
106
|
+
label.to = state.transitions[label.name]
|
107
|
+
|
108
|
+
rule.right.each do |part|
|
109
|
+
transition = current_state.transitions[part.name]
|
110
|
+
current_state = transition
|
111
|
+
end
|
112
|
+
|
113
|
+
final = current_state.rule_for(rule)
|
114
|
+
|
115
|
+
final.lookahead = Set.new unless final.lookahead
|
116
|
+
final.lookahead.merge follow(label)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def incorrect_argument!(arg, *types)
|
123
|
+
raise ArgumentError, "Expected one of #{types.join(', ')}, got #{arg.class}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Antelope
|
4
|
-
module Generation
|
5
|
-
|
6
|
-
# Defines an error that can occur within the Generation module.
|
7
|
-
# All errors that are raised within the Generation module are
|
8
|
-
# subclasses of this.
|
9
|
-
class Error < Antelope::Error
|
10
|
-
end
|
11
|
-
|
12
|
-
# Used mainly in the {Tableizer}, this is raised when a conflict
|
13
|
-
# could not be resolved.
|
14
|
-
class UnresolvableConflictError < Error
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Antelope
|
4
|
+
module Generation
|
5
|
+
|
6
|
+
# Defines an error that can occur within the Generation module.
|
7
|
+
# All errors that are raised within the Generation module are
|
8
|
+
# subclasses of this.
|
9
|
+
class Error < Antelope::Error
|
10
|
+
end
|
11
|
+
|
12
|
+
# Used mainly in the {Tableizer}, this is raised when a conflict
|
13
|
+
# could not be resolved.
|
14
|
+
class UnresolvableConflictError < Error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module Antelope
|
2
|
-
module Generation
|
3
|
-
class Null
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(*)
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(*)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module Antelope
|
2
|
+
module Generation
|
3
|
+
class Null
|
4
|
+
|
5
|
+
|
6
|
+
def initialize(*)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(*)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|