Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/python-wasm
Path: blob/main/python/pylang/src/compiler.py
1396 views
1
# vim:fileencoding=utf-8
2
# License: BSD
3
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
# globals: console
5
6
from utils import DefaultsError, string_template
7
from errors import ImportError, SyntaxError
8
from tokenizer import ALL_KEYWORDS, IDENTIFIER_PAT, tokenizer
9
from parse import parse, NATIVE_CLASSES, compile_time_decorators
10
from output.stream import OutputStream
11
from output.codegen import generate_code
12
13
generate_code() # create the print methods on the AST nodes
14
15
# The following allows this module to be used from a pure javascript, require()
16
# based environment like Node.js
17
if jstype(exports) is 'object':
18
exports.DefaultsError = DefaultsError
19
exports.parse = parse
20
exports.compile_time_decorators = compile_time_decorators
21
exports.OutputStream = OutputStream
22
exports.string_template = string_template # noqa:undef
23
# Needed for REPL and linter
24
exports.ALL_KEYWORDS = ALL_KEYWORDS
25
exports.IDENTIFIER_PAT = IDENTIFIER_PAT
26
exports.NATIVE_CLASSES = NATIVE_CLASSES
27
exports.ImportError = ImportError
28
exports.SyntaxError = SyntaxError
29
exports.tokenizer = tokenizer
30
# Magic! Export all the AST_* nodes
31
ast = ρσ_modules['ast_types']
32
for ast_node in ast:
33
if ast_node.substr(0, 4) is 'AST_':
34
exports[ast_node] = ast[ast_node] # noqa:undef
35
36