Skip to content

Commit

Permalink
Update Lean Char Parsing from Cedar PR#1047 (#384)
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Rozek <[email protected]>
  • Loading branch information
Brandon-Rozek authored Jul 9, 2024
1 parent 36560c2 commit a65f2da
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cedar-lean/DiffTest/Util.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,12 @@ def jsonToInt64 (json : Json) : ParseResult Int64 := do
| .none => .error s!"jsonToInt64: not a signed 64-bit integer {num.mantissa}"
| n => .error s!"jsonToInt64: number has exponent {n}"

def jsonToChar (json : Json) : ParseResult Char := do
let num ← jsonToNum json
match num.exponent with
| 0 =>
let nat := num.mantissa.toNat
if nat.isValidChar
then .ok (Char.ofNat nat)
else .error s!"jsonToChar: cannot convert to character {nat}"
| n => .error s!"jsonToChar: cannot convert to character {n}"
def jsonToChar (json: Json) : ParseResult Char :=
match json.getStr? with
| .ok s => match s.data with
| [c] => .ok c
| _ => .error s!"jsonToChar: Expected single character"
| .error e => .error s!"jsonToChar: {e}\n{json.pretty}"

def getSingleElement (kvs : RBNode String (λ _ => Json)) : String × Json :=
kvs.fold (init := ("",Json.null)) (λ _ k v => (k,v))
Expand Down

0 comments on commit a65f2da

Please sign in to comment.