Class: Treetop::Runtime::SyntaxNode

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/cddl-util.rb

Instance Method Summary collapse

Instance Method Details

#astObject



5
6
7
# File 'lib/parser/cddl-util.rb', line 5

def ast
  fail "undefined_ast #{inspect}"
end

#ast1Object

devhack



8
9
10
# File 'lib/parser/cddl-util.rb', line 8

def ast1                      # devhack
  "#{inspect[10..20]}--#{text_value[0..15]}"
end

#mkgen(name, genparm) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/parser/cddl-util.rb', line 11

def mkgen(name, genparm)
  nm = name.text_value
  if el = genparm.elements
    ["gen", nm, *genparm.ast] # XXX
  else
    ["name", nm]
  end
end

#repwrap(el, val) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/parser/cddl-util.rb', line 44

def repwrap(el, val)
  if el.text_value == ''
    val
  else
    ["rep", *el.ast, val]
  end
end

#tvtoi(el, default) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/parser/cddl-util.rb', line 36

def tvtoi(el, default)
  v = el.text_value
  if v == ''
    default
  else
    v.to_i
  end
end

#wrapop(op, first, rest) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/parser/cddl-util.rb', line 19

def wrapop(op, first, rest)
  a = first.ast
  b = rest.map(&:ast)
  if b.size != 0
    [op, a, *b]
  else
    a
  end
end

#wrapop0(op, all) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/parser/cddl-util.rb', line 28

def wrapop0(op, all)
  a = all.map(&:ast)
  if a.size == 1
    a[0]
  else
    [op, *a]
  end
end