Skip to content

Commit

Permalink
cli, concurrency, syntax: Pretty-print syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Jan 22, 2025
1 parent 0f1b3b8 commit 0762355
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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)))
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 e))
Right (ParsedProgram{ parsedProgCFGs = ok
, parsedProgExterns = externs
, parsedProgForwardDecs = fds
Expand Down

0 comments on commit 0762355

Please sign in to comment.