/tutorial/backtracking/tiny_parse/perser.e

http://github.com/tybor/Liberty · Specman e · 54 lines · 44 code · 8 blank · 2 comment · 0 complexity · 7b8f73b16f7288173ebcbad6b61dbc17 MD5 · raw file

  1. class PARSER
  2. inherit BACKTRACKING
  3. feature
  4. get_context: PARSER_CONTEXT is
  5. do
  6. Result.make(stack.count,position)
  7. end
  8. restore_context(ctxt: PARSER_CONTEXT) is
  9. do
  10. stack.resize(ctxt.depth)
  11. position := ctxt.position
  12. end
  13. push_mark_begin(what: PARSER_PARSEABLE) is
  14. local
  15. mark: PARSER_MARK
  16. do
  17. mark.make_begin(position,what)
  18. stack.add_last(mark)
  19. end
  20. push_mark_end(what: PARSER_PARSEABLE) is
  21. local
  22. mark: PARSER_MARK
  23. do
  24. mark.make_end(position,what)
  25. stack.add_last(mark)
  26. end
  27. push_and_mark_end(what: PARSER_PARSEABLE) is
  28. local
  29. sequence: PARSER_SEQUENCE_MARK_END
  30. do
  31. sequence := pool_of_mark_end.get_instance
  32. sequence.set_parseable(what)
  33. push_sequence(sequence)
  34. end
  35. goto(what: PARSER_PARSEABLE) is
  36. do
  37. -- TODO bouffer les blancs
  38. -- memoriser what
  39. end
  40. goto_inside(what: PARSER_PARSEABLE) is
  41. do
  42. goto(what)
  43. push_mark_begin(what)
  44. push_and_mark_end(what)
  45. end
  46. end