Commit Graph

87 Commits (f35f5c96ba79400422a068d4600e11d83936573d)

Author SHA1 Message Date
Alex Manning f35f5c96ba
Support Int/Float operators in guard expressions (#92) 2024-07-19 11:02:06 +07:00
Alex Manning e7f5d6ea39
support attributes without arguments (i.e. `@internal`) (#84) 2024-04-23 10:22:39 +07:00
Michael Davis ed9d717629
Allow 'panic' as a function application
This matches the same syntax as 'todo'.

Closes #82
2024-03-18 17:52:22 +07:00
Michael Davis fa2881904b
Allow boolean negation in guard clauses
This is newly allowed in v0.33.0.
2023-12-06 18:55:15 +07:00
Michael Davis c63c3b82f3
Parse unicode escape sequences in strings
In v0.33.0, strings can use escapes like `\u{200D}` to escape in
arbitrary unicode codepoints.
2023-12-06 14:22:39 +07:00
Michael Davis ae4b58b85f
Allow discarding module imports with underscore
Gleam 0.23.3 allows discarding imported modules with the discard syntax.
This needs a small change in tree-sitter-gleam to accept discard nodes
in the import's 'as' field.
2023-11-07 13:07:02 +07:00
Michael Davis 23d2b89651
Remove support for 'try' from the parser
This was 'soft-removed' in the past by removing the highlights and test
cases but we held off on fully removing the parser support. This
finishes the job so that 'try' is no longer treated as a keyword.
This should fix the integration tests. Previously they would fail
against some code in the stdlib which used 'try' as a regular variable
name.
2023-10-29 12:14:58 +07:00
Michael Davis e566689d6d
Parse unqualified type imports with 'type Typename' (#73) 2023-10-29 11:11:53 +07:00
Michael Davis aa987f8b7a
Allow 'as' keyword in binary pattern match expressions 2023-10-29 12:03:25 +07:00
Michael Davis 32c8f1e32a
Add a test case for record access syntax within guards
This improvement was mentioned in the v0.31.0 release notes. This is
already supported so all I've done is remove the comment about how the
behavior does not yet exist upstream and add a test case.
2023-09-26 11:03:01 +07:00
Michael Davis 892e3c5fef
Allow function bodies to be optional (#68) 2023-09-11 18:14:46 +07:00
Michael Davis 5035109688
Add 'as message' syntax for todo and panic (#64) 2023-08-27 19:10:26 +07:00
Michael Davis a1c34b0286
Make 'external' part of external type definitions optional (#63) 2023-08-27 19:09:14 +07:00
Michael Davis 01cba6b1a1
Parse attribute syntax (#65) 2023-08-27 19:08:32 +07:00
Michael Davis ef45f3b044
Add 'use_assignment' and 'use_assignments' nodes under 'use'
Previously the 'use' node would have many 'identifier' or pattern nodes
and, with the parent commit, types as well. This change should make it
easier to figure out which children nodes of 'use' are associated with
one another.

Co-authored-by: Jonathan Arnett <jonarnett90@gmail.com>
2023-08-27 18:33:10 +07:00
Marcin Koziej ceb48343f7
Add optional type annotations to use assignment 2023-08-27 18:28:54 +07:00
Amaan Qureshi 07da684bad
Remove unnecessary conflict (#66) 2023-08-27 17:40:57 +07:00
Alex Manning afddec2b17 support empty case clauses to prevent parsing error 2023-07-29 21:00:46 +07:00
Jonathan Arnett 4a3bae27c7 Add integer negation 2023-07-29 19:17:09 +07:00
Jonathan Arnett 136eaebe7b Semicolons are no longer whitespace 2023-07-29 19:16:40 +07:00
Jonathan Arnett d06bad63d7 Rename "expression_group" to "block" 2023-07-29 19:16:16 +07:00
Jonathan Arnett cd03a61878 Make "let assert" a statement instead of an expression
This makes me a little uneasy, as the way that the Gleam parser parses
"let assert" is that it first parses "let", then calls
"parse_assignment" which will look to see if an "assert" comes next,
and uses this information to choose the node type.

I think a closer tree-sitter implementation would look like this:

_statement: ($) => choice($._expression, $._assignment, $.use),
...
_assignment: ($) => choice($.let, $.let_assert),
let: ($) => seq("let", $._assignment2),
let_assert: ($) => seq("let", "assert", $._assignment2)
_assignment2: ($) =>
  ...

However this requires an awkward "_assignment2" and isn't
substantially closer to the Gleam parser to warrant the change.

Also we could simply do `optional("assert")`, but that would make
"let" and "let assert" the same node type, which I suspect is an anti-feature.
2023-07-29 19:15:21 +07:00
Michael Davis c29d291424 Reclassify 'let' and 'use' as statements
With the latest changes to the gleam parser, code that uses let/use as
expressions is now rejected. This change reorganizes let and use under
a new '_statement' rule. This restricts let/use from taking other
let/use statements since they only accept expressions.
2023-04-07 10:58:08 +07:00
Michael Davis 9013c64605 Rename _statement to _module_statement
This matches the naming within the compiler. This refactor is necessary
since the child commit will use the _statement rule.
2023-04-07 10:58:08 +07:00
inoas 2914d3b437
add `let assert` alt impl (#50) 2023-03-03 16:24:16 +07:00
inoas d14acab7f2
add `panic` keyword / add contributing section to Readme (#46) 2023-03-03 11:38:22 +07:00
Michael Davis 7bfdc49a7c
Allow patterns in use expressions (#49) 2023-03-02 23:25:47 +07:00
Michael Davis 6a99b9c73b
Parse scientific notation suffix for floats (#44) 2023-02-06 11:21:19 +07:00
Michael Davis 8df06b69b0
Parse 'use' expressions (#42) 2022-11-23 14:03:22 +07:00
Michael Davis e21567343e
Support v0.24 binary concatenation operator (#39) 2022-10-27 23:54:52 +07:00
Jonathan Arnett 81670f48fa
Add support for function constants (#37) 2022-08-22 14:53:32 +07:00
Jonathan Arnett 7bfe989c55
Allow empty function bodies (#36) 2022-08-22 14:18:48 +07:00
Jonathan Arnett ed604993ba
Forbid anonymous function parameter labels (#34)
Corresponds to gleam-lang/gleam#1629
2022-06-20 13:13:52 +07:00
Michael Davis 8bde531227
parse floats with no trailing digits (#31)
floats may have a trailing dot with no trailing digits, like in
the float stdlib module:

    pub fn absolute_value(x: Float) -> Float {
      case x >=. 0. {
        True -> x
        _ -> 0. -. x
      }
    }
2022-06-07 23:55:19 +07:00
Jonathan Arnett aed23b28dd
Differentiate data constructor names from type names (#28) 2022-05-24 14:37:32 +07:00
Jonathan Arnett 17ed183fc8
Fix for comment-in-string bug (#27)
Nodes defined in `extras` can be expected before an node. Thus, `comment` could be expected before `escape_sequence` or `quoted_content`; aka inside of a string. Naturally, this makes no sense.

I tried wrapping `escape_sequence` and `quoted_content` in `token.immediate` to resolve the issue, but it had no effect (maybe is specific to whitespace?). Instead, I found success in largely copying [`tree-sitter-rust`'s solution of using an external scanner for string content](9a6d980afb/src/scanner.c (L27-L40)).
2022-05-23 00:17:07 +07:00
Jonathan Arnett b249843e44
Add support for v0.21.0 (aka add bang negation) (#24) 2022-05-04 14:37:31 +07:00
Michael Davis 5b9171bf0e
parse expressions outside of functions (#20)
* parse top-level expressions

This change allows the parser to return valid nodes for expressions
on the "top-level" of a document.

Here "top-level" is read as "not within a function." This is actually
invalid Gleam code: for example, you cannot write a `case/2` statement
outside of a function body. This is desirable for the tree-sitter
parser, though, because the parser will end up being used in flexible
situations, such as one-off highlights in fenced markdown blocks, e.g.:

    ```gleam
    <<code:int-size(8)-unit(2), reason:utf8>>
    ```

Which is a common usage in an editor, or on GitHub.

* remove test cases for invalid syntax
2022-03-24 16:11:57 +07:00
Michael Davis 11d78be28e
generalize bit string option node (#22)
* generalize bit string option node
* highlight bit-string options as function.builtin
2022-03-11 14:16:12 +07:00
Michael Davis ce6ee5195b
add visibility_modifier and opacity_modifier rules (#18)
closes #17

This refactor brings this grammar more in line with tree-sitter-rust.
A function or type declaration may have a visibility modifier ("pub") and
type declarations may also have an opacity modifier ("opaque"). This ends
up reducing the number of named rules, which cleans up the queries a bit.
2022-02-27 21:49:32 +07:00
Jonathan Arnett cfcbca3f8f
Correct name from "type_constructor" to "data_constructor" (#16) 2022-02-26 12:20:54 +07:00
Jonathan Arnett c4743d7776
Extract parts of a string as separate AST nodes (#13) 2022-02-14 11:35:13 +07:00
Michael Davis 3ffbfeb43a
make locals.scm queries more granular (#8)
* make locals.scm queries more granular

* split out (label) nodes from (identifier)

* run formatter

* use (label) for labeled params nodes

* capture all (label)s as properties
2022-01-15 20:13:55 +07:00
Jonathan Arnett b0a23fe88f Extend binaryExpr to guards as well 2022-01-15 16:56:44 +07:00
Jonathan Arnett 7a9759c44c Update ambiguity source comment 2022-01-15 16:43:48 +07:00
Michael Davis d68eab58cf
use fields for left,operator,right of binary expressions (#9) 2022-01-15 15:56:34 +07:00
Michael Davis 4ef644a352
add CI and tune up git config (#5)
* add CI and 'generate parser' actions workflows

* ignore debug log.html file and wasm files

* mark src/ and bindings/ as generated

* run formatter

* rename CI workflow to 'Test'

* use linguist-vendored rather than linguist-generated

* use raw 'git' commands instead of action
2022-01-15 11:10:49 +07:00
Michael Davis 481ebe0be9
parse implicit discard '..' as '$.list_pattern_tail' (#3) 2022-01-14 01:43:58 +07:00
Jonathan Arnett 01f1c1a361 Rename constructor_pattern to record_pattern 2022-01-06 01:17:38 +07:00
Jonathan Arnett 001b2a7a30 Rename "name" field of pattern_constructor_argument to "label"
for consistency
2022-01-06 01:15:12 +07:00