Create CLI scaffolding
This commit is contained in:
27
smnp/main.py
27
smnp/main.py
@@ -1,17 +1,40 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from smnp.error.base import SmnpException
|
||||
from smnp.library.loader import loadStandardLibrary
|
||||
from smnp.program.interpreter import Interpreter
|
||||
from smnp.cli.parser import CliParser
|
||||
from smnp.module.mic.lib.detector.noise import NoiseDetector
|
||||
|
||||
def interpretFile(args, file):
|
||||
stdLibraryEnv = loadStandardLibrary() if not args.dry_run else None
|
||||
Interpreter.interpretFile(file, printTokens=args.tokens, printAst=args.ast, execute=not args.dry_run, baseEnvironment=stdLibraryEnv)
|
||||
|
||||
|
||||
def interpretString(args, string):
|
||||
stdLibraryEnv = loadStandardLibrary() if not args.dry_run else None
|
||||
Interpreter.interpretString(string, printTokens=args.tokens, printAst=args.ast, execute=not args.dry_run, baseEnvironment=stdLibraryEnv, source='<cli>')
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
stdLibraryEnv = loadStandardLibrary()
|
||||
Interpreter.interpretFile(sys.argv[1], printTokens=False, printAst=False, execute=True, baseEnvironment=stdLibraryEnv)
|
||||
parser = CliParser()
|
||||
args = parser.parse()
|
||||
|
||||
if args.mic:
|
||||
nd = NoiseDetector()
|
||||
nd.test()
|
||||
|
||||
for code in args.code:
|
||||
interpretString(args, code)
|
||||
|
||||
for file in args.file:
|
||||
interpretFile(args, file)
|
||||
|
||||
except SmnpException as e:
|
||||
print(e.message())
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Program interrupted")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user