Giter Site home page Giter Site logo

elm-ast's People

Contributors

baransu avatar bogdanp avatar brainrake avatar joonazan avatar majronman avatar shamansir avatar wende avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elm-ast's Issues

Error with multi-element records

It seems like {a = a, b = b} should parse to

Record [("a", (Variable ["a"])), ("b", (Variable ["b"]))]

but it causes the errors

failed to parse: {a = a, b = b} at position 0 with errors: ["expected \"let\"","expected \"case\"","expected \"if\"","expected \"\\\\\"","expected '\\''","expected \"\\\"\\\"\\\"\"","expected \"\\\"\"","expected a float","expected an integer","expected \"_\"","expected a lowercase character","expected an uppercase character","expected \"_\"","expected a
lowercase character","expected an uppercase character","expected \"[\"","expected \"[\"","expected \"}\"","expected \"(\""]

Parser fails for string "\\" and similar values

The following declaration in the parser:

x = "\\"

shows the following error:
(Err (["expected end of input"]),{ input = "x = "\\"\n", position = 0 })

In fact, any number of backslashes followed by a single quote fails to parse. While some of those are legitimate errors (odd numbers of backslashes), others aren't (even numbers of backslashes).

Only allow pair (Maybe FunctionTypeDeclaration, FunctionDeclaration) as Statement ?

Since a FunctionTypeDeclaration without a corresponding FunctionDeclaration is not legal (syntax?) in Elm, would it be useful to change:

type Statement
    = ...
    | FunctionTypeDeclaration Name Type
    | FunctionDeclaration Name (List Expression) Expression
    | ...

to:

type alias FunctionTypeDeclaration = FunctionTypeDeclaration Name Type
type alias FunctionDeclaration = FunctionDeclaration Name (List Expression) Expression
type Statement
    = ...
    | FunctionDefinition 
           (Maybe FunctionTypeDeclaration, FunctionDeclaration)
    | ...

with corresponding tweak to parser rules?

AST printer?

Thanks for writing this! I think this will be very useful for an idea I have for converting GraphQL schemas to Elm code. However one key thing that seems to be missing is an AST printer. Is that planned? If not I can try to come up with something.

AccessFunction is only a syntactic sugar

fn = .field
{- generates 

   AccessFunction [ field ]

   which is only a syntactic sugar for:
-}
fn = \x -> x.field
{- that generates

   Lambda [ Variable [ "x" ] ] (Access (Variable [ "x" ]) [ field ])

   `x` variable used in example has to be different from `field`; 
   may be generated like field ++ "_"
-}

So it seems that additional algebraic element is not needed here. For sake of (model) simplicity it could be removed.

Stricter type (alias) for module parser?

The parser result is a list of statements at the moment. Are there any plans to add a stricter/richer type or type alias to only support valid combinations of statements, like only one module declaration at the top of the file? This is partially related to the question in #7. Or should something like this be done in some elm-ast-extra package?

Parse tuple constructor (,)

Below is an example from List module.

toIndexedList : Array a -> List (Int, a)
toIndexedList array =
  List.map2
    (,)
    (List.range 0 (Native.Array.length array - 1))
    (Native.Array.toList array)

Error with multi-element lists

I could be wrong, but it seems like [a, b] should parse to

List [Variable ["a"], Variable ["b"]]

but it parses to

List ([BinOp (Variable [","]) (Variable ["a"]) (Variable ["b"])])

and it gets more complicated as you add more elements.

Parse error on names starting with `as`

I've found parsing error on some simple code in my fork and tested that this project suffers it too (as long as example page is up to date). This example is extracted from Html module:

node =
  VirtualDom.node

aside =
  node "aside"

Even simpler (seems same case):

node = 0
aside = 7

What's interesting after switching order of functions code parses correctly.

pattern matching on _ failes

fu n =
  case n of
    _ -> 0

Fails to parse.

This works:

fu n =
  case n of
    x -> 0

These also fail:

a _ = 0
b = (\_ -> 0)
c =
  let
    _ = 0
  in
    0

Comments make parsing fail

f =
  let b = 1 --comment
  in b

The parser does not understand this.

This is probably related to #1, because this, too has to do with newlines.

Incorrect result when using nested case expressions

Hi! I noticed an incorrect AST when parsing something along the likes of

foo =
    case pattern of
        A -> 1
        B ->
            case variable of
                C -> 2
                _ -> 3

        _ ->
            4

Which results in an AST like the following

ast =
    Case (Variable [ "pattern" ])
        ([ ( Variable [ "A" ]
           , Integer 1
           )
         , ( Variable [ "B" ]
           , Case
                (Variable [ "variable" ])
                ([ ( Variable [ "C" ]
                   , Integer 2
                   )
                 , ( Variable [ "_" ], Integer 3 )
                 , ( Variable [ "_" ], Integer 4 )
                 ]
                )
           )
         ]
        )

I expect the first case expression to have 3 patterns (A, B and _ ) and the nested one under B to have 2 (C and _ ), but they respectively have 2 ((A, B) and (C, _ and _ ).

Parsing error when pattern matching with a variable named alias

Hi! First of all, thanks for making/picking up the package! โค๏ธ

I noticed that parsing fails when I'm pattern matching, and I named one of the variables alias (which is valid Elm code).

This fails:

fn param =
  case param of
    A alias -> 1
    B -> 2

This works:

fn param =
  case param of
    A aliass -> 1
    B -> 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.