Fix parser for personal recipes: newlines, ranges, &, markdown-style headings
Three categories of fixes:
1. Multi-line steps: removed \n from pText exclusion list so newlines
within a step are consumed as regular text
2. Range timers (e.g. ~{14-18%minutes}): handle hyphen-separated
ranges in parseSimpleRational by taking the lower value
3. & in ingredient names: added & to pSingleNameChar and
pMultiNameChar char sets
4. Markdown-style # headings: added pAnyChar fallback so # followed
by invalid cookware name falls through to text consumption
5. Note detection: tightened > check to require > (with space)
or > followed by non->, preventing >> metadata from being
treated as notes
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import System.Directory (listDirectory)
|
||||
import System.Environment (getArgs)
|
||||
import System.FilePath (takeExtension, (</>))
|
||||
import qualified Data.Text.IO as TIO
|
||||
import Roux.Parser (parseCookFile)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
let recipeDir = case args of
|
||||
(d : _) -> d
|
||||
[] -> error "Usage: check-recipes <recipe-directory>"
|
||||
entries <- listDirectory recipeDir
|
||||
let cookFiles = filter ((== ".cook") . takeExtension) (map (recipeDir </>) entries)
|
||||
putStrLn $ "Found " ++ show (length cookFiles) ++ " recipes in " ++ recipeDir
|
||||
results <- mapM testParse cookFiles
|
||||
let failures = [(name, err) | (name, Just err) <- results]
|
||||
ok = length results - length failures
|
||||
mapM_ (\(name, err) -> putStrLn $ "\n" ++ name ++ ":\n " ++ err) failures
|
||||
putStrLn $ "\nOK: " ++ show ok ++ " / FAIL: " ++ show (length failures)
|
||||
where
|
||||
testParse fp = do
|
||||
let name = reverse . takeWhile (/= '/') . reverse $ fp
|
||||
content <- TIO.readFile fp
|
||||
case parseCookFile content of
|
||||
Left err -> pure (name, Just err)
|
||||
Right _ -> pure (name, Nothing)
|
||||
Reference in New Issue
Block a user