| 1 |
hspace = (' '|'\t'|'\f'|('#' (~eol anything)*)) |
| 2 |
ws = ('\r' '\n'|'\r' | '\n' | hspace)* |
| 3 |
|
| 4 |
number = ws barenumber |
| 5 |
barenumber = '-'?:sign (('0' ((('x'|'X') hexdigit*:hs -> makeHex(sign, hs)) |
| 6 |
|floatPart(sign '0') |
| 7 |
|octaldigit*:ds -> makeOctal(sign, ds))) |
| 8 |
|decdigits:ds floatPart(sign ds) |
| 9 |
|decdigits:ds -> signedInt(sign, ds)) |
| 10 |
|
| 11 |
|
| 12 |
exponent = <('e' | 'E') ('+' | '-')? decdigits> |
| 13 |
|
| 14 |
|
| 15 |
floatPart :sign :ds = <('.' decdigits exponent?) | exponent>:tail -> makeFloat(sign, ds, tail) |
| 16 |
|
| 17 |
decdigits = digit:d ((:x ?(isDigit(x)) -> x) | '_' -> "")*:ds -> concat(d, join(ds)) |
| 18 |
octaldigit = :x ?(isOctDigit(x)) -> x |
| 19 |
hexdigit = :x ?(isHexDigit(x)) -> x |
| 20 |
|
| 21 |
string = ws '"' (escapedChar | ~('"') anything)*:c '"' -> join(c) |
| 22 |
character = ws '\'' (escapedChar | ~('\''|'\n'|'\r'|'\\') anything):c '\'' -> Character(c) |
| 23 |
escapedUnicode = ('u' <hexdigit hexdigit hexdigit hexdigit>:hs -> unichr(int(hs, 16)) |
| 24 |
|'U' <hexdigit hexdigit hexdigit hexdigit |
| 25 |
hexdigit hexdigit hexdigit hexdigit>:hs -> unichr(int(hs, 16))) |
| 26 |
|
| 27 |
escapedOctal = ( <:a ?(contains("0123", a)) octdigit? octdigit?> |
| 28 |
| <:a ?(contains("4567", a)) octdigit?>):os -> int(os, 8) |
| 29 |
|
| 30 |
escapedChar = '\\' ('n' -> '\n' |
| 31 |
|'r' -> '\r' |
| 32 |
|'t' -> '\t' |
| 33 |
|'b' -> '\b' |
| 34 |
|'f' -> '\f' |
| 35 |
|'"' -> '"' |
| 36 |
|'\'' -> '\'' |
| 37 |
|'?' -> '?' |
| 38 |
|'\\' -> '\\' |
| 39 |
| escapedUnicode |
| 40 |
| escapedOctal |
| 41 |
| eol -> "") |
| 42 |
|
| 43 |
eol = hspace* ('\r' '\n'|'\r' | '\n') |
| 44 |
|
| 45 |
uriBody = <(letterOrDigit|'_'|';'|'/'|'?'|':'|'@'|'&'|'='|'+'|'$'|','|'-'|'.'|'!'|'~'|'*'|'\''|'('|')'|'%'|'\\'|'|'|'#')+> |
| 46 |
|
| 47 |
|
| 48 |
literal = string:x -> leafInternal(Tag(".String."), x) |
| 49 |
| character:x -> leafInternal(Tag(".char."), x) |
| 50 |
| number:x -> leafInternal(Tag(numberType(x)), x) |
| 51 |
|
| 52 |
tag = ( |
| 53 |
segment:seg1 (':' ':' sos)*:segs -> makeTag(cons(seg1, segs)) |
| 54 |
| (':' ':' sos)+:segs -> prefixedTag(segs)) |
| 55 |
|
| 56 |
sos = segment | (string:s -> tagString(s)) |
| 57 |
|
| 58 |
segment = ident | special | uri |
| 59 |
|
| 60 |
ident = segStart:i1 segPart*:ibits -> join(cons(i1, ibits)) |
| 61 |
|
| 62 |
segStart = letter | '_' | '$' |
| 63 |
|
| 64 |
segPart = letterOrDigit | '_' | '.' | '-' | '$' |
| 65 |
|
| 66 |
special = '.':a ident:b -> concat(a, b) |
| 67 |
|
| 68 |
uri = '<' uriBody*:uriChars '>' -> concat(b, uriChars, e) |
| 69 |
|
| 70 |
functor = ws (literal | tag:t -> leafInternal(t, None)) |
| 71 |
baseTerm = functor:f ('(' argList:a ws ')' -> makeTerm(f, a) |
| 72 |
| -> makeTerm(f, None)) |
| 73 |
|
| 74 |
arg = term |
| 75 |
|
| 76 |
argList = ((arg:t (ws ',' arg)*:ts ws ','?) -> cons(t, ts) |
| 77 |
| -> []) |
| 78 |
|
| 79 |
tupleTerm = ws '[' argList:a ws ']' -> Tuple(a) |
| 80 |
|
| 81 |
bagTerm = ws '{' argList:a ws '}' -> Bag(a) |
| 82 |
|
| 83 |
labelledBagTerm = functor:f bagTerm:b -> LabelledBag(f, b) |
| 84 |
|
| 85 |
extraTerm = tupleTerm | labelledBagTerm | bagTerm | baseTerm |
| 86 |
|
| 87 |
attrTerm = extraTerm:k ws ':' extraTerm:v -> Attr(k, v) |
| 88 |
|
| 89 |
term = ws (attrTerm | extraTerm) |