Module: Antelope::Ace::Grammar::Loading::ClassMethods
- Defined in:
- lib/antelope/ace/grammar/loading.rb
Overview
Defines class methods on the grammar.
Instance Method Summary collapse
-
#from_file(file_name) ⇒ Grammar
Loads a grammar from a file.
-
#from_string(name, output, string) ⇒ Grammar
Loads a grammar from a string.
Instance Method Details
#from_file(file_name) ⇒ Grammar
Loads a grammar from a file. Assumes the output directory and name from the file name.
19 20 21 22 23 24 |
# File 'lib/antelope/ace/grammar/loading.rb', line 19 def from_file(file_name) body = File.read(file_name) output = File.dirname(file_name) name = File.basename(file_name).gsub(/\.[A-Za-z]+/, "") from_string(name, output, body) end |
#from_string(name, output, string) ⇒ Grammar
Loads a grammar from a string. First runs the scanner and compiler over the string, and then instantiates a new Grammar from the resultant.
36 37 38 39 40 |
# File 'lib/antelope/ace/grammar/loading.rb', line 36 def from_string(name, output, string) scanner = Ace::Scanner.scan(string, name) compiler = Ace::Compiler.compile(scanner) new(name, output, compiler) end |