Commit 27c75fa4 authored by Camil Staps's avatar Camil Staps 🍃

Split up parsing and code generation to allow for cyclic dependencies in constructors

parent ef7e977e
......@@ -7,7 +7,7 @@ import StdString
import StdTuple
import Data.Error
from Data.Func import $, seqSt
from Data.Func import $, mapSt, seqSt
from Data.Map import fromList, newMap
import Data.Maybe
import System.CommandLine
......@@ -60,10 +60,13 @@ Start w
| isNothing opts.output = error usage "No output file given" w
| isNothing opts.output && isJust opts.beautify = error Nothing "Cannot use beautifier when outputting to stdout" w
# (files,(pst,w)) = mapSt (parseFile opts) opts.sapl_files (defaultParserState,w)
| any isNothing files = error Nothing "Parsing failed" w
# (ok,out,w) = case opts.output of
Nothing -> let (f,w`) = stdio w in (True,f,w`)
Just o -> fopen o FWriteText w
# (out,_,w) = seqSt (handleFile opts) opts.sapl_files (out,defaultParserState,w)
# (out,_,w) = seqSt (genCode opts) [f \\ Just f <- files] (out,pst,w)
# (_,w) = fclose out w
# w = case opts.beautify of
......@@ -110,11 +113,19 @@ error usage s w
# w = setReturnCode 1 w
= w
handleFile :: !Options !FilePath !*(!*File,!ParserState,!*World) -> *(!*File,!ParserState,!*World)
handleFile opts fp (out,pst,w)
parseFile :: !Options !FilePath !*(!ParserState,!*World) -> *(!Maybe String, !*(!ParserState,!*World))
parseFile opts fp (pst,w)
#! (f,w) = readFile fp w
| isError f = (out, pst, error Nothing (fromError f <+ " " +++ fp) w)
#! genResult = generateJS cleanFlavour opts.trampoline (fromOk f) (Just pst)
| isError f = (Nothing, (pst, error Nothing (fromError f <+ " " +++ fp) w))
#! f = fromOk f
#! parseRes = parse (tokensWithPositions f)
| isError parseRes = (Nothing, (pst, error Nothing (fp +++ ": " <+ fromError parseRes) w))
#! (_,pst`) = fromOk parseRes
= (Just f, (mergeParserStates pst` (Just pst),w))
genCode :: !Options !String !*(!*File,!ParserState,!*World) -> *(!*File,!ParserState,!*World)
genCode opts sapl (out,pst,w)
#! genResult = generateJS cleanFlavour opts.trampoline sapl (Just pst)
| isError genResult = (out, pst, error Nothing (fromError genResult) w)
#! (res,pst) = fromOk genResult
#! (mbError,out) = intoFile res out
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment