def t_identifier(p): obj = p[0].value try: return HyInteger(obj) except ValueError: pass try: return HyFloat(obj) except ValueError: pass if obj != 'j': try: return HyComplex(obj) except ValueError: pass table = { "true": "True", "false": "False", "nil": "None", "null": "None", } if obj in table: return HySymbol(table[obj]) if obj.startswith(":"): return HyKeyword(obj) if obj.startswith("&"): return HyLambdaListKeyword(obj) def mangle(p): if p.startswith("*") and p.endswith("*") and p not in ("*", "**"): p = p[1:-1].upper() if "-" in p and p != "-": p = p.replace("-", "_") if p.endswith("?") and p != "?": p = "is_%s" % (p[:-1]) return p obj = ".".join([mangle(part) for part in obj.split(".")]) return HySymbol(obj)
def _resolve_atom(obj): """ Resolve a bare atom into one of the following (in order): - Integer - LambdaListKeyword - Float - Complex - Symbol """ try: return HyInteger(obj) except ValueError: pass if obj.startswith("&"): return HyLambdaListKeyword(obj) try: return HyFloat(obj) except ValueError: pass if obj != "j": try: return HyComplex(obj) except ValueError: pass table = { "true": "True", "false": "False", "null": "None", } if obj in table: return HySymbol(table[obj]) if obj.startswith(":"): return HyKeyword(obj) if obj.startswith("*") and obj.endswith("*") and obj not in ("*", "**"): obj = obj[1:-1].upper() if "-" in obj and obj != "-": obj = obj.replace("-", "_") return HySymbol(obj)
def t_identifier(p): obj = p[0].value try: return HyInteger(obj) except ValueError: pass try: return HyFloat(obj) except ValueError: pass if obj != 'j': try: return HyComplex(obj) except ValueError: pass table = { "true": "True", "false": "False", "null": "None", } if obj in table: return HySymbol(table[obj]) if obj.startswith(":"): return HyKeyword(obj) if obj.startswith("&"): return HyLambdaListKeyword(obj) if obj.startswith("*") and obj.endswith("*") and obj not in ("*", "**"): obj = obj[1:-1].upper() if "-" in obj and obj != "-": obj = obj.replace("-", "_") return HySymbol(obj)
def test_lex_lambda_list_keyword(): """ Make sure expressions can produce lambda list keywords """ objs = tokenize("(x &rest xs)") assert objs == [HyExpression([HySymbol("x"), HyLambdaListKeyword("&rest"), HySymbol("xs")])]