git @ Cat's Eye Technologies Tamsin / 7734de7
I can get this test out of DVCS history if I ever need it again. Cat's Eye Technologies 11 years ago
2 changed file(s) with 1 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
175175
176176 ### performance ###
177177
178 * IR: map program a map from prod name -> [prod AST].
179178 * a second implementation, in C
180179 * a compiler (in Python) *to* C
66 import codecs
77 import sys
88
9 from tamsin.term import Term
109 from tamsin.event import DebugEventListener
11 from tamsin.scanner import (
12 Scanner,
13 TamsinScannerEngine, CharScannerEngine, ProductionScannerEngine
14 )
10 from tamsin.scanner import Scanner, CharScannerEngine
1511 from tamsin.parser import Parser
1612 from tamsin.interpreter import Interpreter
17
18
19
20 def test_peek_is_idempotent():
21 ast = ('PROGRAM', [('PROD', u'main', [], ('USING', ('CALL', u'program', [], None), u'scanner')), ('PROD', u'scanner', [], ('USING', ('CALL', u'scan', [], None), u'char')), ('PROD', u'scan', [], ('AND', ('LITERAL', u'X'), ('OR', ('AND', ('AND', ('AND', ('LITERAL', u'c'), ('LITERAL', u'a')), ('LITERAL', u't')), ('RETURN', Term('cat'))), ('AND', ('AND', ('AND', ('LITERAL', u'd'), ('LITERAL', u'o')), ('LITERAL', u'g')), ('RETURN', Term('dog')))))), ('PROD', u'program', [], ('AND', ('LITERAL', u'cat'), ('LITERAL', u'dog')))])
22 scanner = Scanner('XdogXcat')
23 scanner.push_engine(TamsinScannerEngine())
24 interpreter = Interpreter(ast, scanner)
25
26 prod = interpreter.find_productions('scanner')[0]
27 print repr(prod)
28
29 new_engine = ProductionScannerEngine(interpreter, prod)
30 scanner.push_engine(new_engine)
31
32 print "---INITIAL STATE---"
33 scanner.dump()
34 print repr(interpreter)
35 print
36
37 print "---INITIAL CALL TO peek---"
38 token = scanner.peek()
39 print token
40 scanner.dump()
41 print repr(interpreter)
42 print
43
44 for i in xrange(0, 4):
45 sav_tok = token
46 print "---SUBSEQUENT CALL TO peek---"
47 token = scanner.peek()
48 print token
49 scanner.dump()
50 print repr(interpreter)
51 print
52
53 if sav_tok != token:
54 print "FAILED"
55 break
5613
5714
5815 def main(args):
6017 if args[0] == '--debug':
6118 listeners.append(DebugEventListener())
6219 args = args[1:]
63 if args[0] == 'test':
64 test_peek_is_idempotent()
65 return
6620 if args[0] == 'parse':
6721 with codecs.open(args[1], 'r', 'UTF-8') as f:
6822 contents = f.read()