core: runFirstIO
This commit is contained in:
parent
38c69c0ae3
commit
1658e15487
1 changed files with 16 additions and 4 deletions
|
@ -19,10 +19,9 @@ Combine the parser state at time of error with an error message.
|
||||||
|
|
||||||
```idris
|
```idris
|
||||||
public export
|
public export
|
||||||
record ParseError where
|
data ParseError : Type where
|
||||||
constructor MkParseError
|
MkParseError : (state : ParserInternal Id) -> (message : String) -> ParseError
|
||||||
state : ParserInternal Id
|
BeforeParse : (message : String) -> ParseError
|
||||||
message : String
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- idris
|
<!-- idris
|
||||||
|
@ -33,6 +32,8 @@ Show ParseError where
|
||||||
(line, col) = (show line, show col)
|
(line, col) = (show line, show col)
|
||||||
position = show state.position.index
|
position = show state.position.index
|
||||||
in "Error at line \{line}, column \{col} (\{position}): \{message}"
|
in "Error at line \{line}, column \{col} (\{position}): \{message}"
|
||||||
|
show (BeforeParse message) =
|
||||||
|
"Error before parsing: \{message}"
|
||||||
-->
|
-->
|
||||||
|
|
||||||
## Type Alias
|
## Type Alias
|
||||||
|
@ -95,6 +96,17 @@ rundownFirst f =
|
||||||
runExcept . guardMaybe "No returning parses" . runChoose {f = Maybe} $ f
|
runExcept . guardMaybe "No returning parses" . runChoose {f = Maybe} $ f
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Provide wrappers for `rundownFirst` for evaluating it in various contexts.
|
||||||
|
|
||||||
|
```idris
|
||||||
|
export
|
||||||
|
runFirstIO : (f : Parser a) -> String -> IO (Either ParseError a)
|
||||||
|
runFirstIO f str = do
|
||||||
|
Just state <- newInternalIO str
|
||||||
|
| _ => pure . Left $ BeforeParse "Empty input"
|
||||||
|
runEff (rundownFirst f) [handleParserStateIO state]
|
||||||
|
```
|
||||||
|
|
||||||
## Utility functionality
|
## Utility functionality
|
||||||
|
|
||||||
### Parser combinators
|
### Parser combinators
|
||||||
|
|
Loading…
Add table
Reference in a new issue