Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unicode escape decode bug in DoubleQuoteString example. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions examples/DoubleQuoteString.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@ import Parser exposing (..)


main =
Html.text <| Debug.toString <|
run string "\"hello\""
let
input =
"\"Hell\\u{006f}! What's up?\\r\\nThis >\\t< is a tab, that's what.\\r\\n\\u{1f600}\""

result =
run string input

display text =
[ Html.dt [] [ Html.text "Rendered:" ]
, Html.dd [] [ Html.pre [] [ Html.text text ] ]
]
in
Html.dl [] <|
[ Html.dt [] [ Html.text "Input:" ]
, Html.dd [] [ Html.pre [] [ Html.text input ] ]
, Html.dt [] [ Html.text "Parse result:" ]
, Html.dd [] [ Html.pre [] [ Html.text <| Debug.toString result ] ]
]
++ (Result.map display result |> Result.withDefault [])


-- STRINGS
Expand Down Expand Up @@ -67,7 +83,7 @@ codeToChar str =
length = String.length str
code = String.foldl addHex 0 str
in
if 4 <= length && length <= 6 then
if length < 4 || length > 6 then
problem "code point must have between 4 and 6 digits"
else if 0 <= code && code <= 0x10FFFF then
succeed (Char.fromCode code)
Expand Down