Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Pretty-print syntax errors #1275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crucible-cli/src/Lang/Crucible/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Data.Map (Map)
import Data.Text (Text)
import Data.String (IsString(..))
import qualified Data.Text.IO as T
import qualified Prettyprinter as PP
import qualified Prettyprinter.Render.Text as PP
import System.IO
import System.Exit
import Text.Megaparsec as MP
Expand All @@ -43,7 +45,6 @@ import Lang.Crucible.CFG.SSAConversion

import Lang.Crucible.Syntax.Atoms
import Lang.Crucible.Syntax.Concrete
import Lang.Crucible.Syntax.ExprParse (printSyntaxError)
import Lang.Crucible.Syntax.Prog (doParseCheck, assertNoExterns, assertNoForwardDecs)
import Lang.Crucible.Syntax.SExpr

Expand Down Expand Up @@ -139,8 +140,8 @@ simulateProgramWithExtension mkExt fn theInput outh profh opts hooks =
let hdls = [ (SomeHandle h, p) | (FnBinding h _,p) <- ovrs ]
parseResult <- top ng ha hdls $ prog v
case parseResult of
Left (SyntaxParseError e) -> T.hPutStrLn outh $ printSyntaxError e
Left err -> hPutStrLn outh $ show err
Left e ->
T.hPutStrLn outh (PP.renderStrict (PP.layoutPretty PP.defaultLayoutOptions (PP.pretty e)))
langston-barrett marked this conversation as resolved.
Show resolved Hide resolved
Right (ParsedProgram{ parsedProgCFGs = cs
, parsedProgExterns = externs
, parsedProgForwardDecs = fds
Expand Down
1 change: 1 addition & 0 deletions crucible-concurrency/crucible-concurrency.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ library
, megaparsec
, mtl
, parameterized-utils
, prettyprinter
, simple-get-opt < 0.5
, text
, vector
Expand Down
4 changes: 2 additions & 2 deletions crucible-concurrency/src/Cruces/CrucesMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.List (find)
import qualified Data.Map as Map
import Data.Text (pack)
import Data.String (IsString(..))
import qualified Prettyprinter as PP
import System.Exit
import Text.Megaparsec as MP

Expand Down Expand Up @@ -138,8 +139,7 @@ run (cruxOpts, opts) =
let ?parserHooks = defaultParserHooks
parseResult <- top nonceGen ha builtins $ prog v
case parseResult of
Left (SyntaxParseError e) -> error $ show $ printSyntaxError e
Left err -> error $ show err
Left err -> error (show (PP.pretty err))
Right (ParsedProgram
{ parsedProgGlobals = gs
, parsedProgExterns = externs
Expand Down
5 changes: 2 additions & 3 deletions crucible-syntax/src/Lang/Crucible/Syntax/Prog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import qualified Data.Map as Map
import Data.Map (Map)
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Prettyprinter as PP
import System.IO
import System.Exit
import Text.Megaparsec as MP
Expand All @@ -31,7 +32,6 @@ import Lang.Crucible.CFG.SSAConversion

import Lang.Crucible.Syntax.Concrete
import Lang.Crucible.Syntax.SExpr
import Lang.Crucible.Syntax.ExprParse (printSyntaxError)
import Lang.Crucible.Syntax.Atoms

import Lang.Crucible.Analysis.Postdom
Expand Down Expand Up @@ -72,8 +72,7 @@ doParseCheck fn theInput pprint outh =
\e -> T.hPutStrLn outh (printExpr e) >> hPutStrLn outh ""
cs <- top ng ha [] $ prog v
case cs of
Left (SyntaxParseError e) -> T.hPutStrLn outh $ printSyntaxError e
Left err -> hPutStrLn outh $ show err
Left err -> hPutStrLn outh (show (PP.pretty err))
Right (ParsedProgram{ parsedProgCFGs = ok
, parsedProgExterns = externs
, parsedProgForwardDecs = fds
Expand Down
Loading