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 ...@@ -7,6 +7,7 @@ import StdTuple
import Data.Error import Data.Error
from Data.Func import $, seqSt from Data.Func import $, seqSt
from Data.Map import fromList, newMap
import Data.Maybe import Data.Maybe
import System.CommandLine import System.CommandLine
import System.File import System.File
...@@ -30,6 +31,18 @@ defaultOptions = ...@@ -30,6 +31,18 @@ defaultOptions =
, output = Nothing , 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 Start w
# ([prog:opts],w) = getCommandLine w # ([prog:opts],w) = getCommandLine w
# noUsage = Nothing # noUsage = Nothing
...@@ -45,7 +58,7 @@ Start w ...@@ -45,7 +58,7 @@ Start w
# (ok,out,w) = case opts.output of # (ok,out,w) = case opts.output of
Nothing -> let (f,w`) = stdio w in (True,f,w`) Nothing -> let (f,w`) = stdio w in (True,f,w`)
Just o -> fopen o FWriteText 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 = w
where where
optionDescription :: Option Options optionDescription :: Option Options
...@@ -76,14 +89,14 @@ error usage s w ...@@ -76,14 +89,14 @@ error usage s w
# w = setReturnCode 1 w # w = setReturnCode 1 w
= 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) handleFile opts fp (out,pst,w)
#! (f,w) = readFile fp w #! (f,w) = readFile fp w
| isError f = (out, pst, error Nothing (fromError f <+ " " +++ 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) | isError genResult = (out, pst, error Nothing (fromError genResult) w)
#! (res,pst) = fromOk genResult #! (res,pst) = fromOk genResult
#! (mbError,out) = intoFile res out #! (mbError,out) = intoFile res out
#! out = out <<< "\n" #! out = out <<< "\n"
#! w = if (isError mbError) (error Nothing "Error while writing output\n" w) w #! 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