Fix parsing and rendering issues, all but 3 of aoc2024 work.
This commit is contained in:
@@ -84,7 +84,7 @@ getOps = P $ \ toks com ops col => OK ops toks com ops
|
||||
|
||||
addOp : String -> Int -> Fixity -> Parser Unit
|
||||
addOp nm prec fix = P $ \ toks com ops col =>
|
||||
let parts = split "_" nm in
|
||||
let parts = split nm "_" in
|
||||
case parts of
|
||||
"" :: key :: rule => OK MkUnit toks com (updateMap key (MkOp nm prec fix False rule) ops)
|
||||
key :: rule => OK MkUnit toks com (updateMap key (MkOp nm prec fix True rule) ops)
|
||||
|
||||
@@ -29,6 +29,14 @@ flatten Line = Text " "
|
||||
flatten (Text str) = Text str
|
||||
flatten (Alt x y) = flatten x
|
||||
|
||||
noAlt : Doc -> Doc
|
||||
noAlt Empty = Empty
|
||||
noAlt (Seq x y) = Seq (noAlt x) (noAlt y)
|
||||
noAlt (Nest i x) = noAlt x
|
||||
noAlt Line = Line
|
||||
noAlt (Text str) = Text str
|
||||
noAlt (Alt x y) = noAlt x
|
||||
|
||||
group : Doc -> Doc
|
||||
group x = Alt (flatten x) x
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ writeSource fn = do
|
||||
( "\"use strict\";"
|
||||
:: "const PiType = (h0, h1) => ({ tag: \"PiType\", h0, h1 })"
|
||||
:: Nil)
|
||||
++ map (render 90) docs
|
||||
++ map (render 90 ∘ noAlt) docs
|
||||
(Right _) <- liftIO {M} $ writeFile fn src
|
||||
| Left err => exitFailure (show err)
|
||||
-- (Right _) <- chmodRaw fn 493 | Left err => exitFailure (show err)
|
||||
@@ -150,6 +150,19 @@ baseDir (dirs :< d) (ns :< n) = if d == n
|
||||
else Left "module path doesn't match directory"
|
||||
baseDir Lin _ = Left "module path doesn't match directory"
|
||||
|
||||
showErrors : String -> String -> M Unit
|
||||
showErrors fn src = do
|
||||
top <- get
|
||||
(Nil) <- liftIO {M} $ readIORef top.errors
|
||||
| errors => do
|
||||
ignore $ for errors $ \err =>
|
||||
putStrLn (showError src err)
|
||||
-- if err.file == fn
|
||||
-- then putStrLn (showError src err)
|
||||
-- else putStrLn (showError "" err)
|
||||
exitFailure "Compile failed"
|
||||
pure MkUnit
|
||||
|
||||
|
||||
processFile : String -> M Unit
|
||||
processFile fn = do
|
||||
@@ -180,7 +193,7 @@ processFile fn = do
|
||||
processDecl ("Prim" :: Nil) (PType emptyFC "Int" Nothing)
|
||||
processDecl ("Prim" :: Nil) (PType emptyFC "String" Nothing)
|
||||
processDecl ("Prim" :: Nil) (PType emptyFC "Char" Nothing)
|
||||
let base = "port" -- FIXME
|
||||
let base = "aoc2024" -- FIXME
|
||||
src <- processModule emptyFC base Nil (QN path modName')
|
||||
top <- get
|
||||
-- -- dumpContext top
|
||||
@@ -190,6 +203,7 @@ processFile fn = do
|
||||
-- for_ errors $ \err =>
|
||||
-- putStrLn (showError src err)
|
||||
-- exitFailure "Compile failed"
|
||||
showErrors fn src
|
||||
pure MkUnit
|
||||
|
||||
|
||||
|
||||
@@ -30,5 +30,8 @@ pfunc writeFile uses (fs MkIORes MkUnit) : String → String → IO (Either Stri
|
||||
}`
|
||||
|
||||
-- maybe System.exit or something, like the original putStrLn msg >> exitFailure
|
||||
pfunc exitFailure : ∀ a. String → a := `(_, msg) => { throw new Error(msg) }`
|
||||
pfunc exitFailure : ∀ a. String → a := `(_, msg) => {
|
||||
console.log(msg);
|
||||
process.exit(1);
|
||||
}`
|
||||
|
||||
|
||||
35
scripts/aoc2
Executable file
35
scripts/aoc2
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
mkdir -p tmp
|
||||
echo "Test AoC 2024 solutions"
|
||||
NCC="bun run newt.js"
|
||||
total=0
|
||||
failed=0
|
||||
for fn in aoc2024/Day*.newt; do
|
||||
total=$((total + 1))
|
||||
echo Test $fn
|
||||
bn=$(basename $fn)
|
||||
$NCC $fn -o out.js > tmp/${bn}.compile
|
||||
if [ $? != "0" ]; then
|
||||
echo Compile failed for $fn
|
||||
failed=$((failed + 1))
|
||||
continue
|
||||
fi
|
||||
# if there is a golden file, run the code and compare output
|
||||
if [ -f ${fn}.golden ]; then
|
||||
bun run out.js > tmp/${bn}.out
|
||||
if [ $? != "0" ]; then
|
||||
echo Run failed for $fn
|
||||
failed=$((failed + 1))
|
||||
continue
|
||||
fi
|
||||
if ! diff -q tmp/${bn}.out ${fn}.golden; then
|
||||
echo "Output mismatch for $fn"
|
||||
failed=$((failed + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Total tests: $total"
|
||||
echo "Failed tests: $failed"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user