/usr/share/pyshared/terml/quasiterm.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 | from ometa.grammar import loadGrammar
from ometa.runtime import EOFError
import terml
from terml.parser import TermLParser
from terml.qnodes import ValueHole, PatternHole, QTerm, QSome, QFunctor
def interleave(l, *r):
if r:
raise NotImplementedError()
return l
def _or(l, *r):
if r:
raise NotImplementedError()
return l
def some(value, quant):
if quant:
return QSome(value, quant)
else:
return value
def dollarHole(i):
return ValueHole(None, i, False)
def patternHole(i):
return PatternHole(None, i, False)
def taggedHole(t, h):
return h.__class__(t, h.name, h.isFunctorHole)
def leafInternal(tag, data, span=None):
return QFunctor(tag, data, span)
def makeTerm(t, args=None, span=None):
if args is None:
return t
else:
if isinstance(t, QTerm):
if t.data:
if not args:
return t
else:
raise ValueError("Literal terms can't have arguments")
return QTerm(t.asFunctor(), None, args and tuple(args), span)
QTermParser = loadGrammar(terml, "quasiterm", TermLParser.globals, TermLParser)
QTermParser.globals.update(globals())
def quasiterm(termString):
"""
Build a quasiterm from a string.
"""
p = QTermParser(termString)
result, error = p.apply("term")
try:
p.input.head()
except EOFError:
pass
else:
raise error
return result
|