Class: SexpGrammar::Grammar

Inherits:
Object
  • Object
show all
Defined in:
lib/sexp_grammar/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules = {}, root = rules.keys.first) ⇒ Grammar

Returns a new instance of Grammar.



6
7
8
9
# File 'lib/sexp_grammar/grammar.rb', line 6

def initialize(rules = {}, root = rules.keys.first)
  @rules = compile_rules(rules)
  @root  = root && self[root.to_sym]
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



4
5
6
# File 'lib/sexp_grammar/grammar.rb', line 4

def rules
  @rules
end

Instance Method Details

#[](rule_name) ⇒ Object



11
12
13
# File 'lib/sexp_grammar/grammar.rb', line 11

def [](rule_name)
  @rules[rule_name]
end

#match?(sexp) ⇒ Boolean Also known as: ===

Returns:

  • (Boolean)


15
16
17
# File 'lib/sexp_grammar/grammar.rb', line 15

def match?(sexp)
  @root.match?(sexp)
end