Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/interpreter/test_lexer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from truck.interpreter import Lexer


class TestLexer(TestCase):
def test_ident(self):
self._check("ident", [("Ident", "ident"), "Eof"])
Expand Down Expand Up @@ -35,7 +36,8 @@ def _check(self, s, r):
ts = self._get_tokens(s)
self.assertEqual(ts, r)

def _get_tokens(self, s):
@staticmethod
def _get_tokens(s):
l = Lexer(s)
ts = []
while True:
Expand Down
1 change: 1 addition & 0 deletions test/interpreter/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from truck.interpreter import *
from truck.interpreter.ast import *


class TestParser(TestCase):
def test_if(self):
p = Parser(Lexer("""
Expand Down
1 change: 1 addition & 0 deletions test/truck/test_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from truck import truck


class TestClass(TestCase):
def test_normal(self):
res = truck.execute("""
Expand Down
1 change: 1 addition & 0 deletions test/truck/test_function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from truck import truck


class TestFunction(TestCase):
def test_normal(self):
res = truck.execute("""
Expand Down
3 changes: 1 addition & 2 deletions truck/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

if __name__ == "__main__":
args = sys.argv[1:]
if args == []:
if not args:
run_prompt()
else:
run_file(args[0])
pass
1 change: 1 addition & 0 deletions truck/interpreter/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from codecs import decode


class Lexer:
def __init__(self, string):
self.string = string
Expand Down
4 changes: 2 additions & 2 deletions truck/interpreter/parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .ast import *


class Parser:
def __init__(self, lexer):
self.lexer = lexer

def parse(self):
root = self._program()
return root
return self._program()

def _program(self):
# program -> (stmt)
Expand Down
1 change: 1 addition & 0 deletions truck/truck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
__about__ ="""Truck {version}
""".format(version=__version__)


def execute(string, env=None):
if env is None:
env = Environ()
Expand Down