Last active
January 15, 2019 03:24
-
-
Save bstro/2436e7d3214e4f22544f872a56ad0512 to your computer and use it in GitHub Desktop.
Revisions
-
Brendan Stromberger revised this gist
Jan 15, 2019 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,9 @@ -- If the parser instead reaches a `.`, continue and recursively capture every integer following a `.` -- Tag the resulting Int and List Int with XX. (see Index type below) -- Also, I'm not sure, but I think line 16 needs this type: -- dotDigit : List String -> Parser.Parser (Step (List Int) (List Int)) type Index = XXXXXX (Parser.Parser Int) | XX (Parser.Parser ( Int, List Int )) -
Brendan Stromberger revised this gist
Jan 15, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ -- My strategy is this: I parse the input as an integer. -- If the parser has reached the end of the string, tag the chomped value as XXXXXX (see Index type below) -- If the parser instead reaches a `.`, continue and recursively capture every integer following a `.` -- Tag the resulting Int and List Int with XX. (see Index type below) type Index = XXXXXX (Parser.Parser Int) -
Brendan Stromberger created this gist
Jan 15, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ -- My goal here is to be able to parse a string like "678767". -- However, this same parser needs to be able to handle a string like "18.1.2.4" -- My strategy is this: I parse the input as an integer. -- If the parser has reached the end of the string, tag the chomped value as XXXXXX (see Index type below) -- If the parser instead reaches a `.`, continue and recursively capture every integer following a `.` -- Tag the resulting value with XX. (see Index type below) type Index = XXXXXX (Parser.Parser Int) | XX (Parser.Parser ( Int, List Int )) | Unknown String dotDigit : List String -> Parser.Parser (Step (List String) (List String)) dotDigit nums = let checkNum numsSoFar num = if String.length num > 0 then Loop (num :: numsSoFar) else Done (List.reverse numsSoFar) in succeed (checkNum nums) |. symbol "." |= (getChompedString <| chompWhile Char.isDigit) parseIndex = succeed identity |= Parser.int |. Parser.oneOf [ succeed XXXXXX |. Parser.end , succeed XX |. Parser.andThen (\value -> if value >= 1 && value <= 64 then Parser.loop [] dotDigit |> Parser.map (\digits -> ( value, digits )) else Parser.problem "out of range" ) ]