Method: EBNF::Native#postfix

Defined in:
lib/ebnf/native.rb

#postfix(s) ⇒ Object

parse postfix

>>> postfix("a b c")
(a ' b c')

>>> postfix("a? b c")
((opt, a) ' b c')


229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ebnf/native.rb', line 229

def postfix(s)
  debug("postfix") {"(#{s.inspect})"}
  e, s = depth {primary(s)}
  debug {"=> primary returned #{[e, s].inspect}"}
  return ["", s] if e.to_s.empty?
  if !s.to_s.empty?
    t, ss = depth {terminal(s)}
    debug {"=> #{[t, ss].inspect}"}
    if t.is_a?(Array) && [:opt, :star, :plus].include?(t.first)
      return [[t.first, e], ss]
    end
  end
  [e, s]
end