raku.peg 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # RAKU is a simple, fun to use and to embed scripting language.
  2. # The syntax resembles TCL somewhat but it's semantics are somewhat lisp like.
  3. STATEMENTS ← ((STATEMENT COMMENT? / COMMENT) EOS)+
  4. ~COMMENT ← "#---" (!("---#").)* "---#" / "#" (!([\r\n]+).)*
  5. STATEMENT ← TERM ( OPERATOR TERM )*
  6. TERM ← CALL / VALUE / BLOCK / PBLOCK / BBLOCK
  7. CALL ← VALUE ARGUMENTS
  8. BLOCK ← "{" EOS? STATEMENTS? "}"
  9. BBLOCK ← "[" EOS? STATEMENTS? "]"
  10. PBLOCK ← "(" EOS? STATEMENT EOS? ")"
  11. ARGUMENTS ← (BLOCK / PBLOCK / BBLOCK / VALUE)+
  12. OPERATOR ← < [-+/*] / "<<" / ">>" / "<-" / "->" / "<=>" / "<=" / ">=" / "<" / ">" /
  13. ".." / "." /
  14. "&&"/ "&" / "||" / "|" / "^^" / "^" / "==" / "=" >
  15. VALUE ← WORD / SYMBOL / STRING / NUMBER
  16. STRING ← SYMBOL / ESCSTR / RAWSTR
  17. # Raw string macro
  18. RAWSM(O,C) ← O < (!(C).)* > C
  19. # Escaped string macro.
  20. ESCSM(O,C) ← O < (!(C)STRCHAR)* > C
  21. SYMBOL ← < ":" WORD >
  22. ESCSTR ← ESCSM("`", "`") / ESCSM('"', '"')
  23. RAWSTR ← RAWSM("'", "'") / RAWSM('«', '»') / RAWSM('‹', '›') / RAWSM('“', '”')
  24. STRESC1 ← "\\" [nrtfv\'\\"\[\]\\]
  25. STRESC2 ← "\\" [0-3] [0-7] [0-7]
  26. STRESC3 ← "\\" [0-7] [0-7]*
  27. STRESC4 ← "\\x" [0-9a-fA-F] [0-9a-fA-F]?
  28. STRESC5 ← "\\u" [0-9a-fA-F]+
  29. STRNOESC ← (!('\\\\').)
  30. STRCHAR ← STRESC1 / STRESC2 / STRESC3 / STRESC4 / STRESC5 / STRNOESC
  31. NUMBER ← DECIMAL / INTEGER
  32. DECIMAL ← < [-+]?[0-9]+[.][0-9]+ >
  33. INTEGER ← < [-+]?[0-9]+ >
  34. ~EOS ← ([ \t]*[\r\n;]+[ \t]*)+
  35. WORD ← < [_a-zA-Z][-_a-zA-Z0-9]* >
  36. WHITESPACE ← < [ \t]* >
  37. %whitespace ← [ \t]*
  38. %word ← [a-zA-Z][-+/*a-zA-Z0-9]*
  39. ---
  40. # Expression parsing option
  41. %expr = STATEMENT # Rule to apply 'precedence climbing method' to
  42. %binop = L =
  43. %binop = L <- ->
  44. %binop = L + - | ^
  45. %binop = L * / & << >>
  46. %binop = L && || ^^
  47. %binop = L == <=> <= >= < >
  48. %binop = L . ..