/usr/share/pyshared/terml/parser.py is in python-parsley 1.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | import string
from ometa.grammar import loadGrammar
from ometa.runtime import character, EOFError
import terml
from terml.nodes import Tag, Term, termMaker
## Functions called from grammar actions
def concat(*bits):
return ''.join(map(str, bits))
Character = termMaker.Character
def makeFloat(sign, ds, tail):
return float((sign or '') + ds + tail)
def signedInt(sign, x, base=10):
return int(str((sign or '')+x), base)
def join(x):
return ''.join(x)
def makeHex(sign, hs):
return int((sign or '') + ''.join(hs), 16)
def makeOctal(sign, ds):
return int((sign or '') + '0'+''.join(ds), 8)
def isDigit(x):
return x in string.digits
def isOctDigit(x):
return x in string.octdigits
def isHexDigit(x):
return x in string.hexdigits
def contains(container, value):
return value in container
def cons(first, rest):
return [first] + rest
def Character(char):
return character(char)
def makeTag(nameSegs):
return Tag('::'.join(nameSegs))
def prefixedTag(tagnameSegs):
return makeTag([''] + tagnameSegs)
def tagString(string):
return '"' + string + '"'
def numberType(n):
if isinstance(n, float):
return ".float64."
elif isinstance(n, (long, int)):
return ".int."
raise ValueError("wtf")
def leafInternal(tag, data, span=None):
return Term(tag, data, None, None)
def makeTerm(t, args=None, span=None):
if isinstance(t, Term):
if t.data is not None:
if not args:
return t
else:
raise ValueError("Literal terms can't have arguments")
return Term(t.asFunctor(), None, args and tuple(args), span)
def Tuple(args, span=None):
return Term(Tag(".tuple."), None, tuple(args), span)
def Bag(args, span=None):
return Term(Tag(".bag."), None, tuple(args), span)
def LabelledBag(f, arg, span=None):
return Term(f.asFunctor(), None, (arg,), span)
def Attr(k, v, span=None):
return Term(Tag(".attr."), None, (k, v), span)
TermLParser = loadGrammar(terml, "terml", globals())
def parseTerm(termString):
"""
Build a TermL term tree from a string.
"""
p = TermLParser(termString)
result, error = p.apply("term")
try:
p.input.head()
except EOFError:
pass
else:
raise error
return result
|