Skip to content

Commit

Permalink
[WIP] Improve parse error (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcl authored Oct 9, 2024
1 parent 038c38c commit cf77ce5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions SHerLOC/Parsing/Operations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ def parseOpCode : PState OpCode := do
if let some op := opCode then
parseItem "\""
return op
else throw <| (← error "op code")
else throw (← errorSimple (String.join ["Unknown op code: '", opCodeString, "'"]))

mutual

partial def parseInputFunc : PState InputFunc := do
parseItem "{"
let mut funcInputs : List FuncInput := []
if ← is "^" then
discard <| parseUnusedId
discard parseUnusedId
funcInputs ← parseInputFuncInputs
parseItem ":"
let body ← parseInputFuncBody
Expand Down
7 changes: 6 additions & 1 deletion SHerLOC/Parsing/Parser.lean
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ structure ParsingState where

abbrev PState (T : Type) := StateT ParsingState (Except (String × List Trace × List Derivation)) T

def error (msg : String) : PState (String × (List Trace) × (List Derivation) ):= do
def error (msg : String) : PState (String × (List Trace) × (List Derivation)) := do
let st ← get
let mut token := ""
let mut started := false
Expand All @@ -62,6 +62,11 @@ def error (msg : String) : PState (String × (List Trace) × (List Derivation) )
let errorMsg := s!"Parsing error line {st.lineNumber}, column {st.columnNumber} : expected {msg} but found {token}"
return (errorMsg, st.trace, st.derivations)

def errorSimple (msg : String) : PState (String × (List Trace) × (List Derivation)) := do
let st ← get
let errorMsg := s!"Parsing error line {st.lineNumber}, column {st.columnNumber} : {msg}"
return (errorMsg, st.trace, st.derivations)

def report (msg : String) : PState Unit := do
let st ← get
let msg := s!"line {st.lineNumber}, column {st.columnNumber}: {msg}\n"
Expand Down

0 comments on commit cf77ce5

Please sign in to comment.