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

Update to 0.18 by @brainrape, record parsing, and spaced tuples #19

Merged
merged 11 commits into from
Apr 18, 2017
10 changes: 5 additions & 5 deletions elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.2",
"summary": "A parser for Elm code",
"repository": "https://github.com/Bogdanp/elm-ast.git",
"license": "BSD3",
Expand All @@ -14,9 +14,9 @@
"Ast.Statement"
],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"Bogdanp/elm-combine": "2.2.1 <= v < 3.0.0",
"elm-community/list-extra": "3.1.0 <= v < 4.0.0"
"Bogdanp/elm-combine": "3.1.1 <= v < 4.0.0",
"elm-community/list-extra": "5.0.0 <= v < 6.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0"
},
"elm-version": "0.17.1 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}
14 changes: 4 additions & 10 deletions example/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Ast
import Ast.Expression exposing (..)
import Ast.Statement exposing (..)
import Html exposing (..)
import Html.App as App
import Html
import Html.Events exposing (..)
import Json.Decode as JD

Expand Down Expand Up @@ -45,12 +45,6 @@ withChild title children =
expression : Expression -> Html Msg
expression e =
case e of
Range e1 e2 ->
withChild e
[ expression e1
, expression e2
]

List es ->
withChild e (List.map expression es)

Expand All @@ -77,7 +71,7 @@ statement s =
tree : String -> Html Msg
tree m =
case Ast.parse m of
( Ok statements, _ ) ->
( Ok (_, _, statements)) ->
ul [] (List.map statement statements)

err ->
Expand All @@ -92,9 +86,9 @@ view model =
]


main : Program Never
main : Program Never String Msg
main =
App.beginnerProgram
Html.beginnerProgram
{ model = init
, update = update
, view = view
Expand Down
14 changes: 7 additions & 7 deletions example/elm-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.0.0",
"summary": "an example",
"version": "2.0.0",
"summary": "example for elm-ast",
"repository": "https://github.com/Bogdanp/elm-ast.git",
"license": "BSD3",
"source-directories": [
Expand All @@ -9,10 +9,10 @@
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0",
"Bogdanp/elm-combine": "2.1.0 <= v < 3.0.0",
"elm-community/list-extra": "3.1.0 <= v < 4.0.0"
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"Bogdanp/elm-combine": "3.1.0 <= v < 4.0.0",
"elm-community/list-extra": "5.0.0 <= v < 6.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}
19 changes: 9 additions & 10 deletions src/Ast.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,39 @@ module Ast exposing

-}

import Combine exposing (Context, end)
import Combine.Infix exposing ((<*))
import Combine exposing (end, (<*))

import Ast.BinOp exposing (OpTable, operators)
import Ast.Expression exposing (Expression, expression)
import Ast.Statement exposing (Statement, statement, statements, opTable)


{-| Parse an Elm expression. -}
parseExpression : OpTable -> String -> (Result (List String) Expression, Context)
parseExpression : OpTable -> String -> Result (Combine.ParseErr ()) (Combine.ParseOk () Expression)
parseExpression ops = Combine.parse (expression ops <* end)


{-| Parse an Elm statement. -}
parseStatement : OpTable -> String -> (Result (List String) Statement, Context)
parseStatement : OpTable -> String -> Result (Combine.ParseErr ()) (Combine.ParseOk () Statement)
parseStatement ops = Combine.parse (statement ops <* end)


{-| Parse an OpTable from a module. -}
parseOpTable : OpTable -> String -> (Result (List String) OpTable, Context)
parseOpTable : OpTable -> String -> Result (Combine.ParseErr ()) (Combine.ParseOk () OpTable)
parseOpTable ops = Combine.parse (opTable ops)


{-| Parse an Elm module. -}
parseModule : OpTable -> String -> (Result (List String) (List Statement), Context)
parseModule : OpTable -> String -> Result (Combine.ParseErr ()) (Combine.ParseOk () (List Statement))
parseModule ops = Combine.parse (statements ops)


{-| Parse an Elm module, scanning for infix declarations first. -}
parse : String -> (Result (List String) (List Statement), Context)
parse : String -> Result (Combine.ParseErr ()) (Combine.ParseOk () (List Statement))
parse input =
case parseOpTable operators input of
(Ok ops, _) ->
(Ok (state, stream, ops)) ->
parseModule ops input

(Err ms, cx) ->
(Err ms, cx)
(Err e) ->
(Err e)
Loading