Module: Sexpr::Grammar::Options

Included in:
Sexpr::Grammar
Defined in:
lib/sexpr/grammar/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/sexpr/grammar/options.rb', line 5

def options
  @options
end

#parserObject (readonly)

Returns the value of attribute parser.



9
10
11
# File 'lib/sexpr/grammar/options.rb', line 9

def parser
  @parser
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/sexpr/grammar/options.rb', line 6

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/sexpr/grammar/options.rb', line 8

def root
  @root
end

#rulesObject (readonly)

Returns the value of attribute rules.



7
8
9
# File 'lib/sexpr/grammar/options.rb', line 7

def rules
  @rules
end

Instance Method Details

#compile_rules(rules) ⇒ Object



47
48
49
# File 'lib/sexpr/grammar/options.rb', line 47

def compile_rules(rules)
  @rules = rules
end

#install_options(options) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
# File 'lib/sexpr/grammar/options.rb', line 11

def install_options(options)
  @options = options
  install_path
  install_rules
  install_root
  install_parser
  yield self if block_given?
end

#install_parserObject



39
40
41
42
43
44
45
# File 'lib/sexpr/grammar/options.rb', line 39

def install_parser
  @parser = option(:parser)
  if @parser.is_a?(String) && !File.exists?(@parser)
    @parser = File.join(File.dirname(path), @parser)
  end
  @parser = Parser.factor(@parser) if @parser
end

#install_pathObject



24
25
26
# File 'lib/sexpr/grammar/options.rb', line 24

def install_path
  @path = option(:path)
end

#install_rootObject



33
34
35
36
37
# File 'lib/sexpr/grammar/options.rb', line 33

def install_root
  @root = option(:root)
  @root = rules.keys.first unless @root
  @root = root.to_sym if @root
end

#install_rulesObject



28
29
30
31
# File 'lib/sexpr/grammar/options.rb', line 28

def install_rules
  @rules = option(:rules) || {}
  @rules = compile_rules(@rules)
end

#option(key) ⇒ Object



20
21
22
# File 'lib/sexpr/grammar/options.rb', line 20

def option(key)
  @options[key.to_sym] || @options[key.to_s]
end