Skip to content

Commit

Permalink
inline upgradeRes in doParse
Browse files Browse the repository at this point in the history
  • Loading branch information
msmorgan committed Jan 17, 2018
1 parent 410be2c commit c89cd4e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions libs/contrib/Text/Parser/Core.idr
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,16 @@ shorter : (more : List tok) -> .(ys : List tok) ->
shorter more [] = lteRefl
shorter more (x :: xs) = LTESucc (lteSuccLeft (shorter more xs))

upgradeRes : {c : Bool} -> {xs : List tok} ->
outerST ->
ParseResult innerST xs c ty ->
ParseResult outerST xs c (ty, innerST)
upgradeRes state (Failure com msg xs) = Failure com msg xs
upgradeRes state (EmptyRes inner com val xs) = EmptyRes state com (val, inner) xs
upgradeRes state (NonEmptyRes inner com val xs) = NonEmptyRes state com (val, inner) xs

doParse : {c : Bool} ->
(state : st) ->
(commit : Bool) -> (xs : List tok) -> (act : GrammarST st tok c ty) ->
ParseResult st xs c ty
doParse state com xs act with (sizeAccessible xs)
doParse state com xs (Run sub init) | sml = upgradeRes state (doParse init com xs sub | sml)
doParse state com xs (Run sub init) | sml
= case (doParse init com xs sub | sml) of
Failure com' msg xs' => Failure com' msg xs'
EmptyRes inner com' val xs' => EmptyRes state com' (val, inner) xs'
NonEmptyRes inner com' val xs' => NonEmptyRes state com' (val, inner) xs'
doParse state com xs Get | sml = EmptyRes state com state xs
doParse state com xs (Put newState) | sml = EmptyRes newState com () xs
doParse state com xs (Empty val) | sml = EmptyRes state com val xs
Expand Down

0 comments on commit c89cd4e

Please sign in to comment.