# imba$inlineHelpers=1 # imba$v2=0 # var imba = require '../imba' var T = require './token' var util = require './helpers' var lexer = require './lexer' var rewriter = require './rewriter' export var parser = require('../../build/parser')['parser'] var ast = require './nodes' import resolveConfigFile from './imbaconfig' import ImbaParseError from './errors' import {Diagnostic,Compilation} from './compilation' # Instantiate a Lexer for our use here. export var lex = lexer.Lexer.new export var Rewriter = rewriter.Rewriter export var helpers = util var rewriter = Rewriter.new parser:lexer = lex.jisonBridge parser:yy = ast # everything is exported right here now Compilation:prototype:lexer = lex Compilation:prototype:rewriter = rewriter Compilation:prototype:parser = parser # normalize compiler options, resolve imbaconfig.json++ export def resolveConfig o = {} let path = o:sourcePath o:config ||= resolveConfigFile(path,o) or {} return o export def deserialize data, options = {} Compilation.deserialize(data,options) export def tokenize code, options = {} let script = Compilation.new(code,options) return script.tokenize() export def rewrite tokens, o = {} rewriter.rewrite tokens, o export def parse code, o = {} o = resolveConfig(o) var tokens = code isa Array ? code : tokenize(code,o) try return parser.parse(tokens) catch err err:_code = code err:_sourcePath = o:sourcePath if o:sourcePath throw err export def compile code, o = {} let compilation = Compilation.new(code,resolveConfig(o)) return compilation.compile() export def resolve code, o = {} let compilation = Compilation.new(code,resolveConfig(o)) return compilation.compile() export def analyze code, o = {} var meta try var ast = parse(code,o) meta = ast.analyze(o) catch e unless e isa ImbaParseError if e:lexer e = ImbaParseError.new(e, tokens: e:lexer:tokens, pos: e:lexer:pos) else throw e meta = {warnings: [e]} return meta