Class: RParsec::BestParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/rparsec/parsers.rb

Constant Summary

Constants inherited from Parser

Parser::MyMonad

Constants included from Functors

Functors::And, Functors::At, Functors::BitAnd, Functors::Call, Functors::Compare, Functors::Dec, Functors::Div, Functors::Eq, Functors::Feed, Functors::Fst, Functors::Ge, Functors::Gt, Functors::Id, Functors::Idn, Functors::Inc, Functors::Le, Functors::Lt, Functors::Match, Functors::Minus, Functors::Mod, Functors::Mul, Functors::Ne, Functors::Neg, Functors::Not, Functors::Or, Functors::Plus, Functors::Power, Functors::Snd, Functors::Succ, Functors::To_a, Functors::To_f, Functors::To_i, Functors::To_s, Functors::To_sym, Functors::Union, Functors::Xor

Instance Attribute Summary

Attributes inherited from Parser

#name

Attributes included from Monad

#this

Instance Method Summary collapse

Methods inherited from Parser

#>>, #atomize, #bindn, #catchp, #delimited, #delimited1, #expect, #followed, #fragment, #infixl, #infixn, #infixr, #lexeme, #lookahead, #many, #many_, #map, #mapn, #nested, #not, #optional, #parse, #peek, #postfix, #prefix, #repeat, #repeat_, #separated, #separated1, #seq, #setName, #some, #some_, #to_s, #token, #|

Methods included from Signature

#def_sig

Methods included from DefHelper

#def_ctor, #def_mutable, #def_readable

Methods included from Monad

#bind, #initMonad, #map, #plus, #seq, #value

Methods included from Functors

#compose, #const, #curry, #flip, make_curry, make_reverse_curry, #nth, #power, #repeat, #reverse_curry, #reverse_uncurry, #uncurry

Instance Method Details

#_parse(ctxt) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/rparsec/parsers.rb', line 219

def _parse ctxt
  best_result, best_ind = nil, -1
  err_ind, err_pos = -1, -1
  ind, result, err = ctxt.index, ctxt.result, ctxt.error
  for p in @alts
    ctxt.reset_error
    ctxt.index, ctxt.result = ind, result
    if p._parse(ctxt)
      err, now_ind = nil, ctxt.index
      if best_ind == -1 || (now_ind != best_ind && @longer == (now_ind > best_ind))
        best_result, best_ind = ctxt.result, now_ind
      end
    elsif best_ind < 0 # no good match found yet.
      if ctxt.error.index > err_pos
        err_ind, err_pos = ctxt.index, ctxt.error.index
      end
      err = Failures.add_error(err, ctxt.error)
    end
  end
  if best_ind >= 0
    ctxt.index = best_ind
    return ctxt.retn(best_result)
  else
    ctxt.error, ctxt.index = err, err_ind
    return false
  end
end