Create CLI scaffolding

This commit is contained in:
Bartłomiej Pluta
2019-09-06 18:26:02 +02:00
parent 3061dae723
commit 83ef3f6888
3 changed files with 48 additions and 2 deletions

View File

@@ -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")