Commit graph

87 commits

Author SHA1 Message Date
Richard Feldman
90d463873e Drop type_limit 2019-11-25 22:19:33 -05:00
Richard Feldman
0d69d7e90f Add one_of! combinator 2019-11-25 21:32:11 -05:00
Richard Feldman
4926bfbc3a Reorganize fmt and module 2019-11-25 20:42:44 -05:00
Richard Feldman
ed23e23a54 Rename unqualified_ident to lowercase 2019-11-25 16:25:49 -05:00
Richard Feldman
8e0fb89f66 Introduce Expr::ParensAround 2019-11-22 00:21:32 -05:00
Folkert de Vries
4ed1c98881
Merge pull request #9 from rtfeldman/record-patterns
Add record patterns
2019-11-21 13:10:13 +01:00
Folkert
56e0947646 remove inaccurate comment
patterns in a record destructure can now be any arbitrary pattern,
rather than just identifiers.
2019-11-21 13:04:23 +01:00
Richard Feldman
b3f7726a66 Fix defs parsing bug 2019-11-20 17:52:50 -05:00
Folkert
b7a7dd9b37 remove spaces field from LabelOnly 2019-11-20 15:21:29 +01:00
Folkert
d3c14d16d1 parse all records as patterns
This makes the following parse

    # assuming
    Opaque : Opaque Int

    { x: (Opaque y) } = foo

In most cases a pattern of this kind will not be exhaustive, but it
should be syntactically valid.

Couple of things

- conversion of the value (in `key: value`) requires converting from
expr into a pattern, which returns a `Result` which now propagates. A
comment notes though that the cases for which it gives Err should not
parse. so, is the Result useful here?

- AssignedField constructors have a field for spaces, but also a
SpacesAfter constructor. Are they different? it seems like the spaces
field could be removed in favor of using SpacesAfter.
2019-11-20 15:03:58 +01:00
Folkert de Vries
3d584a53b0 Use the RecordField in conversion from assignedField 2019-11-20 14:51:06 +01:00
Folkert
848b067556 allow pattern matching on records
there are a couple of cases here that are interesting:

- assigned fields, like `{ x: y }` should never occur as a pattern.
- what whitespace can occur now that block comments are removed? In elm, record patters have to be on a single line. For instance this gives a parse error:

```elm
type alias Model =
    { count : Int, value : Int }

x model =
    case model of
        { count
          -- bar
        , value
        }
        ->
            2
```

but its equivalent in Roc with the current parser accepts both newlines and
line comments in record patterns, so this is accepted:

```
x model =
    case model with
        { count
          # bar
        , value
        }
        ->
            2
```

That seems fine, but just want to
check that is desired.
2019-11-20 14:51:06 +01:00
Folkert
d7e2555d08 extract AssignedField -> Pattern into function 2019-11-20 14:51:06 +01:00
Richard Feldman
793e951f3b Create either! macro 2019-11-20 07:10:31 -05:00
Richard Feldman
b074035df2 Use attempt! macro 2019-11-20 07:10:31 -05:00
Richard Feldman
1dafc614e7 Use macros for zero_or_more and one_or_more 2019-11-20 07:10:31 -05:00
Richard Feldman
e850703ca9 Use and! over and() 2019-11-20 07:10:31 -05:00
Richard Feldman
cc74c37045 Use loc! macro instead of loc() 2019-11-20 07:10:31 -05:00
Richard Feldman
7f66c4a10b
Merge pull request #8 from rtfeldman/parse-block-string
Parse BlockString
2019-11-17 17:39:13 -05:00
Richard Feldman
b46bd68c24 Add a clarifying comment. 2019-11-16 22:39:37 -05:00
Richard Feldman
942cf8b781 Require space between function argument patterns. 2019-11-16 22:39:31 -05:00
Folkert
b13c9295e3 add BlockStrLiteral pattern in the parsing ast 2019-11-16 14:20:31 +01:00
Folkert
c39e060ddc Parse BlockString
a couple of open questions:

- shouldn't patterns (for formatting) make the distinction between block
and line?
- can the `arena.alloc` be removed? the Vec is already allocated by bumpalo
- for error reporting, is it better to distinguish block and line?
2019-11-15 18:08:01 +01:00
Richard Feldman
3a7401ecf6 Do what clippy says 2019-11-15 01:23:53 +00:00
Richard Feldman
0b9db3b958 Drop obsolete comment 2019-11-13 23:01:29 +01:00
Richard Feldman
cf1306c463 Fix binop parsing bug 2019-11-09 03:30:27 -05:00
Richard Feldman
97d424f99b Unary ops and case canonicalization compile! 2019-11-08 00:07:32 -05:00
Richard Feldman
7ab7fdb88c Add unary operators 2019-11-04 21:25:55 -05:00
Richard Feldman
7e910532c5 Fix parsing for case-expresison number literals 2019-10-30 20:00:35 +01:00
Richard Feldman
67548a8922 Fix parsing defs
This may break annotation parsing. (I'm not sure; there are no annotation
parsing tests yet.) Something fishy is happening with the one_of2 in def().

If I remove the one_of2, then defs parse correctly. If I reverse the
order of one_of2's arguments, they also pass. This suggests the first
argument to one_of2 (the "parse type alias or custom type") logic was
passing...but on further investigation, it appears that is actually
failing. (Meaning it shouldn't affect one_of2!)

Needs further investigation when I get back to annotations, but for now,
this fixes the problem and leaves the code in a reasonable place.
2019-10-30 02:36:50 -04:00
Richard Feldman
6528be0ed1 Revert "Attempt to fix defs parsing"
This reverts commit 6156a5b8f9.
2019-10-30 01:24:17 -04:00
Richard Feldman
6156a5b8f9 Attempt to fix defs parsing 2019-10-30 01:24:09 -04:00
Richard Feldman
953dad5177 Use correct min_indent 2019-10-30 00:58:07 -04:00
Richard Feldman
7e10805c77 Drop debug printlns 2019-10-30 00:39:33 -04:00
Richard Feldman
4894293e6b wip 2019-10-29 00:56:39 -04:00
Richard Feldman
705425c8c4 Redo record and type annotation parsing 2019-10-28 23:04:28 -04:00
Richard Feldman
f738d9db80 Revise Def structure 2019-10-26 15:31:39 -04:00
Richard Feldman
0bf44e9649 Parser for module headers 2019-10-23 18:38:38 -04:00
Richard Feldman
eeb2bb376c Code gen ints and floats 2019-10-21 20:12:37 -04:00
Richard Feldman
e949188319 wip 2019-10-21 08:09:50 -04:00
Richard Feldman
ae301f3c86 Start merging constraint gen into canonicalization 2019-10-16 19:23:34 -04:00
Richard Feldman
59bdb21ea2 First pass at parsing case. 2019-10-14 19:43:03 -04:00
Richard Feldman
ebaed27193 Parse if and args w/ idents, format w/ parens 2019-10-04 11:50:19 +03:00
Richard Feldman
2ced7ee5d8 flesh out operators 2019-10-04 11:15:04 +03:00
Richard Feldman
f3456325fa Redo AST for if and case 2019-10-04 09:31:36 +03:00
Richard Feldman
899ecdcaf6 Drop superfluous comments 2019-10-03 21:57:27 +03:00
Richard Feldman
ff48718305 Finish expr_to_pattern 2019-10-03 21:52:45 +03:00
Richard Feldman
f4f83d70ee Fix parenthetical defs 2019-10-03 21:00:38 +03:00
Richard Feldman
2c6975e908 Fix parenthetical expr ordering 2019-10-02 21:06:19 +03:00
Richard Feldman
4d7b40d430 Support variant patterns 2019-10-02 21:06:12 +03:00