Commits

Alex Gaynor committed e6d9236

Initial point, most of the boiler plate.

  • Participants

Comments (0)

Files changed (8)

+*.py[co]

File minijs/__init__.py

Empty file added.

File minijs/grammar.txt

Empty file added.

File minijs/objspace.py

+from minijs.parser import Transformer, _parse
+
+
+class ObjectSpace(object):
+    def parse(self, source):
+        return Transformer().visit_main(_parse(source))

File minijs/parser.py

+import os
+
+from pypy.rlib.parsing.ebnfparse import parse_ebnf
+
+
+grammar = os.path.join(os.path.dirname(__file__), "grammar.txt")
+regexs, rules, _ = parse_ebnf(grammar)
+_parse = make_parse_function(regexs, rules, eof=True)
+
+
+class Node(object):
+    _attrs_ = ()
+
+    def __eq__(self, other):
+        return type(self) is type(other) and self.__dict__ == other.__dict__
+
+class Block(Node):
+    def __init__(self, stmts):
+        self.stmt = stmts
+
+class Stmt(Node):
+    def __init__(self, expr):
+        self.expr = expr
+
+class ConstantFloat(Node):
+    def __init__(self, floatval):
+        self.floatval = floatval
+
+
+class Transformer(object):
+    pass

File tests/__init__.py

Empty file added.

File tests/conftest.py

+from minijs.objspace import ObjectSpace
+
+
+def pytest_funcarg__space(request):
+    return ObjectSpace()

File tests/test_parser.py

+from minijs.parser import Block, Stmt, ConstantFloat
+
+
+class TestParser(object):
+    def test_const_float(self, space):
+        assert space.parse("1") == Block([Stmt(ConstantFloat(1))])