Commit Graph

59 Commits (8df06b69b0304b3ca955495f57b6ac13fd275647)

Author SHA1 Message Date
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
Jonathan Arnett f14f89db6f Remove $.var, which is unused 2022-01-06 01:14:14 +07:00
Jonathan Arnett 47ddec1316 Replace field(..., optional(...)) with optional(field( ...)) 2022-01-06 01:13:28 +07:00
Jonathan Arnett d97c67eab6 Support funky syntax, especially trailing commas 2022-01-04 03:42:10 +07:00
Jonathan Arnett 06ca4e630d Finish making params match the tree-sitter-rust style 2022-01-04 03:42:10 +07:00
Jonathan Arnett 8e4aaa8d3b The list of imports can, technically, be empty 2022-01-04 03:42:10 +07:00
Jonathan Arnett 8cdefc6d97 The parser doesn't actually care about newlines... at all 2022-01-04 03:42:10 +07:00
Jonathan Arnett 399ea8eca9 Merged discard_var into discard, var into identifier 2022-01-03 00:26:47 +07:00
Jonathan Arnett 4b90565275 Rework pattern AST nodes a bit 2022-01-02 21:59:34 +07:00
Jonathan Arnett 6a8420e02c Surface discard parameters in AST 2022-01-02 21:57:05 +07:00
Jonathan Arnett d08180396b Refine case structure a tad 2022-01-02 17:00:21 +07:00
Jonathan Arnett e40a645e11 Also parse comments 2022-01-02 16:50:13 +07:00
Jonathan Arnett 12a4daa54c Label function bodies 2022-01-02 15:25:18 +07:00
Jonathan Arnett 0e2c6951fe "labeled" only has two 'l's and y'all never told me 2022-01-02 03:38:05 +07:00
Jonathan Arnett 35cd8b2dfd A great big update
Highlights:
- Give "_upname" the visible name "type_identifier". Name stolen
shamelessly from tree-sitter-rust.
- Remove "record_name" in favor of "type_identifier".
- Remote "function_name" in favor of "identifier".
- Surface names for several nodes, mostly using "type_identifier".
- Remove "remote_" variants of several nodes. Essentially we needed to
give these nodes "names" anyhow, and having the name encapsulate the
local vs remote information proved wildly efficient.
2022-01-02 03:35:30 +07:00
Jonathan Arnett e5b283e41a Add or re-add encapsulating nodes
In a previous commit, I removed several encapsulating nodes such as
"parameters" or "arguments" where they were not absolutely necessary.
While reviewing tree-sitter-rust, I noticed that they always
incorporated these encapsulating nodes. This likely helps with AST-based
code navigation, and so I introduced or re-introduced them here.
2022-01-02 01:56:30 +07:00
Jonathan Arnett d22ce5f6ae Fix unlabeled constant record argument bug 2022-01-01 20:54:54 +07:00
Jonathan Arnett dbf9063de1 "Finish" parsing
This commit primarily introduces the ability to parse custom types and
type aliases. The tests for these constructs are contained in the
subsequent commit, because they were written against the "cleaned up"
AST.
2022-01-01 19:57:20 +07:00
Jonathan Arnett ad88927358 AST "cleanup"
- Combine "type" and "type_constructor" across the board into
"type". These two had represented the same thing for a while, with the
latter simply being a "generic" type that has parameters, but now the
difference is exactly that; the presence of parameters. Also the name
"type_constructor" was needed for inside custom type definitions.
- Remove the "parameter" field for functions that do not have them.
- Correct mistaken usages of "type" when "type_name" was meant.
- Correct mistaken usages of "type_argument" when "type_parameter" was
meant.
2022-01-01 19:57:20 +07:00
Jonathan Arnett 7c1ce5e840 Finished first pass at function parsing 2021-12-31 03:08:48 +07:00
Jonathan Arnett 58ae4730ee '_' isn't an integer and octal, hex, and binary values are 2021-12-29 14:57:06 +07:00
Jonathan Arnett 12ab1ee0f9 Added more function tests and improved case AST 2021-12-29 14:20:18 +07:00
Jonathan Arnett 99e0b3b0ae More function work; got some good tests 2021-12-29 02:47:33 +07:00
Jonathan Arnett 2bb02b1278 Started investigation into parsing expressions
Mostly just left comments about how I'll need to revise the Gleam
parser's "expression unit" parsing approach.
2021-12-21 01:00:44 +07:00
Jonathan Arnett bd3a92b58c Pretty good pattern support, I'd say 2021-12-20 00:43:08 +07:00
Jonathan Arnett e691cc44f7 Finally replicate parse_bit_string_segment in tree-sitter
The Gleam parser contains a function called `parse_bit_string_segment`
that contains the logic for how to parse bit_strings for constants,
patterns, and expression units by allowing callers to pass functions to
parse the values and arguments. After much trial-and-error, I managed to
functionally replicate this function within the tree-sitter grammar.
2021-12-19 23:37:07 +07:00
Jonathan Arnett 4f1cee304c WIP: Most of "patterns" 2021-12-19 22:14:44 +07:00
Jonathan Arnett fd348b11c3 Improve generated AST. Fixed a few "empty" bugs. 2021-12-17 02:41:40 +07:00
Jonathan Arnett 71c1660942 Differentiate concrete types from type constructors 2021-12-17 01:53:33 +07:00