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
data/lib/antelope/ace/scanner.rb
CHANGED
@@ -1,144 +1,144 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "strscan"
|
4
|
-
require "antelope/ace/scanner/argument"
|
5
|
-
require "antelope/ace/scanner/first"
|
6
|
-
require "antelope/ace/scanner/second"
|
7
|
-
require "antelope/ace/scanner/third"
|
8
|
-
|
9
|
-
module Antelope
|
10
|
-
module Ace
|
11
|
-
|
12
|
-
# Scans a given input. The input should be a properly formatted
|
13
|
-
# ACE file; see the Ace module for more information. This scanner
|
14
|
-
# uses the StringScanner class internally; see the ruby
|
15
|
-
# documentation for more on that. This scanner seperates scanning
|
16
|
-
# into three seperate stages: First, Second, and Third, for each
|
17
|
-
# section of the file, respectively.
|
18
|
-
#
|
19
|
-
# @see Ace
|
20
|
-
# @see http://ruby-doc.org/stdlib-2.1.2/libdoc/strscan/rdoc/StringScanner.html
|
21
|
-
class Scanner
|
22
|
-
|
23
|
-
IDENTIFIER = "[a-zA-Z_.][a-zA-Z0-9_.-]*"
|
24
|
-
|
25
|
-
include First
|
26
|
-
include Second
|
27
|
-
include Third
|
28
|
-
|
29
|
-
# The string scanner that we're using to scan the string with.
|
30
|
-
#
|
31
|
-
# @return [StringScanner]
|
32
|
-
attr_reader :scanner
|
33
|
-
|
34
|
-
# An array of the tokens that the scanner scanned.
|
35
|
-
#
|
36
|
-
# @return [Array<Array<(Symbol, Object, ...)>>]
|
37
|
-
attr_reader :tokens
|
38
|
-
|
39
|
-
# The boundry between each section. Placed here to be easily.
|
40
|
-
# modifiable. **MUST** be a regular expression.
|
41
|
-
#
|
42
|
-
# @return [RegExp]
|
43
|
-
CONTENT_BOUNDRY = /%%/
|
44
|
-
|
45
|
-
# The value regular expression. It should match values; for
|
46
|
-
# example, things quoted in strings or word letters without
|
47
|
-
# quotes. Must respond to #to_s, since it is embedded within
|
48
|
-
# other regular expressions. The regular expression should
|
49
|
-
# place the contents of the value in the groups 2 or 3.
|
50
|
-
#
|
51
|
-
# @return [#to_s]
|
52
|
-
VALUE = %q{(?:
|
53
|
-
(?:("|')((?:\\\\|\\"|\\'|.)+?)\\1)
|
54
|
-
| ([A-Za-z0-9_.<>*-]+)
|
55
|
-
)}
|
56
|
-
|
57
|
-
# Scans a file. It returns the tokens resulting from scanning.
|
58
|
-
#
|
59
|
-
# @param source [String] the source to scan. This should be
|
60
|
-
# compatible with StringScanner.
|
61
|
-
# @param name [String] the name of the source file. This is
|
62
|
-
# primarilyused in backtrace information.
|
63
|
-
# @return [Array<Array<(Symbol, Object, ...)>>]
|
64
|
-
# @see #tokens
|
65
|
-
def self.scan(source, name = "(ace file)")
|
66
|
-
new(source, name).scan_file
|
67
|
-
end
|
68
|
-
|
69
|
-
# Initialize the scanner with the input.
|
70
|
-
#
|
71
|
-
# @param input [String] The source to scan.
|
72
|
-
# @param source [String] the source file. This is primarily
|
73
|
-
# used in backtrace information.
|
74
|
-
def initialize(input, source = "(ace file)")
|
75
|
-
@source = source
|
76
|
-
@scanner = StringScanner.new(input)
|
77
|
-
@tokens = []
|
78
|
-
end
|
79
|
-
|
80
|
-
# Scans the file in parts.
|
81
|
-
#
|
82
|
-
# @raise [SyntaxError] if the source is malformed in some way.
|
83
|
-
# @return [Array<Array<(Symbol, Object, ...)>>] the tokens that
|
84
|
-
# were scanned in this file.
|
85
|
-
# @see #scan_first_part
|
86
|
-
# @see #scan_second_part
|
87
|
-
# @see #scan_third_part
|
88
|
-
# @see #tokens
|
89
|
-
def scan_file
|
90
|
-
@line = 1
|
91
|
-
scan_first_part
|
92
|
-
scan_second_part
|
93
|
-
scan_third_part
|
94
|
-
tokens
|
95
|
-
rescue SyntaxError => e
|
96
|
-
start = [@scanner.pos - 8, 0].max
|
97
|
-
stop = [@scanner.pos + 8, @scanner.string.length].min
|
98
|
-
snip = @scanner.string[start..stop].strip.inspect
|
99
|
-
char = @scanner.string[@scanner.pos]
|
100
|
-
char = if char
|
101
|
-
char.inspect
|
102
|
-
else
|
103
|
-
"EOF"
|
104
|
-
end
|
105
|
-
|
106
|
-
new_line = "#{@source}:#{@line}: unexpected #{char} " \
|
107
|
-
"(near #{snip})"
|
108
|
-
|
109
|
-
raise e, e.message, [new_line, *e.backtrace]
|
110
|
-
end
|
111
|
-
|
112
|
-
# Scans for whitespace. If the next character is whitespace, it
|
113
|
-
# will consume all whitespace until the next non-whitespace
|
114
|
-
# character.
|
115
|
-
#
|
116
|
-
# @return [Boolean] if any whitespace was matched.
|
117
|
-
def scan_whitespace
|
118
|
-
if @scanner.scan(/(\s+)/)
|
119
|
-
@line += @scanner[1].count("\n")
|
120
|
-
end
|
121
|
-
end
|
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
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
# Raises an error.
|
136
|
-
#
|
137
|
-
# @raise [SyntaxError] always.
|
138
|
-
# @return [void]
|
139
|
-
def error!
|
140
|
-
raise SyntaxError, "invalid syntax"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "strscan"
|
4
|
+
require "antelope/ace/scanner/argument"
|
5
|
+
require "antelope/ace/scanner/first"
|
6
|
+
require "antelope/ace/scanner/second"
|
7
|
+
require "antelope/ace/scanner/third"
|
8
|
+
|
9
|
+
module Antelope
|
10
|
+
module Ace
|
11
|
+
|
12
|
+
# Scans a given input. The input should be a properly formatted
|
13
|
+
# ACE file; see the Ace module for more information. This scanner
|
14
|
+
# uses the StringScanner class internally; see the ruby
|
15
|
+
# documentation for more on that. This scanner seperates scanning
|
16
|
+
# into three seperate stages: First, Second, and Third, for each
|
17
|
+
# section of the file, respectively.
|
18
|
+
#
|
19
|
+
# @see Ace
|
20
|
+
# @see http://ruby-doc.org/stdlib-2.1.2/libdoc/strscan/rdoc/StringScanner.html
|
21
|
+
class Scanner
|
22
|
+
|
23
|
+
IDENTIFIER = "[a-zA-Z_.][a-zA-Z0-9_.-]*"
|
24
|
+
|
25
|
+
include First
|
26
|
+
include Second
|
27
|
+
include Third
|
28
|
+
|
29
|
+
# The string scanner that we're using to scan the string with.
|
30
|
+
#
|
31
|
+
# @return [StringScanner]
|
32
|
+
attr_reader :scanner
|
33
|
+
|
34
|
+
# An array of the tokens that the scanner scanned.
|
35
|
+
#
|
36
|
+
# @return [Array<Array<(Symbol, Object, ...)>>]
|
37
|
+
attr_reader :tokens
|
38
|
+
|
39
|
+
# The boundry between each section. Placed here to be easily.
|
40
|
+
# modifiable. **MUST** be a regular expression.
|
41
|
+
#
|
42
|
+
# @return [RegExp]
|
43
|
+
CONTENT_BOUNDRY = /%%/
|
44
|
+
|
45
|
+
# The value regular expression. It should match values; for
|
46
|
+
# example, things quoted in strings or word letters without
|
47
|
+
# quotes. Must respond to #to_s, since it is embedded within
|
48
|
+
# other regular expressions. The regular expression should
|
49
|
+
# place the contents of the value in the groups 2 or 3.
|
50
|
+
#
|
51
|
+
# @return [#to_s]
|
52
|
+
VALUE = %q{(?:
|
53
|
+
(?:("|')((?:\\\\|\\"|\\'|.)+?)\\1)
|
54
|
+
| ([A-Za-z0-9_.<>*-]+)
|
55
|
+
)}
|
56
|
+
|
57
|
+
# Scans a file. It returns the tokens resulting from scanning.
|
58
|
+
#
|
59
|
+
# @param source [String] the source to scan. This should be
|
60
|
+
# compatible with StringScanner.
|
61
|
+
# @param name [String] the name of the source file. This is
|
62
|
+
# primarilyused in backtrace information.
|
63
|
+
# @return [Array<Array<(Symbol, Object, ...)>>]
|
64
|
+
# @see #tokens
|
65
|
+
def self.scan(source, name = "(ace file)")
|
66
|
+
new(source, name).scan_file
|
67
|
+
end
|
68
|
+
|
69
|
+
# Initialize the scanner with the input.
|
70
|
+
#
|
71
|
+
# @param input [String] The source to scan.
|
72
|
+
# @param source [String] the source file. This is primarily
|
73
|
+
# used in backtrace information.
|
74
|
+
def initialize(input, source = "(ace file)")
|
75
|
+
@source = source
|
76
|
+
@scanner = StringScanner.new(input)
|
77
|
+
@tokens = []
|
78
|
+
end
|
79
|
+
|
80
|
+
# Scans the file in parts.
|
81
|
+
#
|
82
|
+
# @raise [SyntaxError] if the source is malformed in some way.
|
83
|
+
# @return [Array<Array<(Symbol, Object, ...)>>] the tokens that
|
84
|
+
# were scanned in this file.
|
85
|
+
# @see #scan_first_part
|
86
|
+
# @see #scan_second_part
|
87
|
+
# @see #scan_third_part
|
88
|
+
# @see #tokens
|
89
|
+
def scan_file
|
90
|
+
@line = 1
|
91
|
+
scan_first_part
|
92
|
+
scan_second_part
|
93
|
+
scan_third_part
|
94
|
+
tokens
|
95
|
+
rescue SyntaxError => e
|
96
|
+
start = [@scanner.pos - 8, 0].max
|
97
|
+
stop = [@scanner.pos + 8, @scanner.string.length].min
|
98
|
+
snip = @scanner.string[start..stop].strip.inspect
|
99
|
+
char = @scanner.string[@scanner.pos]
|
100
|
+
char = if char
|
101
|
+
char.inspect
|
102
|
+
else
|
103
|
+
"EOF"
|
104
|
+
end
|
105
|
+
|
106
|
+
new_line = "#{@source}:#{@line}: unexpected #{char} " \
|
107
|
+
"(near #{snip})"
|
108
|
+
|
109
|
+
raise e, e.message, [new_line, *e.backtrace]
|
110
|
+
end
|
111
|
+
|
112
|
+
# Scans for whitespace. If the next character is whitespace, it
|
113
|
+
# will consume all whitespace until the next non-whitespace
|
114
|
+
# character.
|
115
|
+
#
|
116
|
+
# @return [Boolean] if any whitespace was matched.
|
117
|
+
def scan_whitespace
|
118
|
+
if @scanner.scan(/(\s+)/)
|
119
|
+
@line += @scanner[1].count("\n")
|
120
|
+
end
|
121
|
+
end
|
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
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Raises an error.
|
136
|
+
#
|
137
|
+
# @raise [SyntaxError] always.
|
138
|
+
# @return [void]
|
139
|
+
def error!
|
140
|
+
raise SyntaxError, "invalid syntax"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/lib/antelope/ace.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'antelope/ace/errors'
|
4
|
-
require 'antelope/ace/scanner'
|
5
|
-
require 'antelope/ace/compiler'
|
6
|
-
|
7
|
-
module Antelope
|
8
|
-
# Defines the Ace file. The Ace file format works similarly to
|
9
|
-
# bison's y file format. The Ace file is seperated into three
|
10
|
-
# parts:
|
11
|
-
#
|
12
|
-
# <first>
|
13
|
-
# %%
|
14
|
-
# <second>
|
15
|
-
# %%
|
16
|
-
# <third>
|
17
|
-
#
|
18
|
-
# All parts may be empty; thus, the minimal file that Ace will
|
19
|
-
# accept would be
|
20
|
-
#
|
21
|
-
# %%
|
22
|
-
# %%
|
23
|
-
#
|
24
|
-
# The first part consists of _directives_ and _blocks_; directives
|
25
|
-
# look something like `'%' <directive>[ <argument>]*\n`, with
|
26
|
-
# `<directive>` being any alphanumerical character, including
|
27
|
-
# underscores and dashes, and `<argument>` being any word character
|
28
|
-
# or a quote-delimited string. Blocks consist of
|
29
|
-
# `'%{" <content> "\n" "\s"* "%}'`, with `<content>` being any
|
30
|
-
# characters. The content is copied directly into the body of the
|
31
|
-
# output.
|
32
|
-
#
|
33
|
-
# The second part consists of rules. Rules look something like
|
34
|
-
# this:
|
35
|
-
#
|
36
|
-
# <nonterminal>: (<nonterminal> | <terminal>)* ['{" <content> "}"] ["|" (<nonterminal> | <terminal>)* ["{" <content> "}']]* [;]
|
37
|
-
#
|
38
|
-
# Where `<nonterminal>` is any lowercase alphabetical cahracter,
|
39
|
-
# `<terminal>` is any uppercase alphabetical character, and
|
40
|
-
# `<content>` is code to be used in the output file upon matching
|
41
|
-
# the specific rule.
|
42
|
-
#
|
43
|
-
# The third part consists of a body, which is copied directly into
|
44
|
-
# the output.
|
45
|
-
module Ace
|
46
|
-
end
|
47
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'antelope/ace/errors'
|
4
|
+
require 'antelope/ace/scanner'
|
5
|
+
require 'antelope/ace/compiler'
|
6
|
+
|
7
|
+
module Antelope
|
8
|
+
# Defines the Ace file. The Ace file format works similarly to
|
9
|
+
# bison's y file format. The Ace file is seperated into three
|
10
|
+
# parts:
|
11
|
+
#
|
12
|
+
# <first>
|
13
|
+
# %%
|
14
|
+
# <second>
|
15
|
+
# %%
|
16
|
+
# <third>
|
17
|
+
#
|
18
|
+
# All parts may be empty; thus, the minimal file that Ace will
|
19
|
+
# accept would be
|
20
|
+
#
|
21
|
+
# %%
|
22
|
+
# %%
|
23
|
+
#
|
24
|
+
# The first part consists of _directives_ and _blocks_; directives
|
25
|
+
# look something like `'%' <directive>[ <argument>]*\n`, with
|
26
|
+
# `<directive>` being any alphanumerical character, including
|
27
|
+
# underscores and dashes, and `<argument>` being any word character
|
28
|
+
# or a quote-delimited string. Blocks consist of
|
29
|
+
# `'%{" <content> "\n" "\s"* "%}'`, with `<content>` being any
|
30
|
+
# characters. The content is copied directly into the body of the
|
31
|
+
# output.
|
32
|
+
#
|
33
|
+
# The second part consists of rules. Rules look something like
|
34
|
+
# this:
|
35
|
+
#
|
36
|
+
# <nonterminal>: (<nonterminal> | <terminal>)* ['{" <content> "}"] ["|" (<nonterminal> | <terminal>)* ["{" <content> "}']]* [;]
|
37
|
+
#
|
38
|
+
# Where `<nonterminal>` is any lowercase alphabetical cahracter,
|
39
|
+
# `<terminal>` is any uppercase alphabetical character, and
|
40
|
+
# `<content>` is code to be used in the output file upon matching
|
41
|
+
# the specific rule.
|
42
|
+
#
|
43
|
+
# The third part consists of a body, which is copied directly into
|
44
|
+
# the output.
|
45
|
+
module Ace
|
46
|
+
end
|
47
|
+
end
|
data/lib/antelope/cli.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "thor"
|
4
|
-
|
5
|
-
module Antelope
|
6
|
-
|
7
|
-
# Handles the command line interface.
|
8
|
-
class CLI < Thor
|
9
|
-
|
10
|
-
class_option :verbose, default: false, type: :boolean
|
11
|
-
|
12
|
-
option :type, default: nil, type: :string,
|
13
|
-
desc: "The type of generator to use"
|
14
|
-
desc "compile FILE [FILE]*", "compile the given files"
|
15
|
-
|
16
|
-
# Compile.
|
17
|
-
def compile(*files)
|
18
|
-
files.each do |file|
|
19
|
-
compile_file(file)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "check FILE [FILE]*", "check the syntax of the given files"
|
24
|
-
|
25
|
-
# Check.
|
26
|
-
def check(*files)
|
27
|
-
files.each do |file|
|
28
|
-
compile_file(file, [Generator::Null])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "version", "Displays the running version of antelope"
|
33
|
-
def version
|
34
|
-
puts "Antelope version #{Antelope::VERSION}"
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
# Compiles the given file, and then generates. If an error
|
40
|
-
# occurs, it prints it out to stderr, along with a backtrace if
|
41
|
-
# the verbose flag was set.
|
42
|
-
#
|
43
|
-
# @param file [String] the file to compile.
|
44
|
-
# @param gen [Array, Symbol] the generator to use.
|
45
|
-
# @return [void]
|
46
|
-
def compile_file(file, gen = :guess)
|
47
|
-
puts "Compiling #{file}... "
|
48
|
-
|
49
|
-
grammar = Grammar.from_file(file)
|
50
|
-
grammar.generate(options, gen)
|
51
|
-
|
52
|
-
rescue => e
|
53
|
-
$stderr.puts "Error while compiling: #{e.class}: #{e.message}"
|
54
|
-
|
55
|
-
if options[:verbose]
|
56
|
-
$stderr.puts e.backtrace[0..10].map { |_| "\t#{_}" }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
module Antelope
|
6
|
+
|
7
|
+
# Handles the command line interface.
|
8
|
+
class CLI < Thor
|
9
|
+
|
10
|
+
class_option :verbose, default: false, type: :boolean
|
11
|
+
|
12
|
+
option :type, default: nil, type: :string,
|
13
|
+
desc: "The type of generator to use"
|
14
|
+
desc "compile FILE [FILE]*", "compile the given files"
|
15
|
+
|
16
|
+
# Compile.
|
17
|
+
def compile(*files)
|
18
|
+
files.each do |file|
|
19
|
+
compile_file(file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "check FILE [FILE]*", "check the syntax of the given files"
|
24
|
+
|
25
|
+
# Check.
|
26
|
+
def check(*files)
|
27
|
+
files.each do |file|
|
28
|
+
compile_file(file, [Generator::Null])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "version", "Displays the running version of antelope"
|
33
|
+
def version
|
34
|
+
puts "Antelope version #{Antelope::VERSION}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Compiles the given file, and then generates. If an error
|
40
|
+
# occurs, it prints it out to stderr, along with a backtrace if
|
41
|
+
# the verbose flag was set.
|
42
|
+
#
|
43
|
+
# @param file [String] the file to compile.
|
44
|
+
# @param gen [Array, Symbol] the generator to use.
|
45
|
+
# @return [void]
|
46
|
+
def compile_file(file, gen = :guess)
|
47
|
+
puts "Compiling #{file}... "
|
48
|
+
|
49
|
+
grammar = Grammar.from_file(file)
|
50
|
+
grammar.generate(options, gen)
|
51
|
+
|
52
|
+
rescue => e
|
53
|
+
$stderr.puts "Error while compiling: #{e.class}: #{e.message}"
|
54
|
+
|
55
|
+
if options[:verbose]
|
56
|
+
$stderr.puts e.backtrace[0..10].map { |_| "\t#{_}" }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/antelope/errors.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Antelope
|
4
|
-
# Every error in antelope inherits this error class.
|
5
|
-
class Error < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
# This is used primarily in the {Grammar}; if a rule references a
|
9
|
-
# token (a nonterminal or a terminal) that was not previously
|
10
|
-
# defined, this is raised.
|
11
|
-
class UndefinedTokenError < Error
|
12
|
-
end
|
13
|
-
|
14
|
-
# Used primarily in the {Compiler}, this is raised when the
|
15
|
-
# version requirement of the Ace file doesn't match the running
|
16
|
-
# version of Ace.
|
17
|
-
class IncompatibleVersionError < Error
|
18
|
-
end
|
19
|
-
|
20
|
-
# Primarily used in the {Grammar} (specifically
|
21
|
-
# {Grammar::Generation}), if the grammar could not determine the
|
22
|
-
# generator to use for the generation, it raises this.
|
23
|
-
class NoTypeError < Error
|
24
|
-
end
|
25
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Antelope
|
4
|
+
# Every error in antelope inherits this error class.
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
# This is used primarily in the {Grammar}; if a rule references a
|
9
|
+
# token (a nonterminal or a terminal) that was not previously
|
10
|
+
# defined, this is raised.
|
11
|
+
class UndefinedTokenError < Error
|
12
|
+
end
|
13
|
+
|
14
|
+
# Used primarily in the {Compiler}, this is raised when the
|
15
|
+
# version requirement of the Ace file doesn't match the running
|
16
|
+
# version of Ace.
|
17
|
+
class IncompatibleVersionError < Error
|
18
|
+
end
|
19
|
+
|
20
|
+
# Primarily used in the {Grammar} (specifically
|
21
|
+
# {Grammar::Generation}), if the grammar could not determine the
|
22
|
+
# generator to use for the generation, it raises this.
|
23
|
+
class NoTypeError < Error
|
24
|
+
end
|
25
|
+
end
|