OILS / mycpp / examples / lexer_main.py View on Github | oilshell.org

47 lines, 26 significant
1#!/usr/bin/env python2
2"""
3lexer_main.py
4"""
5from __future__ import print_function
6
7import os
8import sys
9
10from _devbuild.gen.types_asdl import lex_mode_e
11
12from core import alloc
13from core.pyerror import log
14from frontend import lexer
15from frontend import match
16
17from typing import cast
18
19
20def run_tests():
21 # type: () -> None
22
23 arena = alloc.Arena()
24 line_lexer = lexer.LineLexer('echo hi', arena)
25
26 # Works!
27 tok = line_lexer.Read(lex_mode_e.ShCommand)
28 log("tok.val = '%s'", tok.val)
29 tok = line_lexer.Read(lex_mode_e.ShCommand)
30 log("tok.val = '%s'", tok.val)
31 tok = line_lexer.Read(lex_mode_e.ShCommand)
32 log("tok.val = '%s'", tok.val)
33
34 # TODO: how to print Id_t? With %r or something?
35
36
37def run_benchmarks():
38 # type: () -> None
39 pass
40
41
42if __name__ == '__main__':
43 if os.getenv('BENCHMARK'):
44 log('Benchmarking...')
45 run_benchmarks()
46 else:
47 run_tests()