From 58ad1feab133705909687523e65747aef90e9950 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Tue, 19 Nov 2019 23:29:19 -0500 Subject: [PATCH] allow reading from stdin --- README.md | 3 ++- src/Language/SystemVerilog/Parser/Lex.x | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f251ae7..410af4c 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ running `stack install`, or copy over the executable manually. sv2v takes in a list of files and prints the converted Verilog to `stdout`. Users may specify `include` search paths, define macros during preprocessing, -and exclude some of the conversions. +and exclude some of the conversions. Specifying `-` as an input file will read +from `stdin`. Below is the current usage printout. This interface is subject to change. diff --git a/src/Language/SystemVerilog/Parser/Lex.x b/src/Language/SystemVerilog/Parser/Lex.x index 2465130..11e2e8e 100644 --- a/src/Language/SystemVerilog/Parser/Lex.x +++ b/src/Language/SystemVerilog/Parser/Lex.x @@ -527,7 +527,10 @@ alexInitUserState = LS [] "" Map.empty [] [] [] -- public-facing lexer entrypoint lexFile :: [String] -> Env -> FilePath -> IO (Either String ([Token], Env)) lexFile includePaths env path = do - str <- readFile path >>= return . normalize + str <- + if path == "-" + then getContents + else readFile path >>= return . normalize let result = runAlex str $ setEnv >> alexMonadScan >> get return $ case result of Left msg -> Left msg