parser.y 942 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class Journey::Parser
  2. token SLASH LITERAL SYMBOL LPAREN RPAREN DOT STAR OR
  3. rule
  4. expressions
  5. : expressions expression { result = Cat.new(val.first, val.last) }
  6. | expression { result = val.first }
  7. | or
  8. ;
  9. expression
  10. : terminal
  11. | group
  12. | star
  13. ;
  14. group
  15. : LPAREN expressions RPAREN { result = Group.new(val[1]) }
  16. ;
  17. or
  18. : expressions OR expression { result = Or.new([val.first, val.last]) }
  19. ;
  20. star
  21. : STAR literal { result = Star.new(Symbol.new(val.last.left)) }
  22. ;
  23. terminal
  24. : symbol
  25. | literal
  26. | slash
  27. | dot
  28. ;
  29. slash
  30. : SLASH { result = Slash.new('/') }
  31. ;
  32. symbol
  33. : SYMBOL { result = Symbol.new(val.first) }
  34. ;
  35. literal
  36. : LITERAL { result = Literal.new(val.first) }
  37. dot
  38. : DOT { result = Dot.new(val.first) }
  39. ;
  40. end
  41. ---- header
  42. require 'journey/parser_extras'