antelope 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +25 -25
  3. data/.rspec +3 -3
  4. data/.travis.yml +10 -10
  5. data/.yardopts +7 -7
  6. data/CONTRIBUTING.md +50 -38
  7. data/GENERATORS.md +180 -124
  8. data/Gemfile +7 -7
  9. data/LICENSE.txt +22 -22
  10. data/README.md +240 -104
  11. data/Rakefile +2 -2
  12. data/TODO.md +58 -58
  13. data/antelope.gemspec +29 -28
  14. data/bin/antelope +7 -7
  15. data/examples/deterministic.ace +35 -35
  16. data/examples/example.ace +52 -51
  17. data/examples/example.ace.err +192 -192
  18. data/examples/example.ace.inf +432 -432
  19. data/examples/example.ate +70 -70
  20. data/examples/example.ate.err +192 -192
  21. data/examples/example.ate.inf +432 -432
  22. data/examples/liquidscript.ace +233 -233
  23. data/examples/simple.ace +22 -22
  24. data/lib/antelope/ace/compiler.rb +334 -334
  25. data/lib/antelope/ace/errors.rb +30 -30
  26. data/lib/antelope/ace/scanner/argument.rb +57 -57
  27. data/lib/antelope/ace/scanner/first.rb +89 -89
  28. data/lib/antelope/ace/scanner/second.rb +178 -178
  29. data/lib/antelope/ace/scanner/third.rb +27 -27
  30. data/lib/antelope/ace/scanner.rb +144 -144
  31. data/lib/antelope/ace.rb +47 -47
  32. data/lib/antelope/cli.rb +60 -60
  33. data/lib/antelope/errors.rb +25 -25
  34. data/lib/antelope/generation/constructor/first.rb +86 -86
  35. data/lib/antelope/generation/constructor/follow.rb +105 -105
  36. data/lib/antelope/generation/constructor/nullable.rb +64 -64
  37. data/lib/antelope/generation/constructor.rb +127 -127
  38. data/lib/antelope/generation/errors.rb +17 -17
  39. data/lib/antelope/generation/null.rb +13 -13
  40. data/lib/antelope/generation/recognizer/rule.rb +216 -216
  41. data/lib/antelope/generation/recognizer/state.rb +129 -129
  42. data/lib/antelope/generation/recognizer.rb +177 -177
  43. data/lib/antelope/generation/tableizer.rb +176 -176
  44. data/lib/antelope/generation.rb +15 -15
  45. data/lib/antelope/generator/base/coerce.rb +115 -0
  46. data/lib/antelope/generator/base/extra.rb +50 -0
  47. data/lib/antelope/generator/base.rb +134 -264
  48. data/lib/antelope/generator/c.rb +11 -11
  49. data/lib/antelope/generator/c_header.rb +105 -105
  50. data/lib/antelope/generator/c_source.rb +39 -39
  51. data/lib/antelope/generator/error.rb +34 -34
  52. data/lib/antelope/generator/group.rb +60 -57
  53. data/lib/antelope/generator/html.rb +51 -51
  54. data/lib/antelope/generator/info.rb +47 -47
  55. data/lib/antelope/generator/null.rb +18 -18
  56. data/lib/antelope/generator/output.rb +17 -17
  57. data/lib/antelope/generator/ruby.rb +112 -79
  58. data/lib/antelope/generator/templates/c_header.ant +36 -36
  59. data/lib/antelope/generator/templates/c_source.ant +202 -202
  60. data/lib/antelope/generator/templates/error.erb +40 -0
  61. data/lib/antelope/generator/templates/html/antelope.css +53 -1
  62. data/lib/antelope/generator/templates/html/antelope.html +82 -1
  63. data/lib/antelope/generator/templates/html/antelope.js +9 -1
  64. data/lib/antelope/generator/templates/html/css.ant +53 -53
  65. data/lib/antelope/generator/templates/html/html.ant +82 -82
  66. data/lib/antelope/generator/templates/html/js.ant +9 -9
  67. data/lib/antelope/generator/templates/info.erb +61 -0
  68. data/lib/antelope/generator/templates/{ruby.ant → ruby.erb} +171 -178
  69. data/lib/antelope/generator.rb +62 -66
  70. data/lib/antelope/grammar/generation.rb +76 -76
  71. data/lib/antelope/grammar/loading.rb +84 -84
  72. data/lib/antelope/grammar/precedence.rb +59 -59
  73. data/lib/antelope/grammar/precedences.rb +64 -64
  74. data/lib/antelope/grammar/production.rb +56 -56
  75. data/lib/antelope/grammar/productions.rb +154 -154
  76. data/lib/antelope/grammar/symbols.rb +64 -64
  77. data/lib/antelope/grammar/token/epsilon.rb +23 -23
  78. data/lib/antelope/grammar/token/error.rb +24 -24
  79. data/lib/antelope/grammar/token/nonterminal.rb +15 -15
  80. data/lib/antelope/grammar/token/terminal.rb +15 -15
  81. data/lib/antelope/grammar/token.rb +231 -231
  82. data/lib/antelope/grammar.rb +68 -68
  83. data/lib/antelope/version.rb +6 -6
  84. data/lib/antelope.rb +18 -19
  85. data/optimizations.txt +42 -42
  86. data/spec/antelope/ace/compiler_spec.rb +60 -60
  87. data/spec/antelope/ace/scanner_spec.rb +27 -27
  88. data/spec/antelope/generation/constructor_spec.rb +131 -131
  89. data/spec/fixtures/simple.ace +22 -22
  90. data/spec/spec_helper.rb +39 -39
  91. data/spec/support/benchmark_helper.rb +5 -5
  92. data/spec/support/grammar_helper.rb +14 -14
  93. data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
  94. data/subl/Ace (Ruby).tmLanguage +153 -153
  95. metadata +22 -11
  96. data/lib/antelope/generator/templates/error.ant +0 -34
  97. data/lib/antelope/generator/templates/info.ant +0 -53
  98. data/lib/antelope/template/compiler.rb +0 -78
  99. data/lib/antelope/template/errors.rb +0 -9
  100. data/lib/antelope/template/scanner.rb +0 -109
  101. data/lib/antelope/template.rb +0 -64
  102. data/spec/antelope/template_spec.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8616858e0c427809df04d9549c82e59533f7e3d6
4
- data.tar.gz: 5417d980a44bcba6eae47087fa776c4a386cafb2
3
+ metadata.gz: 4fe39127307122c50724ddcc32a04d775a21370e
4
+ data.tar.gz: 6e34887449541f93b104ebc2f46d6960e06eea5b
5
5
  SHA512:
6
- metadata.gz: b39550335aaea311c99c0af16de97b84a8148747f664426a283c48f5f2622ec419ffc51cf4fbd68deb1ad546363caf0347c1e983d43ef150b53d28ac18cb3d58
7
- data.tar.gz: 3d2b652ff10db8e7f090bf9f3f36f3f216d5caadf3082c4bc5790c558a292772f4ea18cab24471b3d91529c59f210d8843d939f2fd8835cb0c5dfbc8e1398b8b
6
+ metadata.gz: 23087f5fbc9505da1aae8dc5705d44173b6558bce8c06db52fb34bee34fc449d38067866b8cf0773a28e89cdfb37c3a070848c95a2cf9d06183fe9915b99becf
7
+ data.tar.gz: 486c530e2e26b5e0d4b8cb4b89254944a6ec2e1bc4e52bb2546271caf9b05ad02f0c771d7c1147ae4e688c0b2fa1342f2c68f57d23c77dd7fc2272d4c134d854
data/.gitignore CHANGED
@@ -1,25 +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
24
- *.ant.rb
25
- *.output
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,10 +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
10
- cache: bundler
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,50 @@
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
4
+ great! There are a few guidelines, however...
5
+
6
+ ## Contribution Process
7
+
8
+ 1. Fork the repository ([medcat/antelope])
9
+ 2. Create a new branch for your feature (something like `my-feature`)
10
+ 3. Make your changes
11
+ 4. Commit your changes
12
+ 5. if(notDone) goto 3;
13
+ 6. Push your changes
14
+ 7. Make a pull request
15
+
16
+ Creating a new branch is a _really, really_ good idea; it keeps things
17
+ neat in the world of git. When you make the pull request, any commits
18
+ you make to the merging branch are added to the pull request. Also,
19
+ _please_ make sure you describe the pull request, and what it does,
20
+ and why it's needed.
21
+
22
+ ## Commit Message Style
23
+
24
+ I have to admit, I'm absolutely terrible at commits. But, in case of
25
+ a commit, commit messages should be imperative - it's what the commit
26
+ _does_, not what it _will do_ or what it _has done_; for example,
27
+ "Create Generator for C Output". Messages should have a subject, and
28
+ optionally a body; the subject should have no more than 50 characters,
29
+ and should be concise, as well as in Title Case. If you can't fit
30
+ information in the subject, put it in the body.
31
+
32
+ ## Issues
33
+
34
+ When opening issues, there are a few requirements:
35
+
36
+ - Describe the problem
37
+ - Show how to reproduce it, if applicable
38
+ - Explain what you think is causing it, if applicable
39
+ - Give a plausible solution, if applicable
40
+
41
+ Give (us|me) as much information as needed so (we|I) can decide how to
42
+ handle the issue.
43
+
44
+ ## Closing Words
45
+
46
+ And, most of all, the last requirement: have fun!
47
+
48
+
49
+
50
+ [medcat/antelope]: https://github.com/medcat/antelope
data/GENERATORS.md CHANGED
@@ -1,124 +1,180 @@
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
4
+ wish to create a custom generator, here's how.
5
+
6
+ First, you'll want to make your generator a subclass of
7
+ `Antelope::Generator::Base`. This sets up a basic framework for you
8
+ to build upon.
9
+
10
+ ```Ruby
11
+ class MyGenerator < Antelope::Generator::Base
12
+
13
+ end
14
+ ```
15
+
16
+ Next, you'll want to define a `generate` method on your generator that
17
+ takes no arguments. This is used internally by _Antelope_ to actually
18
+ have your generator perform its generation. In the case of this
19
+ generator, we'll have it copy over a template (after running the
20
+ templating generator over it over it).
21
+
22
+ ```Ruby
23
+ class MyGenerator < Antelope::Generator::Base
24
+
25
+ def generate
26
+ template "my_template", "#{file}.my_file"
27
+ end
28
+ end
29
+ ```
30
+
31
+ `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);
32
+ `file` is also provided, and it contains the base part of the file
33
+ name of the parser ace file that this is being generated for. The
34
+ template, by default, should rest in
35
+ `<lib path>/lib/antelope/generator/templates` (with `<lib path>` being
36
+ the place that _Antelope_ was installed); however, if it should be
37
+ changed, you can overwrite the `source_root` method on the class:
38
+
39
+ ```Ruby
40
+ class MyGenerator < Antelope::Generator::Base
41
+
42
+ def self.source_root
43
+ Pathname.new("/path/to/source")
44
+ end
45
+
46
+ def generate
47
+ template "my_template", "#{file}.my_file"
48
+ end
49
+ end
50
+ ```
51
+
52
+ In the template, the code is run in the context of the instance of the
53
+ class, so you have access to instance variables and methods as if you
54
+ were defining a method on the class:
55
+
56
+ ```
57
+ {{ table.each_with_index do |hash, i| }}
58
+ state {{= i }}:
59
+ {{ hash.each do |token, action| }}
60
+ for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
61
+ {{ end }}
62
+ {{ end }}
63
+ ```
64
+
65
+ _Note: in templates, blocks that start at the beginning of a line and
66
+ end at the end of a line do not produce any whitespace._
67
+
68
+ `table` here is defined on the base class, and we're iterating over
69
+ all of the values of it.
70
+
71
+ The last thing to do is to register the generator with _Antelope_.
72
+ This is as simple as adding a line `register_as "my_generator"` to the
73
+ class definition. Then, if any grammar file has the type
74
+ `"my_generator"`, your generator will be run (assuming it's been
75
+ required by _Antelope_).
76
+
77
+ The finialized product:
78
+
79
+ ```Ruby
80
+ # my_generator.rb
81
+ class MyGenerator < Antelope::Generator::Base
82
+
83
+ register_as "my_generator"
84
+
85
+ def self.source_root
86
+ Pathname.new("/path/to/source")
87
+ end
88
+
89
+ def generate
90
+ template "my_template.erb", "#{file}.my_file"
91
+ end
92
+ end
93
+ ```
94
+
95
+ ```
96
+ # my_template.ant
97
+ {{ table.each_with_index do |hash, i| }}
98
+ state {{= i }}:
99
+ {{ hash.each do |token, action| }}
100
+ for {{= token }}, I'll {{= action[0] }} {{= action[1] }}
101
+ {{ end }}
102
+ {{ end }}
103
+ ```
104
+
105
+ ## Bundling
106
+
107
+ If you want to bundle a few generators together such that the bundle
108
+ is generated together, you can use an `Antelope::Generator::Group`.
109
+ This would be useful for something like a C language generator, which
110
+ may need to generate both a header and a source file:
111
+
112
+ ```Ruby
113
+ class CHeader < Antelope::Generator::Base
114
+ # ...
115
+ end
116
+
117
+ class CSource < Antelope::Generator::Base
118
+ # ...
119
+ end
120
+
121
+
122
+ class C < Antelope::Generator::Group
123
+ register_generator CHeader, "c-header"
124
+ register_generator CSource, "c-source"
125
+ end
126
+ ```
127
+
128
+ The `register_generator` takes a generator class and a name for the
129
+ generator, and adds the generator to the list of generators on the
130
+ receiver (in this case, the `C` class). Now, when `C#generate` is
131
+ run, it will run both `CHeader#generate` and `CSource#generate`.
132
+
133
+ ## Using Compiler Directives
134
+
135
+ Directives are statements that are used in Ace files in order to pass
136
+ information to _Antelope_. They normally follow the syntax
137
+ `%<directive name> [directive arguments]*`. See
138
+ [the Ace file format](http://rubydoc.info/github/medcat/antelope/Antelope/Ace)
139
+ for more information about directives.
140
+
141
+ In some cases, like in the [Ruby generator][Ruby], options from the
142
+ Ace file are needed for generation. In the case of the Ruby
143
+ generator, we need the error class that the developer wants the
144
+ generator to use; and we reference it through the `ruby.error-class`
145
+ directive. In order to define directives that can be used in custom
146
+ generators, you just need to add a few lines:
147
+
148
+ ```Ruby
149
+ class MyGenerator < Antelope::Generator::Base
150
+
151
+ has_directive "my-generator.some-value", Boolean
152
+
153
+ end
154
+ ```
155
+
156
+ In this example, we define a directive named
157
+ `my-generator.some-value`; this directive is eventually coerced into
158
+ a `true`/`false` value. In order to actually use the value of the
159
+ directive, in either the template or a method on the generator, you
160
+ can reference `directives["my-generator.some-value"]`, which will be
161
+ `nil` (it wasn't defined), `true` (it was defined, with any
162
+ arguments), or `false` (it was explicitly defined with one argument,
163
+ `"false"`). Some other values you can pass in place of `Boolean`
164
+ would be `:single` (or `:one`), which only gives the first argument
165
+ passed to the directive; an `Array` of types, which would coerce each
166
+ argument into its corresponding element of the array; `Array`, which
167
+ will give an array of the given arguments; `String`, which gives a
168
+ string representation of the first argument; any `Numeric` subclass,
169
+ which would coerce the first argument into an integer; `Float`, which
170
+ would coerce the first argument into a float; any class, which would
171
+ be instantized with the arguments to the directive. Any other values
172
+ would yield an error.
173
+
174
+ It is recommended that you namespace directives that only your
175
+ generator would use, using dashed syntax, like in our example above.
176
+ However, some directives are not namespaced, or are not namespaced
177
+ under a generator; these may be used by any generator. It is also
178
+ recommended that you declare every directive that you use.
179
+
180
+ [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.