restructure + syntactic sugar implementation
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
import py
|
||||
|
||||
from simpleparser import parse
|
||||
from objmodel import W_NormalObject, W_Integer
|
||||
from objmodel import W_Integer
|
||||
from interpreter import Interpreter
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
import py
|
||||
|
||||
from simpleparser import parse
|
||||
from objmodel import W_NormalObject, W_Integer
|
||||
from interpreter import Interpreter
|
||||
|
||||
|
||||
|
||||
13
mytest/test_sugar_lex.py
Normal file
13
mytest/test_sugar_lex.py
Normal file
@ -0,0 +1,13 @@
|
||||
from rply import Token
|
||||
from simplelexer import lex
|
||||
|
||||
|
||||
def test_lexing():
|
||||
token = lex("+ - * / ++ %")
|
||||
|
||||
assert Token("Plus", "+") == token[0]
|
||||
assert Token("Minus", "-") == token[1]
|
||||
assert Token("Multiply", "*") == token[2]
|
||||
assert Token("Divide", "/") == token[3]
|
||||
assert Token("Increment", "++") == token[4]
|
||||
assert Token("Modulo", "%") == token[5]
|
||||
14
mytest/test_sugar_parse.py
Normal file
14
mytest/test_sugar_parse.py
Normal file
@ -0,0 +1,14 @@
|
||||
from simpleparser import parse
|
||||
|
||||
|
||||
def test_parsing():
|
||||
assert parse("1 + 2") == parse("1 $int_add(2)")
|
||||
assert parse("1 + 2 + 3") == parse("1 $int_add(2) $int_add(3)")
|
||||
assert parse("1 + 2 * 3") == parse("1 $int_add(2 $int_mul(3))")
|
||||
assert parse("1 - 2 - 3") == parse("1 $int_sub(2) $int_sub(3)")
|
||||
assert parse("1 + 2 % 3 / 4 - 5 * 6 + 7++") \
|
||||
== parse("1 $int_add(2 $int_mod(3) $int_div(4)) $int_sub(5 $int_mul(6)) $int_add(7 $int_inc)")
|
||||
|
||||
|
||||
def test_parsing_parenthesis():
|
||||
pass
|
||||
Binary file not shown.
Reference in New Issue
Block a user