Class: JSGF::Rule

Inherits:
Array
  • Object
show all
Defined in:
lib/jsgf/rule.rb

Class Method Summary collapse

Class Method Details

.parse_atom(atom, optional: nil) ⇒ Object

Convert a string containing a single atom into an Atom or a rule reference

Parameters:

  • atom (String)

    the text to parse



5
6
7
8
9
10
11
12
13
# File 'lib/jsgf/rule.rb', line 5

def self.parse_atom(atom, optional:nil)
    case atom
	# Parse optionals first to prevent the reference-regex from grabbing it first
	when /\[(.*)\]/		    then parse_atom($1, optional:true)
	when /\<(.*)\>/, /:(.*)/    then Atom.new($1, optional:optional, reference:true)
	else
	    Atom.new(atom, optional:optional)
    end
end