Class: KPeg::Operator
- Inherits:
-
Object
show all
- Defined in:
- lib/kpeg/grammar.rb
Direct Known Subclasses
Action, AndPredicate, Bounds, CharRange, Choice, Collect, Dot, ForeignInvokeRule, InvokeRule, LiteralRegexp, LiteralString, Multiple, NotPredicate, RuleReference, Sequence, Tag
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Operator.
17
18
19
20
|
# File 'lib/kpeg/grammar.rb', line 17
def initialize
@action = nil
@has_tags = false
end
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
22
23
24
|
# File 'lib/kpeg/grammar.rb', line 22
def action
@action
end
|
Instance Method Details
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/kpeg/grammar.rb', line 28
def detect_tags(ops)
tags = []
ops.each_with_index do |r,idx|
if r.kind_of?(Tag)
@has_tags = true
tags << idx
end
end
@tags = tags if @has_tags
end
|
#inspect_type(tag, body) ⇒ Object
45
46
47
|
# File 'lib/kpeg/grammar.rb', line 45
def inspect_type(tag, body)
"#<#{tag} #{body}>"
end
|
#prune_values(values) ⇒ Object
40
41
42
43
|
# File 'lib/kpeg/grammar.rb', line 40
def prune_values(values)
return values unless @has_tags
return values.values_at(*@tags)
end
|
#set_action(act) ⇒ Object
24
25
26
|
# File 'lib/kpeg/grammar.rb', line 24
def set_action(act)
@action = act
end
|