Exemple #1
0
class ParserTests(unittest.TestCase):
    def setUp(self):
        self.parser = Parser()

    def parse(self, s):
        return self.parser.parse(SingleLineFeeder(s))

    def check(self, expr1, expr2):
        if isinstance(expr1, str):
            expr1 = self.parse(expr1)
        if isinstance(expr2, str):
            expr2 = self.parse(expr2)

        if expr1 is None:
            self.assertIsNone(expr2)
        else:
            self.assertEqual(repr(expr1), repr(expr2))
            self.assertEqual(expr1, expr2)

    def scan_error(self, string):
        self.assertRaises(ScanError, self.parse, string)

    def incomplete_error(self, string):
        self.assertRaises(IncompleteSyntaxError, self.parse, string)

    def invalid_error(self, string):
        self.assertRaises(InvalidSyntaxError, self.parse, string)
Exemple #2
0
class ParserTests(unittest.TestCase):
    def setUp(self):
        self.parser = Parser()

    def parse(self, s):
        return self.parser.parse(SingleLineFeeder(s))

    def check(self, expr1, expr2):
        if isinstance(expr1, six.string_types):
            expr1 = self.parse(expr1)
        if isinstance(expr2, six.string_types):
            expr2 = self.parse(expr2)

        if expr1 is None:
            self.assertIsNone(expr2)
        else:
            self.assertEqual(repr(expr1), repr(expr2))
            self.assertEqual(expr1, expr2)

    def scan_error(self, string):
        self.assertRaises(ScanError, self.parse, string)

    def incomplete_error(self, string):
        self.assertRaises(IncompleteSyntaxError, self.parse, string)

    def invalid_error(self, string):
        self.assertRaises(InvalidSyntaxError, self.parse, string)
Exemple #3
0
 def setUp(self):
     self.parser = Parser()
Exemple #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from mathics.core.parser.parser import Parser
from mathics.core.parser.convert import convert
from mathics.core.parser.feed import SingleLineFeeder
from mathics.core.expression import ensure_context

parser = Parser()


def parse(definitions, feeder):
    '''
    Parse input (from the frontend, -e, input files, ToExpression etc).
    Look up symbols according to the Definitions instance supplied.

    Feeder must implement the feed and empty methods, see core/parser/feed.py.
    '''
    ast = parser.parse(feeder)
    if ast is not None:
        return convert(ast, definitions)
    else:
        return None


class SystemDefinitions(object):
    """
    Dummy Definitions object that puts every unqualified symbol in
    System`.
    """
    def lookup_name(self, name):
Exemple #5
0
 def setUp(self):
     self.parser = Parser()