# Path: prolog/interpreter/parsing.py
# def make_regexes():
# def make_default_operations():
# def make_from_form(form, op, x, y):
# def make_expansion(y, x, allops):
# def eliminate_immediate_left_recursion(symbol, expansions):
# def make_all_rules(standard_rules, operations=None):
# def add_necessary_regexs(regexs, names, operations=None):
#     def terminal_equality(self, symbol, input):
#     def match_symbol(self, i, symbol):
#     def __init__(self, rules, startsymbol):
# def make_basic_rules():
# def make_parser(basic_rules, names, regexs):
# def make_all():
# def make_parser_at_runtime(operations):
# def _dummyfunc(arg, tree, source_string, file_name):
# def parse_file(s, parser=None, callback=_dummyfunc, arg=None, file_name=None):
# def _parse_file(s, parser, callback, arg, file_name):
# def parse_query(s):
# def parse_query_term(s):
# def get_query_and_vars(s):
#     def transform(self, node):
#     def transform_extra(self, extranode, child):
#     def __init__(self):
#     def build(self, s):
#     def build_many(self, trees):
#     def build_query(self, s):
#     def build_fact(self, node):
#     def visit(self, node):
#     def general_nonterminal_visit(self, node):
#     def build_list(self, node):
#     def _build_list(self, node, result):
#     def find_first_interesting(self, node):
#     def general_symbol_visit(self, node):
#     def visit_VAR(self, node):
#     def visit_NUMBER(self, node):
#     def visit_FLOAT(self, node):
#     def visit_STRING(self, node):
#     def visit_complexterm(self, node):
#     def visit_expr(self, node):
#     def visit_listexpr(self, node):
# def unescape(s):
# def get_engine(source, create_files=False, load_system=False, **modules):
# def recognize(runner, i):
# class PrologParseTable(LazyParseTable):
# class PrologPackratParser(PackratParser):
# class OrderTransformer(object):
# class TermBuilder(RPythonVisitor):
# ESCAPES = {
#     "\\a": "\a",
#     "\\b": "\b",
#     "\\f": "\f",
#     "\\n": "\n",
#     "\\r": "\r",
#     "\\t": "\t",
#     "\\v": "\v",
#     "\\\\":  "\\"
# }
# 
# Path: prolog/interpreter/term.py
# class Atom(Callable):
#     TYPE_STANDARD_ORDER = 2
#     __slots__ = ('_name', '_signature')
#     cache = {}
#     _immutable_fields_ = ["_signature"]
#     
#     def __init__(self, name, signature=None):
#         if signature is None:
#             signature = Signature(name, 0)
#         Callable.__init__(self)
#         self._signature = signature
#     
#     def __str__(self):
#         return self.name()
#     
#     def __repr__(self):
#         return "Atom(%r)" % (self.name(),)
#     
#     @staticmethod
#     @jit.elidable
#     def newatom(name, signature=None):
#         if signature is None:
#             signature = Signature.getsignature(name, 0)
#         result = Atom.cache.get(signature, None)
#         if result is not None:
#             return result
#         Atom.cache[signature] = result = Atom(name, signature)
#         return result
#     
#     def eval_arithmetic(self, engine):
#         #XXX beautify that
#         if self.name() == "pi":
#             return Float.pi
#         if self.name() == "e":
#             return Float.e
#         error.throw_type_error("evaluable", self.get_prolog_signature())
#     
#     def arguments(self):
#         return []
#     
#     def argument_at(self, i):
#         raise IndexError
#     
#     def argument_count(self):
#         return 0
#     
#     def name(self):
#         return self._signature.name
#     
#     def signature(self):
#         return self._signature
# 
#     def basic_unify_and_standardize_apart(self, other, heap, env):
#         if not isinstance(other, Atom):
#             return Callable.basic_unify_and_standardize_apart(self, other, heap, env)
#         if not self.signature().eq(other.signature()):
#             raise UnificationFailed


from rpython.translator.interactive import Translation
from rpython.rpython.test.test_llinterp import interpret
from prolog.interpreter import parsing
from prolog.interpreter.term import Atom
from prolog.interpreter.test.tool import *
from prolog.interpreter.conftest import option

if not option.slow:
    py.test.skip("slow tests")

def test_parser():
    def f(x):
        if x:
            s = "a(X, Y, Z)."
        else:
            s = "f(a, X, _, _, X, f(X, 2.455))."
        term = parsing.parse_file(s)

# Path: prolog/interpreter/parsing.py
# def make_regexes():
# def make_default_operations():
# def make_from_form(form, op, x, y):
# def make_expansion(y, x, allops):
# def eliminate_immediate_left_recursion(symbol, expansions):
# def make_all_rules(standard_rules, operations=None):
# def add_necessary_regexs(regexs, names, operations=None):
#     def terminal_equality(self, symbol, input):
#     def match_symbol(self, i, symbol):
#     def __init__(self, rules, startsymbol):
# def make_basic_rules():
# def make_parser(basic_rules, names, regexs):
# def make_all():
# def make_parser_at_runtime(operations):
# def _dummyfunc(arg, tree, source_string, file_name):
# def parse_file(s, parser=None, callback=_dummyfunc, arg=None, file_name=None):
# def _parse_file(s, parser, callback, arg, file_name):
# def parse_query(s):
# def parse_query_term(s):
# def get_query_and_vars(s):
#     def transform(self, node):
#     def transform_extra(self, extranode, child):
#     def __init__(self):
#     def build(self, s):
#     def build_many(self, trees):
#     def build_query(self, s):
#     def build_fact(self, node):
#     def visit(self, node):
#     def general_nonterminal_visit(self, node):
#     def build_list(self, node):
#     def _build_list(self, node, result):
#     def find_first_interesting(self, node):
#     def general_symbol_visit(self, node):
#     def visit_VAR(self, node):
#     def visit_NUMBER(self, node):
#     def visit_FLOAT(self, node):
#     def visit_STRING(self, node):
#     def visit_complexterm(self, node):
#     def visit_expr(self, node):
#     def visit_listexpr(self, node):
# def unescape(s):
# def get_engine(source, create_files=False, load_system=False, **modules):
# def recognize(runner, i):
# class PrologParseTable(LazyParseTable):
# class PrologPackratParser(PackratParser):
# class OrderTransformer(object):
# class TermBuilder(RPythonVisitor):
# ESCAPES = {
#     "\\a": "\a",
#     "\\b": "\b",
#     "\\f": "\f",
#     "\\n": "\n",
#     "\\r": "\r",
#     "\\t": "\t",
#     "\\v": "\v",
#     "\\\\":  "\\"
# }
# 
# Path: prolog/interpreter/term.py
# class Atom(Callable):
#     TYPE_STANDARD_ORDER = 2
#     __slots__ = ('_name', '_signature')
#     cache = {}
#     _immutable_fields_ = ["_signature"]
#     
#     def __init__(self, name, signature=None):
#         if signature is None:
#             signature = Signature(name, 0)
#         Callable.__init__(self)
#         self._signature = signature
#     
#     def __str__(self):
#         return self.name()
#     
#     def __repr__(self):
#         return "Atom(%r)" % (self.name(),)
#     
#     @staticmethod
#     @jit.elidable
#     def newatom(name, signature=None):
#         if signature is None:
#             signature = Signature.getsignature(name, 0)
#         result = Atom.cache.get(signature, None)
#         if result is not None:
#             return result
#         Atom.cache[signature] = result = Atom(name, signature)
#         return result
#     
#     def eval_arithmetic(self, engine):
#         #XXX beautify that
#         if self.name() == "pi":
#             return Float.pi
#         if self.name() == "e":
#             return Float.e
#         error.throw_type_error("evaluable", self.get_prolog_signature())
#     
#     def arguments(self):
#         return []
#     
#     def argument_at(self, i):
#         raise IndexError
#     
#     def argument_count(self):
#         return 0
#     
#     def name(self):
#         return self._signature.name
#     
#     def signature(self):
#         return self._signature
# 
#     def basic_unify_and_standardize_apart(self, other, heap, env):
#         if not isinstance(other, Atom):
#             return Callable.basic_unify_and_standardize_apart(self, other, heap, env)
#         if not self.signature().eq(other.signature()):
#             raise UnificationFailed


# Path: prolog/interpreter/test/dont_test_translate.py
from rpython.translator.interactive import Translation
from rpython.rpython.test.test_llinterp import interpret
from prolog.interpreter import parsing
from prolog.interpreter.term import Atom
from prolog.interpreter.test.tool import *
from prolog.interpreter.conftest import option


if not option.slow:
    py.test.skip("slow tests")

def test_parser():
    def f(x):
        if x:
            s = "a(X, Y, Z)."
        else:
            s = "f(a, X, _, _, X, f(X, 2.455))."
        term = parsing.parse_file(s)

        assert isinstance(term, parsing.Nonterminal)