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

Instance Method Details

#from_file(file_name) ⇒ Grammar

Loads a grammar from a file. Assumes the output directory and name from the file name.

Parameters:

  • file_name (String)

    the file name.

Returns:

See Also:



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.

Parameters:

  • name (String)

    the name of the grammar.

  • output (String)

    the output directory.

  • string (String)

    the grammar body.

Returns:

See Also:



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