Module: Srgs::DSL

Defined in:
lib/srgs/dsl.rb

Instance Method Summary collapse

Instance Method Details

#example(text) ⇒ Object



4
5
6
# File 'lib/srgs/dsl.rb', line 4

def example(text)
  @grammar.current_level << Example.new(text)
end

#grammar(root, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/srgs/dsl.rb', line 8

def grammar(root, &block)
  @grammar = Grammar.new root
  instance_eval &block
  @grammar.current_level = nil
  grammar =  Srgs.build(@grammar)
  puts grammar
  grammar
end

#item(element = '', args = {}, &block) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/srgs/dsl.rb', line 17

def item(element = '', args = {}, &block)
  item = Item.new(element, args[:repeat], args[:repeat_prob], args[:weight])
  @grammar.current_level << item
  old_current = @grammar.current_level
  @grammar.current_level = item
  instance_eval &block unless block.nil?
  @grammar.current_level = old_current
end

#lexicon(uri, args = {}) ⇒ Object



26
27
28
# File 'lib/srgs/dsl.rb', line 26

def lexicon(uri, args = {})
  @grammar << Lexicon.new(uri, args[:type])
end

#meta(content, args = {}) ⇒ Object



30
31
32
# File 'lib/srgs/dsl.rb', line 30

def meta(content, args = {})
  @grammar << Meta.new(content, args[:name], args[:http_equiv])
end

#one_of(&block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/srgs/dsl.rb', line 34

def one_of(&block)
  old_current = @grammar.current_level
  @grammar.current_level = OneOf.new
  old_current << @grammar.current_level
  instance_eval &block
  @grammar.current_level = old_current
end

#private_rule(id, args = {}, &block) ⇒ Object



49
50
51
52
53
54
# File 'lib/srgs/dsl.rb', line 49

def private_rule(id, args = {},  &block)
  @grammar.current_level = Rule.new(id, 'private', args[:dynamic])
  @grammar << @grammar.current_level
  instance_eval &block
  @grammar.current_level = nil
end

#public_rule(id, args = {}, &block) ⇒ Object



42
43
44
45
46
47
# File 'lib/srgs/dsl.rb', line 42

def public_rule(id, args = {}, &block)
  @grammar.current_level = Rule.new(id, 'public', args[:dynamic])
  @grammar << @grammar.current_level
  instance_eval &block
  @grammar.current_level = nil
end

#reference(name, args = {}) ⇒ Object



56
57
58
# File 'lib/srgs/dsl.rb', line 56

def reference(name, args = {})
  @grammar.current_level << RuleRef.new(name, args[:special])
end

#reference_item(name, args = {}) ⇒ Object



60
61
62
# File 'lib/srgs/dsl.rb', line 60

def reference_item(name, args = {})
  @grammar.current_level << Item.new(RuleRef.new(name, args[:special]))
end

#reference_wildcardObject



64
65
66
# File 'lib/srgs/dsl.rb', line 64

def reference_wildcard
  @grammar.current_level << RuleRef.new(nil, 'GARBAGE')
end

#tag(text) ⇒ Object



68
69
70
# File 'lib/srgs/dsl.rb', line 68

def tag(text)
  @grammar.current_level << Tag.new(text)
end

#text(text) ⇒ Object



72
73
74
# File 'lib/srgs/dsl.rb', line 72

def text(text)
  @grammar.current_level << text
end

#token(text, args = {}) ⇒ Object



76
77
78
# File 'lib/srgs/dsl.rb', line 76

def token(text, args = {})
  @grammar.current_level << Token.new(text, args[:display], args[:pron])
end