antelope 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +25 -23
- data/.rspec +3 -3
- data/.travis.yml +10 -9
- data/.yardopts +7 -7
- data/CONTRIBUTING.md +38 -38
- data/GENERATORS.md +124 -124
- data/Gemfile +7 -7
- data/LICENSE.txt +22 -22
- data/README.md +104 -104
- data/Rakefile +2 -2
- data/TODO.md +58 -58
- data/antelope.gemspec +28 -28
- data/bin/antelope +7 -7
- data/examples/deterministic.ace +35 -35
- data/examples/example.ace +51 -50
- data/examples/example.err +192 -0
- data/examples/{example.output → example.inf} +384 -385
- data/examples/liquidscript.ace +233 -162
- data/examples/simple.ace +22 -22
- data/lib/antelope/ace/compiler.rb +334 -334
- data/lib/antelope/ace/errors.rb +48 -48
- data/lib/antelope/ace/grammar/generation.rb +80 -80
- data/lib/antelope/ace/grammar/loading.rb +53 -53
- data/lib/antelope/ace/grammar/precedences.rb +68 -65
- data/lib/antelope/ace/grammar/productions.rb +156 -150
- data/lib/antelope/ace/grammar/symbols.rb +66 -66
- data/lib/antelope/ace/grammar.rb +69 -69
- data/lib/antelope/ace/precedence.rb +61 -61
- data/lib/antelope/ace/production.rb +57 -57
- 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 +177 -177
- data/lib/antelope/ace/scanner/third.rb +27 -27
- data/lib/antelope/ace/scanner.rb +134 -134
- data/lib/antelope/ace/token/epsilon.rb +24 -24
- data/lib/antelope/ace/token/error.rb +26 -26
- data/lib/antelope/ace/token/nonterminal.rb +17 -17
- data/lib/antelope/ace/token/terminal.rb +17 -17
- data/lib/antelope/ace/token.rb +238 -238
- data/lib/antelope/ace.rb +53 -53
- data/lib/antelope/cli.rb +55 -55
- data/lib/antelope/errors.rb +8 -8
- data/lib/antelope/generation/constructor/first.rb +88 -88
- data/lib/antelope/generation/constructor/follow.rb +103 -103
- data/lib/antelope/generation/constructor/nullable.rb +64 -64
- data/lib/antelope/generation/constructor.rb +126 -126
- 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 +130 -130
- data/lib/antelope/generation/recognizer.rb +180 -180
- data/lib/antelope/generation/tableizer.rb +175 -154
- data/lib/antelope/generation.rb +15 -15
- data/lib/antelope/generator/base.rb +264 -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 -0
- data/lib/antelope/generator/group.rb +57 -57
- data/lib/antelope/generator/html.rb +51 -0
- data/lib/antelope/generator/info.rb +47 -0
- data/lib/antelope/generator/null.rb +18 -18
- data/lib/antelope/generator/output.rb +17 -49
- data/lib/antelope/generator/ruby.rb +79 -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.ant +33 -0
- data/lib/antelope/generator/templates/html/antelope.css +1 -0
- data/lib/antelope/generator/templates/html/antelope.html +1 -0
- data/lib/antelope/generator/templates/html/antelope.js +1 -0
- data/lib/antelope/generator/templates/html/css.ant +53 -0
- data/lib/antelope/generator/templates/html/html.ant +82 -0
- data/lib/antelope/generator/templates/html/js.ant +9 -0
- data/lib/antelope/generator/templates/info.ant +53 -0
- data/lib/antelope/generator/templates/ruby.ant +178 -146
- data/lib/antelope/generator.rb +66 -63
- data/lib/antelope/template/compiler.rb +78 -78
- data/lib/antelope/template/errors.rb +9 -9
- data/lib/antelope/template/scanner.rb +109 -109
- data/lib/antelope/template.rb +65 -60
- data/lib/antelope/version.rb +6 -6
- data/lib/antelope.rb +13 -13
- data/optimizations.txt +42 -0
- data/spec/antelope/ace/compiler_spec.rb +60 -60
- data/spec/antelope/ace/scanner_spec.rb +27 -27
- data/spec/antelope/constructor_spec.rb +133 -136
- data/spec/antelope/template_spec.rb +50 -49
- 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 +15 -15
- data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
- data/subl/Ace (Ruby).tmLanguage +153 -153
- metadata +17 -6
- data/lib/antelope/generator/templates/output.ant +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b92cf3cc4e8746993ec89f21f9eb97646787cbf1
|
4
|
+
data.tar.gz: 2739de2a0326fa116232b6f6be22e1b771d87225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bca5d306f74efc0f25f4823e288221e3b5c708a2f6a15e870254df602c617bfac7482c5871b6241a17c2fd81cad4bb83a132c7c04a44c2c035e14604faf85cd
|
7
|
+
data.tar.gz: 22b68475fe03066f181006e21763707dd01102143998634b8938597d771a9bca7a776f5980702a55db87db6ad923b63434c14dd12be925a2d1c0cf40ccdf9653
|
data/.gitignore
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
examples/*.rb
|
18
|
-
tmp
|
19
|
-
*.bundle
|
20
|
-
*.so
|
21
|
-
*.o
|
22
|
-
*.a
|
23
|
-
mkmf.log
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
examples/*.rb
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
24
|
+
*.ant.rb
|
25
|
+
*.output
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--color
|
2
|
-
-f d
|
3
|
-
--require spec_helper.rb
|
1
|
+
--color
|
2
|
+
-f d
|
3
|
+
--require spec_helper.rb
|
data/.travis.yml
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.2
|
4
|
-
- 2.1.0
|
5
|
-
- 2.0.0
|
6
|
-
- 1.9.3
|
7
|
-
- jruby-19mode
|
8
|
-
script: bundle exec rspec -f d spec
|
9
|
-
sudo: false
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.2
|
4
|
+
- 2.1.0
|
5
|
+
- 2.0.0
|
6
|
+
- 1.9.3
|
7
|
+
- jruby-19mode
|
8
|
+
script: bundle exec rspec -f d spec
|
9
|
+
sudo: false
|
10
|
+
cache: bundler
|
data/.yardopts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
--protected
|
2
|
-
--private
|
3
|
-
-m markdown
|
4
|
-
-
|
5
|
-
LICENSE.txt
|
6
|
-
CONTRIBUTING.md
|
7
|
-
GENERATORS.md
|
1
|
+
--protected
|
2
|
+
--private
|
3
|
+
-m markdown
|
4
|
+
-
|
5
|
+
LICENSE.txt
|
6
|
+
CONTRIBUTING.md
|
7
|
+
GENERATORS.md
|
data/CONTRIBUTING.md
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# Contributing to _Antelope_
|
2
|
-
|
3
|
-
First and foremost, **thank you**! Contributing to _Antelope_ is great! There are a few guidelines, however...
|
4
|
-
|
5
|
-
## Contribution Process
|
6
|
-
|
7
|
-
1. Fork the repository ([medcat/antelope])
|
8
|
-
2. Create a new branch for your feature (something like `my-feature`)
|
9
|
-
3. Make your changes
|
10
|
-
4. Commit your changes
|
11
|
-
5. if(notDone) goto 3;
|
12
|
-
6. Push your changes
|
13
|
-
7. Make a pull request
|
14
|
-
|
15
|
-
Creating a new branch is a _really, really_ good idea; it keeps things neat in the world of git. When you make the pull request, any commits you make to the merging branch are added to the pull request. Also, _please_ make sure you describe the pull request, and what it does, and why it's needed.
|
16
|
-
|
17
|
-
## Commit Message Style
|
18
|
-
|
19
|
-
I have to admit, I'm absolutely terrible at commits. But, in case of a commit, commit messages should be imperative - it's what the commit _does_, not what it _will do_ or what it _has done_; for example, "Create Generator for C Output". Messages should have a subject, and optionally a body; the subject should have no more than 50 characters, and should be concise, as well as in Title Case. If you can't fit information in the subject, put it in the body.
|
20
|
-
|
21
|
-
## Issues
|
22
|
-
|
23
|
-
When opening issues, there are a few requirements:
|
24
|
-
|
25
|
-
- Describe the problem
|
26
|
-
- Show how to reproduce it, if applicable
|
27
|
-
- Explain what you think is causing it, if applicable
|
28
|
-
- Give a plausible solution, if applicable
|
29
|
-
|
30
|
-
Give (us|me) as much information as needed so (we|I) can decide how to handle the issue.
|
31
|
-
|
32
|
-
## Closing Words
|
33
|
-
|
34
|
-
And, most of all, the last requirement: have fun!
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
[medcat/antelope]: https://github.com/medcat/antelope
|
1
|
+
# Contributing to _Antelope_
|
2
|
+
|
3
|
+
First and foremost, **thank you**! Contributing to _Antelope_ is great! There are a few guidelines, however...
|
4
|
+
|
5
|
+
## Contribution Process
|
6
|
+
|
7
|
+
1. Fork the repository ([medcat/antelope])
|
8
|
+
2. Create a new branch for your feature (something like `my-feature`)
|
9
|
+
3. Make your changes
|
10
|
+
4. Commit your changes
|
11
|
+
5. if(notDone) goto 3;
|
12
|
+
6. Push your changes
|
13
|
+
7. Make a pull request
|
14
|
+
|
15
|
+
Creating a new branch is a _really, really_ good idea; it keeps things neat in the world of git. When you make the pull request, any commits you make to the merging branch are added to the pull request. Also, _please_ make sure you describe the pull request, and what it does, and why it's needed.
|
16
|
+
|
17
|
+
## Commit Message Style
|
18
|
+
|
19
|
+
I have to admit, I'm absolutely terrible at commits. But, in case of a commit, commit messages should be imperative - it's what the commit _does_, not what it _will do_ or what it _has done_; for example, "Create Generator for C Output". Messages should have a subject, and optionally a body; the subject should have no more than 50 characters, and should be concise, as well as in Title Case. If you can't fit information in the subject, put it in the body.
|
20
|
+
|
21
|
+
## Issues
|
22
|
+
|
23
|
+
When opening issues, there are a few requirements:
|
24
|
+
|
25
|
+
- Describe the problem
|
26
|
+
- Show how to reproduce it, if applicable
|
27
|
+
- Explain what you think is causing it, if applicable
|
28
|
+
- Give a plausible solution, if applicable
|
29
|
+
|
30
|
+
Give (us|me) as much information as needed so (we|I) can decide how to handle the issue.
|
31
|
+
|
32
|
+
## Closing Words
|
33
|
+
|
34
|
+
And, most of all, the last requirement: have fun!
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
[medcat/antelope]: https://github.com/medcat/antelope
|
data/GENERATORS.md
CHANGED
@@ -1,124 +1,124 @@
|
|
1
|
-
# Generators
|
2
|
-
|
3
|
-
_Antelope_ comes with an assortment of generators; however, if you wish to create a custom generator, here's how.
|
4
|
-
|
5
|
-
First, you'll want to make your generator a subclass of `Antelope::Generator::Base`. This sets up a basic framework for you to build upon.
|
6
|
-
|
7
|
-
```Ruby
|
8
|
-
class MyGenerator < Antelope::Generator::Base
|
9
|
-
|
10
|
-
end
|
11
|
-
```
|
12
|
-
|
13
|
-
Next, you'll want to define a `generate` method on your generator that takes no arguments. This is used internally by _Antelope_ to actually have your generator perform its generation. In the case of this generator, we'll have it copy over a template (after running the templating generator over it over it).
|
14
|
-
|
15
|
-
```Ruby
|
16
|
-
class MyGenerator < Antelope::Generator::Base
|
17
|
-
|
18
|
-
def generate
|
19
|
-
template "my_template", "#{file}.my_file"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
`Base` provides a few convienince methods for you, one of them being [`template`](http://rubydoc.info/github/medcat/antelope/master/Antelope/Generator/Base#template-instance_method); `file` is also provided, and it contains the base part of the file name of the parser ace file that this is being generated for. The template, by default, should rest in `<lib path>/lib/antelope/generator/templates` (with `<lib path>` being the place that _Antelope_ was installed); however, if it should be changed, you can overwrite the `source_root` method on the class:
|
25
|
-
|
26
|
-
```Ruby
|
27
|
-
class MyGenerator < Antelope::Generator::Base
|
28
|
-
|
29
|
-
def self.source_root
|
30
|
-
Pathname.new("/path/to/source")
|
31
|
-
end
|
32
|
-
|
33
|
-
def generate
|
34
|
-
template "my_template", "#{file}.my_file"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
```
|
38
|
-
|
39
|
-
In the template, the code is run in the context of the instance of the class, so you have access to instance variables and methods as if you were defining a method on the class:
|
40
|
-
|
41
|
-
```
|
42
|
-
{{ table.each_with_index do |hash, i| }}
|
43
|
-
state {{= i }}:
|
44
|
-
{{ hash.each do |token, action| }}
|
45
|
-
for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
|
46
|
-
{{ end }}
|
47
|
-
{{ end }}
|
48
|
-
```
|
49
|
-
|
50
|
-
_Note: in templates, blocks that start at the beginning of a line and end at the end of a line do not produce any whitespace._
|
51
|
-
|
52
|
-
`table` here is defined on the base class, and we're iterating over all of the values of it.
|
53
|
-
|
54
|
-
The last thing to do is to register the generator with _Antelope_. This is as simple as adding a line `register_as "my_generator"` to the class definition. Then, if any grammar file has the type `"my_generator"`, your generator will be run (assuming it's been required by _Antelope_).
|
55
|
-
|
56
|
-
The finialized product:
|
57
|
-
|
58
|
-
```Ruby
|
59
|
-
# my_generator.rb
|
60
|
-
class MyGenerator < Antelope::Generator::Base
|
61
|
-
|
62
|
-
register_as "my_generator"
|
63
|
-
|
64
|
-
def self.source_root
|
65
|
-
Pathname.new("/path/to/source")
|
66
|
-
end
|
67
|
-
|
68
|
-
def generate
|
69
|
-
template "my_template.erb", "#{file}.my_file"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
```
|
75
|
-
# my_template.ant
|
76
|
-
{{ table.each_with_index do |hash, i| }}
|
77
|
-
state {{= i }}:
|
78
|
-
{{ hash.each do |token, action| }}
|
79
|
-
for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
|
80
|
-
{{ end }}
|
81
|
-
{{ end }}
|
82
|
-
```
|
83
|
-
|
84
|
-
## Bundling
|
85
|
-
|
86
|
-
If you want to bundle a few generators together such that the bundle is generated together, you can use an `Antelope::Generator::Group`. This would be useful for something like a C language generator, which may need to generate both a header and a source file:
|
87
|
-
|
88
|
-
```Ruby
|
89
|
-
class CHeader < Antelope::Generator::Base
|
90
|
-
# ...
|
91
|
-
end
|
92
|
-
|
93
|
-
class CSource < Antelope::Generator::Base
|
94
|
-
# ...
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
class C < Antelope::Generator::Group
|
99
|
-
register_generator CHeader, "c-header"
|
100
|
-
register_generator CSource, "c-source"
|
101
|
-
end
|
102
|
-
```
|
103
|
-
|
104
|
-
The `register_generator` takes a generator class and a name for the generator, and adds the generator to the list of generators on the receiver (in this case, the `C` class). Now, when `C#generate` is run, it will run both `CHeader#generate` and `CSource#generate`.
|
105
|
-
|
106
|
-
## Using Compiler Directives
|
107
|
-
|
108
|
-
Directives are statements that are used in Ace files in order to pass information to _Antelope_. They normally follow the syntax `%<directive name> [directive arguments]*`. See [the Ace file format](http://rubydoc.info/github/medcat/antelope/Antelope/Ace) for more information about directives.
|
109
|
-
|
110
|
-
In some cases, like in the [Ruby generator][Ruby], options from the Ace file are needed for generation. In the case of the Ruby generator, we need the error class that the developer wants the generator to use; and we reference it through the `ruby.error-class` directive. In order to define directives that can be used in custom generators, you just need to add a few lines:
|
111
|
-
|
112
|
-
```Ruby
|
113
|
-
class MyGenerator < Antelope::Generator::Base
|
114
|
-
|
115
|
-
has_directive "my-generator.some-value", Boolean
|
116
|
-
|
117
|
-
end
|
118
|
-
```
|
119
|
-
|
120
|
-
In this example, we define a directive named `my-generator.some-value`; this directive is eventually coerced into a `true`/`false` value. In order to actually use the value of the directive, in either the template or a method on the generator, you can reference `directives["my-generator.some-value"]`, which will be `nil` (it wasn't defined), `true` (it was defined, with any arguments), or `false` (it was explicitly defined with one argument, `"false"`). Some other values you can pass in place of `Boolean` would be `:single` (or `:one`), which only gives the first argument passed to the directive; an `Array` of types, which would coerce each argument into its corresponding element of the array; `Array`, which will give an array of the given arguments; `String`, which gives a string representation of the first argument; any `Numeric` subclass, which would coerce the first argument into an integer; `Float`, which would coerce the first argument into a float; any class, which would be instantized with the arguments to the directive. Any other values would yield an error.
|
121
|
-
|
122
|
-
It is recommended that you namespace directives that only your generator would use, using dashed syntax, like in our example above. However, some directives are not namespaced, or are not namespaced under a generator; these may be used by any generator. It is also recommended that you declare every directive that you use.
|
123
|
-
|
124
|
-
[Ruby]: http://rubydoc.info/github/medcat/antelope/Antelope/Generator/Ruby
|
1
|
+
# Generators
|
2
|
+
|
3
|
+
_Antelope_ comes with an assortment of generators; however, if you wish to create a custom generator, here's how.
|
4
|
+
|
5
|
+
First, you'll want to make your generator a subclass of `Antelope::Generator::Base`. This sets up a basic framework for you to build upon.
|
6
|
+
|
7
|
+
```Ruby
|
8
|
+
class MyGenerator < Antelope::Generator::Base
|
9
|
+
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
Next, you'll want to define a `generate` method on your generator that takes no arguments. This is used internally by _Antelope_ to actually have your generator perform its generation. In the case of this generator, we'll have it copy over a template (after running the templating generator over it over it).
|
14
|
+
|
15
|
+
```Ruby
|
16
|
+
class MyGenerator < Antelope::Generator::Base
|
17
|
+
|
18
|
+
def generate
|
19
|
+
template "my_template", "#{file}.my_file"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
`Base` provides a few convienince methods for you, one of them being [`template`](http://rubydoc.info/github/medcat/antelope/master/Antelope/Generator/Base#template-instance_method); `file` is also provided, and it contains the base part of the file name of the parser ace file that this is being generated for. The template, by default, should rest in `<lib path>/lib/antelope/generator/templates` (with `<lib path>` being the place that _Antelope_ was installed); however, if it should be changed, you can overwrite the `source_root` method on the class:
|
25
|
+
|
26
|
+
```Ruby
|
27
|
+
class MyGenerator < Antelope::Generator::Base
|
28
|
+
|
29
|
+
def self.source_root
|
30
|
+
Pathname.new("/path/to/source")
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate
|
34
|
+
template "my_template", "#{file}.my_file"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
In the template, the code is run in the context of the instance of the class, so you have access to instance variables and methods as if you were defining a method on the class:
|
40
|
+
|
41
|
+
```
|
42
|
+
{{ table.each_with_index do |hash, i| }}
|
43
|
+
state {{= i }}:
|
44
|
+
{{ hash.each do |token, action| }}
|
45
|
+
for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
|
46
|
+
{{ end }}
|
47
|
+
{{ end }}
|
48
|
+
```
|
49
|
+
|
50
|
+
_Note: in templates, blocks that start at the beginning of a line and end at the end of a line do not produce any whitespace._
|
51
|
+
|
52
|
+
`table` here is defined on the base class, and we're iterating over all of the values of it.
|
53
|
+
|
54
|
+
The last thing to do is to register the generator with _Antelope_. This is as simple as adding a line `register_as "my_generator"` to the class definition. Then, if any grammar file has the type `"my_generator"`, your generator will be run (assuming it's been required by _Antelope_).
|
55
|
+
|
56
|
+
The finialized product:
|
57
|
+
|
58
|
+
```Ruby
|
59
|
+
# my_generator.rb
|
60
|
+
class MyGenerator < Antelope::Generator::Base
|
61
|
+
|
62
|
+
register_as "my_generator"
|
63
|
+
|
64
|
+
def self.source_root
|
65
|
+
Pathname.new("/path/to/source")
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate
|
69
|
+
template "my_template.erb", "#{file}.my_file"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
```
|
75
|
+
# my_template.ant
|
76
|
+
{{ table.each_with_index do |hash, i| }}
|
77
|
+
state {{= i }}:
|
78
|
+
{{ hash.each do |token, action| }}
|
79
|
+
for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
|
80
|
+
{{ end }}
|
81
|
+
{{ end }}
|
82
|
+
```
|
83
|
+
|
84
|
+
## Bundling
|
85
|
+
|
86
|
+
If you want to bundle a few generators together such that the bundle is generated together, you can use an `Antelope::Generator::Group`. This would be useful for something like a C language generator, which may need to generate both a header and a source file:
|
87
|
+
|
88
|
+
```Ruby
|
89
|
+
class CHeader < Antelope::Generator::Base
|
90
|
+
# ...
|
91
|
+
end
|
92
|
+
|
93
|
+
class CSource < Antelope::Generator::Base
|
94
|
+
# ...
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
class C < Antelope::Generator::Group
|
99
|
+
register_generator CHeader, "c-header"
|
100
|
+
register_generator CSource, "c-source"
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
The `register_generator` takes a generator class and a name for the generator, and adds the generator to the list of generators on the receiver (in this case, the `C` class). Now, when `C#generate` is run, it will run both `CHeader#generate` and `CSource#generate`.
|
105
|
+
|
106
|
+
## Using Compiler Directives
|
107
|
+
|
108
|
+
Directives are statements that are used in Ace files in order to pass information to _Antelope_. They normally follow the syntax `%<directive name> [directive arguments]*`. See [the Ace file format](http://rubydoc.info/github/medcat/antelope/Antelope/Ace) for more information about directives.
|
109
|
+
|
110
|
+
In some cases, like in the [Ruby generator][Ruby], options from the Ace file are needed for generation. In the case of the Ruby generator, we need the error class that the developer wants the generator to use; and we reference it through the `ruby.error-class` directive. In order to define directives that can be used in custom generators, you just need to add a few lines:
|
111
|
+
|
112
|
+
```Ruby
|
113
|
+
class MyGenerator < Antelope::Generator::Base
|
114
|
+
|
115
|
+
has_directive "my-generator.some-value", Boolean
|
116
|
+
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
In this example, we define a directive named `my-generator.some-value`; this directive is eventually coerced into a `true`/`false` value. In order to actually use the value of the directive, in either the template or a method on the generator, you can reference `directives["my-generator.some-value"]`, which will be `nil` (it wasn't defined), `true` (it was defined, with any arguments), or `false` (it was explicitly defined with one argument, `"false"`). Some other values you can pass in place of `Boolean` would be `:single` (or `:one`), which only gives the first argument passed to the directive; an `Array` of types, which would coerce each argument into its corresponding element of the array; `Array`, which will give an array of the given arguments; `String`, which gives a string representation of the first argument; any `Numeric` subclass, which would coerce the first argument into an integer; `Float`, which would coerce the first argument into a float; any class, which would be instantized with the arguments to the directive. Any other values would yield an error.
|
121
|
+
|
122
|
+
It is recommended that you namespace directives that only your generator would use, using dashed syntax, like in our example above. However, some directives are not namespaced, or are not namespaced under a generator; these may be used by any generator. It is also recommended that you declare every directive that you use.
|
123
|
+
|
124
|
+
[Ruby]: http://rubydoc.info/github/medcat/antelope/Antelope/Generator/Ruby
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in antelope.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'coveralls'
|
7
|
-
gem 'simplecov'
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in antelope.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'coveralls'
|
7
|
+
gem 'simplecov'
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 Jeremy Rodi
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2014 Jeremy Rodi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|