Merge commit '85c0753e8ed98d93bb4a238ca485ef4e1fdce4f5'

pull/315/head
Wilfred Hughes 2022-07-10 22:51:36 +07:00
commit cd73d4954f
30 changed files with 25612 additions and 23316 deletions

@ -1,2 +1,3 @@
src/** linguist-generated
src/scanner.c -linguist-generated
test/** linguist-documentation

@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]
jobs:
bless:
test:
name: Test
runs-on: ubuntu-latest
@ -35,3 +35,33 @@ jobs:
- name: Check formatting
run: npm run check-formatted
integration-test:
name: Integration Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: "14.x"
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install npm dependencies
run: npm ci
- name: Ensure generated parser files are up to date
run: npx tree-sitter generate
- name: Run integration tests
run: ./scripts/integration_test.sh

@ -32,7 +32,7 @@ jobs:
run: npx tree-sitter test
- name: Compile library file
run: cc -shared -fPIC -g -O2 -I src src/parser.c -o tree-sitter-gleam.so
run: cc -shared -fPIC -g -O2 -I src src/parser.c src/scanner.c -o tree-sitter-gleam.so
- name: Create archive
run: |

@ -52,7 +52,7 @@ dependencies = [
[[package]]
name = "tree-sitter-gleam"
version = "0.20.1"
version = "0.22.1"
dependencies = [
"cc",
"tree-sitter",

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-gleam"
description = "gleam grammar for the tree-sitter parsing library"
version = "0.20.1"
version = "0.22.1"
keywords = ["incremental", "parsing", "gleam"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-gleam"

@ -2,6 +2,7 @@ const NEWLINE = /\r?\n/;
module.exports = grammar({
name: "gleam",
externals: ($) => [$.quoted_content],
extras: ($) => [
";",
NEWLINE,
@ -17,6 +18,11 @@ module.exports = grammar({
$._maybe_tuple_expression,
$.remote_type_identifier,
],
[
$._maybe_record_expression,
$._maybe_tuple_expression,
$.remote_constructor_name,
],
[$.case_subjects],
[$.source_file],
],
@ -96,7 +102,7 @@ module.exports = grammar({
...bit_string_rules("constant", "_constant_value", "integer"),
constant_record: ($) =>
seq(
field("name", choice($.type_identifier, $.remote_type_identifier)),
field("name", choice($.constructor_name, $.remote_constructor_name)),
optional(
field("arguments", alias($.constant_record_arguments, $.arguments))
)
@ -293,6 +299,7 @@ module.exports = grammar({
$.case,
$.let,
$.assert,
$.negation,
$.record_update,
$.tuple_access,
$.field_access,
@ -300,7 +307,7 @@ module.exports = grammar({
),
record: ($) =>
seq(
field("name", choice($.type_identifier, $.remote_type_identifier)),
field("name", choice($.constructor_name, $.remote_constructor_name)),
optional(field("arguments", $.arguments))
),
todo: ($) =>
@ -323,12 +330,31 @@ module.exports = grammar({
anonymous_function: ($) =>
seq(
"fn",
field("parameters", $.function_parameters),
field(
"parameters",
alias($.anonymous_function_parameters, $.function_parameters)
),
optional(seq("->", field("return_type", $._type))),
"{",
field("body", alias($._expression_seq, $.function_body)),
"}"
),
anonymous_function_parameters: ($) =>
seq(
"(",
optional(
series_of(
alias($.anonymous_function_parameter, $.function_parameter),
","
)
),
")"
),
anonymous_function_parameter: ($) =>
seq(
choice($._discard_param, $._name_param),
optional($._type_annotation)
),
expression_group: ($) => seq("{", $._expression_seq, "}"),
case: ($) =>
seq(
@ -387,6 +413,7 @@ module.exports = grammar({
seq(field("tuple", $.identifier), ".", field("index", $.integer)),
let: ($) => seq("let", $._assignment),
assert: ($) => seq("assert", $._assignment),
negation: ($) => seq("!", $._expression_unit),
_assignment: ($) =>
seq(
field("pattern", $._pattern),
@ -398,7 +425,7 @@ module.exports = grammar({
seq(
field(
"constructor",
choice($.type_identifier, $.remote_type_identifier)
choice($.constructor_name, $.remote_constructor_name)
),
"(",
"..",
@ -504,7 +531,7 @@ module.exports = grammar({
),
record_pattern: ($) =>
seq(
field("name", choice($.type_identifier, $.remote_type_identifier)),
field("name", choice($.constructor_name, $.remote_constructor_name)),
optional(field("arguments", $.record_pattern_arguments))
),
record_pattern_arguments: ($) =>
@ -559,7 +586,7 @@ module.exports = grammar({
data_constructors: ($) => repeat1($.data_constructor),
data_constructor: ($) =>
seq(
field("name", $.type_identifier),
field("name", $.constructor_name),
optional(field("arguments", $.data_constructor_arguments))
),
data_constructor_arguments: ($) =>
@ -579,11 +606,14 @@ module.exports = grammar({
),
/* Literals */
string: ($) => seq('"', repeat($._string_part), '"'),
_string_part: ($) => choice($.escape_sequence, $.quoted_content),
escape_sequence: ($) => /\\[efnrt\"\\]/,
quoted_content: ($) => /(?:[^\\\"]|\\[^efnrt\"\\])+/,
float: ($) => /-?[0-9_]+\.[0-9_]+/,
string: ($) =>
seq(
'"',
repeat(choice($.escape_sequence, $.quoted_content)),
token.immediate('"')
),
escape_sequence: ($) => token.immediate(/\\[efnrt\"\\]/),
float: ($) => /-?[0-9_]+\.[0-9_]*/,
integer: ($) =>
seq(optional("-"), choice($._hex, $._decimal, $._octal, $._binary)),
_hex: ($) => /0[xX][0-9a-fA-F_]+/,
@ -661,6 +691,13 @@ module.exports = grammar({
type_identifier: ($) => $._upname,
remote_type_identifier: ($) =>
seq(field("module", $.identifier), ".", field("name", $.type_identifier)),
constructor_name: ($) => $._upname,
remote_constructor_name: ($) =>
seq(
field("module", $.identifier),
".",
field("name", $.constructor_name)
),
/* Reused types from the Gleam lexer */
_discard_name: ($) => /_[_0-9a-z]*/,

@ -1,12 +1,12 @@
{
"name": "tree-sitter-gleam",
"version": "0.20.1",
"version": "0.22.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "tree-sitter-gleam",
"version": "0.20.1",
"version": "0.22.1",
"license": "Apache-2.0",
"dependencies": {
"nan": "^2.15.0"

@ -1,6 +1,6 @@
{
"name": "tree-sitter-gleam",
"version": "0.20.1",
"version": "0.22.1",
"description": "A tree-sitter grammar for the Gleam programming language",
"main": "bindings/node",
"scripts": {

@ -12,6 +12,8 @@
(import alias: (identifier) @module)
(remote_type_identifier
module: (identifier) @module)
(remote_constructor_name
module: (identifier) @module)
((field_access
record: (identifier) @module
field: (label) @function)
@ -45,6 +47,9 @@
(remote_type_identifier) @type
(type_identifier) @type
; Data constructors
(constructor_name) @constructor
; Literals
(string) @string
(bit_string_segment_option) @function.builtin
@ -58,6 +63,7 @@
; Operators
(binary_expression
operator: _ @operator)
"!" @operator
; Keywords
[

@ -1,5 +1,5 @@
; Scopes
(function_body) @local.scope
(function) @local.scope
(case_clause) @local.scope

@ -32,9 +32,10 @@
(type_definition
(data_constructors
(data_constructor
name: (type_identifier) @name))) @definition.type
name: (constructor_name) @name))) @definition.constructor
(external_type
(type_name
name: (type_identifier) @name)) @definition.type
(type_identifier) @name @reference.type
(constructor_name) @name @reference.constructor

@ -0,0 +1,24 @@
#! /usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
usage() {
echo "$0"
echo ""
echo "Tests that the parser does not create error nodes"
echo "when tested against real Gleam repos"
echo ""
exit 1
}
if [ $# -ne 0 ]; then
usage
fi
repos="gleam-lang/stdlib gleam-lang/json gleam-lang/http gleam-lang/example-todomvc gleam-lang/bitwise gleam-lang/erlang gleam-lang/otp gleam-lang/cowboy gleam-lang/hackney gleam-lang/httpc gleam-lang/elli gleam-lang/javascript gleam-lang/example-echo-server gleam-lang/plug"
for repo in $repos; do
./scripts/parse_repo.sh $repo
done

@ -0,0 +1,29 @@
#! /usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
usage() {
echo "$0 owner/repository"
echo ""
echo "Runs the parser against Gleam files in a GitHub repository"
echo ""
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
gh_repo="$1"
dir="test/integration/${gh_repo//[\/-]/_}"
if [[ ! -d "$dir" ]]; then
mkdir -p "$(dirname "$dir")"
git clone --depth 1 "https://github.com/$gh_repo.git" "$dir"
fi
echo "Running parser against $gh_repo"
npx tree-sitter parse --quiet --stat "$dir/**/*.gleam"

@ -815,11 +815,11 @@
"members": [
{
"type": "SYMBOL",
"name": "type_identifier"
"name": "constructor_name"
},
{
"type": "SYMBOL",
"name": "remote_type_identifier"
"name": "remote_constructor_name"
}
]
}
@ -2494,6 +2494,10 @@
"type": "SYMBOL",
"name": "assert"
},
{
"type": "SYMBOL",
"name": "negation"
},
{
"type": "SYMBOL",
"name": "record_update"
@ -2523,11 +2527,11 @@
"members": [
{
"type": "SYMBOL",
"name": "type_identifier"
"name": "constructor_name"
},
{
"type": "SYMBOL",
"name": "remote_type_identifier"
"name": "remote_constructor_name"
}
]
}
@ -2952,8 +2956,13 @@
"type": "FIELD",
"name": "parameters",
"content": {
"type": "SYMBOL",
"name": "function_parameters"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "anonymous_function_parameters"
},
"named": true,
"value": "function_parameters"
}
},
{
@ -3004,6 +3013,104 @@
}
]
},
"anonymous_function_parameters": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "anonymous_function_parameter"
},
"named": true,
"value": "function_parameter"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "anonymous_function_parameter"
},
"named": true,
"value": "function_parameter"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"anonymous_function_parameter": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_discard_param"
},
{
"type": "SYMBOL",
"name": "_name_param"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_annotation"
},
{
"type": "BLANK"
}
]
}
]
},
"expression_group": {
"type": "SEQ",
"members": [
@ -3749,6 +3856,19 @@
}
]
},
"negation": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "!"
},
{
"type": "SYMBOL",
"name": "_expression_unit"
}
]
},
"_assignment": {
"type": "SEQ",
"members": [
@ -3797,11 +3917,11 @@
"members": [
{
"type": "SYMBOL",
"name": "type_identifier"
"name": "constructor_name"
},
{
"type": "SYMBOL",
"name": "remote_type_identifier"
"name": "remote_constructor_name"
}
]
}
@ -4280,11 +4400,11 @@
"members": [
{
"type": "SYMBOL",
"name": "type_identifier"
"name": "constructor_name"
},
{
"type": "SYMBOL",
"name": "remote_type_identifier"
"name": "remote_constructor_name"
}
]
}
@ -4883,7 +5003,7 @@
"name": "name",
"content": {
"type": "SYMBOL",
"name": "type_identifier"
"name": "constructor_name"
}
},
{
@ -5055,40 +5175,38 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_string_part"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SYMBOL",
"name": "quoted_content"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"_string_part": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SYMBOL",
"name": "quoted_content"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\""
}
}
]
},
"escape_sequence": {
"type": "PATTERN",
"value": "\\\\[efnrt\\\"\\\\]"
},
"quoted_content": {
"type": "PATTERN",
"value": "(?:[^\\\\\\\"]|\\\\[^efnrt\\\"\\\\])+"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\\\[efnrt\\\"\\\\]"
}
},
"float": {
"type": "PATTERN",
"value": "-?[0-9_]+\\.[0-9_]+"
"value": "-?[0-9_]+\\.[0-9_]*"
},
"integer": {
"type": "SEQ",
@ -5686,6 +5804,35 @@
}
]
},
"constructor_name": {
"type": "SYMBOL",
"name": "_upname"
},
"remote_constructor_name": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "module",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "constructor_name"
}
}
]
},
"_discard_name": {
"type": "PATTERN",
"value": "_[_0-9a-z]*"
@ -5735,6 +5882,11 @@
"_maybe_tuple_expression",
"remote_type_identifier"
],
[
"_maybe_record_expression",
"_maybe_tuple_expression",
"remote_constructor_name"
],
[
"case_subjects"
],
@ -5743,7 +5895,12 @@
]
],
"precedences": [],
"externals": [],
"externals": [
{
"type": "SYMBOL",
"name": "quoted_content"
}
],
"inline": [],
"supertypes": []
}

@ -125,6 +125,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -314,6 +318,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -402,6 +410,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -586,6 +598,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -752,6 +768,10 @@
"type": "list_pattern",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -848,6 +868,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -1000,6 +1024,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -1231,6 +1259,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -1336,6 +1368,11 @@
]
}
},
{
"type": "constructor_name",
"named": true,
"fields": {}
},
{
"type": "data_constructor",
"named": true,
@ -1355,7 +1392,7 @@
"required": true,
"types": [
{
"type": "type_identifier",
"type": "constructor_name",
"named": true
}
]
@ -1499,6 +1536,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -1822,6 +1863,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2249,6 +2294,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2337,6 +2386,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2420,6 +2473,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2537,6 +2594,93 @@
"named": true,
"fields": {}
},
{
"type": "negation",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "anonymous_function",
"named": true
},
{
"type": "assert",
"named": true
},
{
"type": "bit_string",
"named": true
},
{
"type": "case",
"named": true
},
{
"type": "expression_group",
"named": true
},
{
"type": "field_access",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "let",
"named": true
},
{
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
},
{
"type": "record_update",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "todo",
"named": true
},
{
"type": "tuple",
"named": true
},
{
"type": "tuple_access",
"named": true
}
]
}
},
{
"type": "pattern_spread",
"named": true,
@ -2561,11 +2705,11 @@
"required": true,
"types": [
{
"type": "remote_type_identifier",
"type": "constructor_name",
"named": true
},
{
"type": "type_identifier",
"type": "remote_constructor_name",
"named": true
}
]
@ -2591,11 +2735,11 @@
"required": true,
"types": [
{
"type": "remote_type_identifier",
"type": "constructor_name",
"named": true
},
{
"type": "type_identifier",
"type": "remote_constructor_name",
"named": true
}
]
@ -2716,11 +2860,11 @@
"required": true,
"types": [
{
"type": "remote_type_identifier",
"type": "constructor_name",
"named": true
},
{
"type": "type_identifier",
"type": "remote_constructor_name",
"named": true
}
]
@ -2781,6 +2925,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2879,6 +3027,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -2922,6 +3074,32 @@
]
}
},
{
"type": "remote_constructor_name",
"named": true,
"fields": {
"module": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "constructor_name",
"named": true
}
]
}
}
},
{
"type": "remote_type_identifier",
"named": true,
@ -3028,6 +3206,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -3307,6 +3489,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -3395,6 +3581,10 @@
"type": "list",
"named": true
},
{
"type": "negation",
"named": true
},
{
"type": "record",
"named": true
@ -3825,6 +4015,10 @@
]
}
},
{
"type": "!",
"named": false
},
{
"type": "!=",
"named": false

48048
vendor/tree-sitter-gleam/src/parser.c generated vendored

File diff suppressed because it is too large Load Diff

@ -0,0 +1,29 @@
#include <tree_sitter/parser.h>
enum TokenType {
QUOTED_CONTENT
};
void * tree_sitter_gleam_external_scanner_create() {return NULL;}
void tree_sitter_gleam_external_scanner_destroy(void * payload) {}
unsigned tree_sitter_gleam_external_scanner_serialize(void * payload, char * buffer) {return 0;}
void tree_sitter_gleam_external_scanner_deserialize(void * payload, const char * buffer, unsigned length) {}
bool tree_sitter_gleam_external_scanner_scan(void * payload, TSLexer *lexer, const bool * valid_symbols) {
if (valid_symbols[QUOTED_CONTENT]) {
bool has_content = false;
while (true) {
if (lexer->lookahead == '\"' || lexer->lookahead == '\\') {
break;
} else if (lexer->lookahead == 0) {
return false;
}
has_content = true;
lexer->advance(lexer, false);
}
lexer->result_symbol = QUOTED_CONTENT;
return has_content;
}
return false;
}

@ -3,13 +3,14 @@ Constants
================================================================================
const a = "hello"
const a = "hello\nworld\!"
const a = "hello\nworld!"
const a = 1_234
const a = 0b110
const a = 0o7224
const a = 0xBEef
const a: Int = 1234
const a: Float = -1_234.53__23
const a: Float = 0.
const a: #(Int, String) = #(1, "Hello!")
const a: #() = #()
const a: List(Int) = [1, 2]
@ -61,6 +62,11 @@ const a: option.Option(String) = option.Some("Hello, World!")
type: (type
name: (type_identifier))
value: (float))
(constant
name: (identifier)
type: (type
name: (type_identifier))
value: (float))
(constant
name: (identifier)
type: (tuple_type
@ -144,16 +150,16 @@ const a: option.Option(String) = option.Some("Hello, World!")
(constant
name: (identifier)
value: (record
name: (type_identifier)))
name: (constructor_name)))
(constant
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments)))
(constant
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments
(argument
value: (string
@ -163,7 +169,7 @@ const a: option.Option(String) = option.Some("Hello, World!")
(constant
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments
(argument
label: (label)
@ -175,9 +181,9 @@ const a: option.Option(String) = option.Some("Hello, World!")
(constant
name: (identifier)
value: (record
name: (remote_type_identifier
name: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
arguments: (arguments
(argument
label: (label)
@ -194,9 +200,9 @@ const a: option.Option(String) = option.Some("Hello, World!")
(type
name: (type_identifier)))))
value: (record
name: (remote_type_identifier
name: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
arguments: (arguments
(argument
value: (string
@ -337,18 +343,18 @@ pub const a = uri.Uri(host: "github.com")
(visibility_modifier)
name: (identifier)
value: (record
name: (type_identifier)))
name: (constructor_name)))
(constant
(visibility_modifier)
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments)))
(constant
(visibility_modifier)
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments
(argument
value: (string
@ -359,7 +365,7 @@ pub const a = uri.Uri(host: "github.com")
(visibility_modifier)
name: (identifier)
value: (record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments
(argument
label: (label)
@ -372,9 +378,9 @@ pub const a = uri.Uri(host: "github.com")
(visibility_modifier)
name: (identifier)
value: (record
name: (remote_type_identifier
name: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
arguments: (arguments
(argument
label: (label)

@ -15,13 +15,13 @@ type NamedBox(inner_type) { Box(String, inner: inner_type) }
name: (type_identifier))
(data_constructors
(data_constructor
name: (type_identifier))))
name: (constructor_name))))
(type_definition
(type_name
name: (type_identifier))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
value: (type
@ -33,7 +33,7 @@ type NamedBox(inner_type) { Box(String, inner: inner_type) }
(type_parameter)))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -45,7 +45,7 @@ type NamedBox(inner_type) { Box(String, inner: inner_type) }
(type_parameter)))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
value: (type
@ -90,7 +90,7 @@ type Boring {
name: (type_identifier))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -106,7 +106,7 @@ type Boring {
parameters: (type_parameters))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -117,7 +117,7 @@ type Boring {
value: (type
name: (type_identifier)))))
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -135,12 +135,12 @@ type Boring {
(type_parameter)))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
value: (type_var))))
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
value: (type_var))))))
@ -149,17 +149,17 @@ type Boring {
name: (type_identifier))
(data_constructors
(data_constructor
name: (type_identifier))
name: (constructor_name))
(data_constructor
name: (type_identifier))
name: (constructor_name))
(data_constructor
name: (type_identifier))))
name: (constructor_name))))
(type_definition
(type_name
name: (type_identifier))
(data_constructors
(data_constructor
name: (type_identifier)))))
name: (constructor_name)))))
================================================================================
Public custom type definitions
@ -182,7 +182,7 @@ pub type Animal(name, cuteness) {
(type_parameter)))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -193,7 +193,7 @@ pub type Animal(name, cuteness) {
value: (type
name: (type_identifier)))))
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -226,7 +226,7 @@ pub opaque type Animal(name, cuteness) {
(type_parameter)))
(data_constructors
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)
@ -237,7 +237,7 @@ pub opaque type Animal(name, cuteness) {
value: (type
name: (type_identifier)))))
(data_constructor
name: (type_identifier)
name: (constructor_name)
arguments: (data_constructor_arguments
(data_constructor_argument
label: (label)

@ -20,3 +20,23 @@ Bit-string expression
(identifier)
(bit_string_segment_options
(bit_string_segment_option)))))
================================================================================
Negation
================================================================================
!False
True && !False
--------------------------------------------------------------------------------
(source_file
(negation
(record
(constructor_name)))
(binary_expression
(record
(constructor_name))
(negation
(record
(constructor_name)))))

@ -250,7 +250,7 @@ fn bit_string() {
<<0:4, 1:3, 1:1>>
}
fn return_fun(x) {
fn(foo y: Int) { x + y }
fn(y: Int) { x + y }
}
fn expression_group() {
{
@ -315,7 +315,7 @@ fn field_access(x) {
parameters: (function_parameters)
body: (function_body
(record
name: (type_identifier)
name: (constructor_name)
arguments: (arguments
(argument
label: (label)
@ -326,9 +326,9 @@ fn field_access(x) {
parameters: (function_parameters)
body: (function_body
(record
name: (remote_type_identifier
name: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
arguments: (arguments
(argument
label: (label)
@ -400,7 +400,6 @@ fn field_access(x) {
(anonymous_function
parameters: (function_parameters
(function_parameter
label: (label)
name: (identifier)
type: (type
name: (type_identifier))))
@ -440,13 +439,13 @@ fn field_access(x) {
(integer)
(integer)))
value: (record
name: (type_identifier)))
name: (constructor_name)))
(case_clause
patterns: (case_clause_patterns
(case_clause_pattern
(discard)))
value: (record
name: (type_identifier)))))))
name: (constructor_name)))))))
(function
name: (identifier)
parameters: (function_parameters)
@ -498,7 +497,7 @@ fn field_access(x) {
name: (identifier)))
body: (function_body
(record_update
constructor: (type_identifier)
constructor: (constructor_name)
spread: (identifier)
arguments: (record_update_arguments
(record_update_argument
@ -511,9 +510,9 @@ fn field_access(x) {
left: (integer)
right: (integer)))))
(record_update
constructor: (remote_type_identifier
constructor: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
spread: (function_call
function: (identifier)
arguments: (arguments))
@ -624,7 +623,7 @@ fn trial(x, y, z) {
index: (integer))
right: (integer)))
value: (record
name: (type_identifier)))
name: (constructor_name)))
(case_clause
patterns: (case_clause_patterns
(case_clause_pattern
@ -646,7 +645,7 @@ fn trial(x, y, z) {
index: (integer))
right: (integer))))
value: (record
name: (type_identifier)))))
name: (constructor_name)))))
(case
subjects: (case_subjects
(tuple
@ -677,25 +676,25 @@ fn trial(x, y, z) {
patterns: (case_clause_patterns
(case_clause_pattern
(record_pattern
name: (type_identifier)
name: (constructor_name)
arguments: (record_pattern_arguments
(record_pattern_argument
label: (label)
pattern: (record_pattern
name: (type_identifier)
name: (constructor_name)
arguments: (record_pattern_arguments
(record_pattern_argument
pattern: (string
(quoted_content))))))
(pattern_spread)))))
value: (record
name: (type_identifier)))
name: (constructor_name)))
(case_clause
patterns: (case_clause_patterns
(case_clause_pattern
(discard)))
value: (record
name: (type_identifier))))))))
name: (constructor_name))))))))
================================================================================
Try patterns
@ -735,14 +734,14 @@ fn try_try_again(x, y) -> Int {
value: (todo))
(try
pattern: (record_pattern
name: (remote_type_identifier
name: (remote_constructor_name
module: (identifier)
name: (type_identifier))
name: (constructor_name))
arguments: (record_pattern_arguments))
value: (todo))
(try
pattern: (record_pattern
name: (type_identifier))
name: (constructor_name))
value: (todo))
(try
pattern: (string
@ -1032,3 +1031,22 @@ fn lists(x) {
(list
(integer)
spread: (identifier)))))
================================================================================
Comment in string
================================================================================
io.println("// hello world!\n")
--------------------------------------------------------------------------------
(source_file
(function_call
function: (field_access
record: (identifier)
field: (label))
arguments: (arguments
(argument
value: (string
(quoted_content)
(escape_sequence))))))

@ -0,0 +1,20 @@
================================================================================
Pipes
================================================================================
string
|> iodata.new
|> iodata.reverse
--------------------------------------------------------------------------------
(source_file
(binary_expression
(binary_expression
(identifier)
(field_access
(identifier)
(label)))
(field_access
(identifier)
(label))))

@ -64,13 +64,13 @@ if javascript {
patterns: (case_clause_patterns
(case_clause_pattern
(record_pattern
name: (type_identifier))))
name: (constructor_name))))
value: (identifier))
(case_clause
patterns: (case_clause_patterns
(case_clause_pattern
(record_pattern
name: (type_identifier))))
name: (constructor_name))))
value: (function_call
function: (field_access
record: (identifier)
@ -193,16 +193,16 @@ pub fn negate(bool: Bool) -> Bool {
patterns: (case_clause_patterns
(case_clause_pattern
(record_pattern
name: (type_identifier))))
name: (constructor_name))))
value: (record
name: (type_identifier)))
name: (constructor_name)))
(case_clause
patterns: (case_clause_patterns
(case_clause_pattern
(record_pattern
name: (type_identifier))))
name: (constructor_name))))
value: (record
name: (type_identifier))))))))
name: (constructor_name))))))))
================================================================================
Trailing commas
@ -255,7 +255,7 @@ fn foo(a,) {
(type
(type_identifier)))))
(record
(type_identifier)
(constructor_name)
(arguments
(argument
(label)
@ -266,7 +266,7 @@ fn foo(a,) {
(type_identifier))
(data_constructors
(data_constructor
(type_identifier)
(constructor_name)
(data_constructor_arguments
(data_constructor_argument
(label)
@ -298,13 +298,13 @@ fn foo(a,) {
(identifier))))
(let
(record_pattern
(type_identifier)
(constructor_name)
(record_pattern_arguments
(record_pattern_argument
(label)
(identifier))))
(record_update
(type_identifier)
(constructor_name)
(identifier)
(record_update_arguments
(record_update_argument

@ -5,13 +5,13 @@ fn case_case(x: Option(String)) {
// ^ variable.parameter
// ^ variable.parameter
#(None, None) -> None
// ^ type
// ^ type
// ^ type
// ^ constructor
// ^ constructor
// ^ constructor
#(Some(y), Some(z)) -> #(y, z)
// ^ type
// ^ constructor
// ^ variable
// ^ type
// ^ constructor
// ^ variable
// ^ variable
// ^ variable

@ -43,6 +43,7 @@ pub fn replace(
fn record_with_fun_field(record) {
let foo = Bar(baz: fn(x) { x + 1 })
// ^ constructor
foo.baz(41)
// <- variable
// ^ property
@ -59,15 +60,22 @@ fn trial(uri) {
case uri {
// ^ variable.parameter
Uri(scheme: None) -> True
// <- type
// <- constructor
// ^ property
// ^ type
// ^ type
// ^ constructor
// ^ constructor
_ -> False
// <- comment.unused
}
}
fn my_uri_to_string(my_uri) -> String {
uri.to_string(my_uri)
// <- module
// ^ function
// ^ variable.parameter
}
fn myfun(argument) {
let local_fun = fn(x) { x + 1 }
// ^ variable
@ -87,3 +95,16 @@ fn myfun(argument) {
// ^ variable
// ^ variable.parameter
}
fn negate(arg) {
!arg
// <- operator
// ^ variable.parameter
}
fn comment_string_test() {
io.println("// hello world!")
// <- module
// ^ function
// ^ string
}

@ -38,5 +38,13 @@ fn remote_type_case() {
gleam.Ok(1)
// <- module
// ^ punctuation.delimiter
// ^ type
// ^ constructor
}
fn make_cat() -> kitty.Cat {
// ^ module
// ^ type
kitty.Cat(name: "Nubi")
// ^ module
// ^ constructor
}

@ -1,6 +1,7 @@
pub type User {
// ^ type
User(name: String)
// <- type
// <- constructor
// ^ property
// ^ type
}

@ -9,14 +9,14 @@ import gleam/bit_builder
pub type FrameData {
// ^ definition.type
Text(String)
// <- definition.type
// <- definition.constructor
// ^ reference.type
Binary(BitString)
Continuation(BitString)
Ping(BitString)
Pong(BitString)
Close(code: Option(Int), reason: Option(String))
// <- definition.type
// <- definition.constructor
// ^ reference.type
// ^ reference.type
// ^ reference.type
@ -42,7 +42,7 @@ fn encode_frame(frame: Frame) -> bit_builder.BitBuilder {
let opcode =
case frame.data {
Continuation(_) -> <<0x0:size(1)>>
// <- reference.type
// <- reference.constructor
Text(_) -> <<0x1:size(1)>>
Binary(_) -> <<0x2:size(1)>>
// 0x3-7 reserved for future non-control frames

@ -1,6 +1,6 @@
fn record_with_fun_field(record) {
let foo = Bar(baz: fn(x) { x + 1 })
// ^ reference.type
// ^ reference.constructor
foo.baz(41)
record.foobar("hello")