flatten the parser directory a bit
[lisp-parkour.git] / parser / lisp / init.lua
blobb56ffb31f04afc3e135bf54a53f129c6aa9f3544
1 require'lpeg'
2 local lpeg = lpeg
3 local P, S = lpeg.P, lpeg.S
4 local cwd = (...):match'(.-)[^%.]+$'
5 local l = require(cwd..'_lexer')
7 -- The LPeg patterns for atoms are taken from the scintillua lexer:
8 -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com.
10 local macro_prefix = P('#.') + ',@' + ',.' + ',' + '`' + "'"
12 local opposite = {
13 ["("] = ")",
14 [")"] = "(",
15 ['"'] = '"',
16 ["|"] = "|",
17 [";"] = "\n",
18 ["#|"] = "|#",
21 local number = P('-')^-1 * l.digit^1 * (S('./') * l.digit^1)^-1
22 local word = l.alpha * (l.alnum + '_' + '-')^0
23 local entity = '&' * word
24 local identifier = word
26 return {
27 prefix = macro_prefix,
28 opposite = opposite,
29 atom = function(pfx) return pfx * identifier + number + entity + "..." + "." end,
30 word = number + identifier + "\\" * l.any