Require that the parser parses the whole string.

This commit is contained in:
Danila Fedorin 2019-02-03 22:46:46 -08:00
parent d4303606df
commit 025b21c954

View File

@ -4,7 +4,7 @@ import Html.Events exposing (onInput)
import Browser exposing (element) import Browser exposing (element)
import Canvas exposing (Shape) import Canvas exposing (Shape)
import Dict exposing (Dict) import Dict exposing (Dict)
import Parser exposing (Parser, Problem(..), DeadEnd, (|.), (|=), variable, succeed, symbol, int, spaces, map, oneOf, lazy, sequence, Trailing(..), keyword, run, backtrackable) import Parser exposing (Parser, Problem(..), DeadEnd, (|.), (|=), variable, succeed, symbol, int, spaces, map, oneOf, lazy, sequence, Trailing(..), keyword, run, backtrackable, end)
import Color import Color
import Canvas exposing (Point, path, lineTo, circle, shapes, stroke, lineWidth, fill, rect) import Canvas exposing (Point, path, lineTo, circle, shapes, stroke, lineWidth, fill, rect)
import Set import Set
@ -357,9 +357,9 @@ init fs =
view : Model -> Html Msg view : Model -> Html Msg
view m = view m =
let let
parseResult = Result.mapError humanParseError (run (parseProg |. end) m.programText)
evalResult = Result.map (\(_, s) -> s) evalResult = Result.map (\(_, s) -> s)
<| Result.andThen (\prg -> evaluateAll prg initialState) <| Result.andThen (\prg -> evaluateAll prg initialState) parseResult
<| Result.mapError humanParseError (run parseProg m.programText)
toRender = Result.withDefault initialState evalResult toRender = Result.withDefault initialState evalResult
error = case evalResult of error = case evalResult of
Err e -> [ p [ classList [ ("centered", True), ("error", True), ("shadow", True) ] ] [ text e ] ] Err e -> [ p [ classList [ ("centered", True), ("error", True), ("shadow", True) ] ] [ text e ] ]