Commit f7ebebe1 authored by Camil Staps's avatar Camil Staps 🍃

Add default parser state for predefined constructors

parent 33184a87
......@@ -7,6 +7,7 @@ import StdTuple
import Data.Error
from Data.Func import $, seqSt
from Data.Map import fromList, newMap
import Data.Maybe
import System.CommandLine
import System.File
......@@ -30,6 +31,18 @@ defaultOptions =
, output = Nothing
}
defaultParserState :: ParserState
defaultParserState =
{ ps_level = 0
, ps_constructors = fromList
[ ("_predefined._Nil", {index=0,nr_cons=2,nr_args=0,args=[]})
, ("_predefined._Cons", {index=1,nr_cons=2,nr_args=2,args=[TypedVar (NormalVar "x" 0) NoType, TypedVar (NormalVar "xs" 0) NoType]})
]
, ps_functions = newMap
, ps_CAFs = newMap
, ps_genFuns = []
}
Start w
# ([prog:opts],w) = getCommandLine w
# noUsage = Nothing
......@@ -45,7 +58,7 @@ Start 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,Nothing,w)
# (out,_,w) = seqSt (handleFile opts) opts.sapl_files (out,defaultParserState,w)
= w
where
optionDescription :: Option Options
......@@ -76,14 +89,14 @@ error usage s w
# w = setReturnCode 1 w
= w
handleFile :: !Options !FilePath !*(!*File,!Maybe ParserState,!*World) -> *(!*File,!Maybe ParserState,!*World)
handleFile :: !Options !FilePath !*(!*File,!ParserState,!*World) -> *(!*File,!ParserState,!*World)
handleFile opts fp (out,pst,w)
#! (f,w) = readFile fp w
| isError f = (out, pst, error Nothing (fromError f <+ " " +++ fp) w)
#! genResult = generateJS cleanFlavour opts.trampoline (fromOk f) pst
#! genResult = generateJS cleanFlavour opts.trampoline (fromOk f) (Just pst)
| isError genResult = (out, pst, error Nothing (fromError genResult) w)
#! (res,pst) = fromOk genResult
#! (mbError,out) = intoFile res out
#! out = out <<< "\n"
#! w = if (isError mbError) (error Nothing "Error while writing output\n" w) w
= (out,Just pst,w)
= (out,pst,w)
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