gleam-lang / tree-sitter-gleam

🌳 A tree-sitter grammar for the Gleam programming language
Apache License 2.0
66 stars 13 forks source link

add `panic` keyword / add contributing section to Readme #46

Closed inoas closed 1 year ago

inoas commented 1 year ago

Sadly I don't know anything at all about treesitter:

❯ tree-sitter test
  imports:
    ✓ Imports
    ✓ Unqualified imports
    ✓ Aliased imports
  pipes:
    ✓ Pipes
  functions:
    ✓ Function examples
    ✓ Public function examples
    ✓ Basic functions
    ✓ Cases
    ✓ Try patterns
    ✓ Let expressions
    ✓ Complex binary expressions
    ✓ Complex nesting of field and tuple access
    ✓ Unusual function invocations
    ✓ Various discard variables
    ✓ Weird lists
    ✓ Comment in string
  targets:
    ✓ Target groups
    ✓ Target group edge cases
  custom_types:
    ✓ Parser example custom types
    ✓ Other custom type examples
    ✓ Public custom type definitions
    ✓ Public opaque custom type definitions
  whole_files:
    ✓ Excerpt from stdlib's base.gleam
    ✓ Excerpt from stdlib's bool.gleam
    ✓ Trailing commas
  external_functions:
    ✓ External functions
    ✓ Public external functions
  destructuring:
    ✓ Case with spread
  external_types:
    ✓ External types
    ✓ Public external types
  constants:
    ✓ Constants
    ✓ Public constants
    ✓ Scientific notation
  type_aliases:
    ✓ Type aliases
    ✓ Public type aliases
    ✓ Public opaque type aliases
  expressions:
    ✓ Bit-string expression
    ✓ Negation
    ✓ Concatenation
    ✓ Use
Error in query file "highlights.scm"

Caused by:
    Query error at 82:4. Invalid node type panic

Any hints?

inoas commented 1 year ago

The error is the same though:

Error in query file "highlights.scm"

Caused by:
    Query error at 82:4. Invalid node type panic
inoas commented 1 year ago

The error is the same though:

Error in query file "highlights.scm"

Caused by:
    Query error at 82:4. Invalid node type panic

Seems like I've fixed it.

inoas commented 1 year ago

I've tried to add let assert but the tests fail on that. The panic stuff seems to be working.

inoas commented 1 year ago

So I have reverted the changes for let assert and just did the ones for panic.

inoas commented 1 year ago

@J3RN could you triggrer the workflow?

inoas commented 1 year ago

npm run test is green for me

inoas commented 1 year ago

Hey @inoas! 👋 Thanks for submitting this patch! 🎉

To answer your direct question: the reason why the tests were failing is that the grammar needed to be "generated" from the grammar.js file by running npm run generate. This is totally non-obvious and (AFAIK) not documented anywhere 😓 I'm making a change now such that when you run npm test it'll run npm run generate first to alleviate this issue!

I also flagged a handful of other tiny issues that we'll want to resolve before merging.

How do I emperically test?

❯ tree-sitter parse test/gleam/list_test.gleam No language found ❯ tree-sitter highlight test/gleam/list_test.gleam No language found for path "test/gleam/list_test.gleam"

I have got tree-sitter cloned

❯ which tree-sitter
/usr/local/bin/tree-sitter

I have this repo here cloned: ~/tree-sitters/tree-sitter-gleam

the-mikedavis commented 1 year ago

You can use npx tree-sitter parse path/to/file.gleam to use the tree-sitter-cli version from the package.json. ./scripts/integration_test.sh will run the integration tests against the gleam stdlib and other gleam repositories. It looks like the integration tests fail until #48 and #49 are merged in since let assert is used in the stdlib and use with patterns is used in gleam-lang/otp.

J3RN commented 1 year ago

When updating this branch, don't worry about resolving the conflicts in src/parser.c by hand. You can "resolve" the conflicts however you like—even just leaving the >>>> etc in there—and generate correct contents src/parser.c by running npm run generate.

inoas commented 1 year ago

./scripts/integration_test.sh

I do not understand this:

❯ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
❯ ./scripts/integration_test.sh
Running parser against gleam-lang/stdlib
test/integration/gleam_lang_stdlib/src/gleam/string.gleam               1 ms    (ERROR [859, 4] - [1025, 28])
test/integration/gleam_lang_stdlib/test/gleam/bool_test.gleam           1 ms    (ERROR [159, 13] - [159, 14])
test/integration/gleam_lang_stdlib/test/gleam/iterator_test.gleam       1 ms    (ERROR [0, 0] - [574, 0])
test/integration/gleam_lang_stdlib/test/gleam/list_test.gleam           14 ms   (ERROR [848, 35] - [848, 41])
test/integration/gleam_lang_stdlib/test/gleam/queue_test.gleam          3 ms    (ERROR [85, 2] - [172, 22])
test/integration/gleam_lang_stdlib/test/gleam/regex_test.gleam          0 ms    (ERROR [5, 2] - [85, 67])
test/integration/gleam_lang_stdlib/test/gleam/string_test.gleam         3 ms    (ERROR [415, 2] - [983, 50])
test/integration/gleam_lang_stdlib/test/gleam/uri_test.gleam            1 ms    (ERROR [9, 2] - [554, 66])
Total parses: 45; successful parses: 37; failed parses: 8; success percentage: 82.22%

❯ git checkout add-panic
Switched to branch 'add-panic'
❯ ./scripts/integration_test.sh
Running parser against gleam-lang/stdlib
test/integration/gleam_lang_stdlib/src/gleam/string.gleam               2 ms    (ERROR [859, 4] - [1025, 28])
test/integration/gleam_lang_stdlib/test/gleam/bool_test.gleam           1 ms    (ERROR [159, 13] - [159, 14])
test/integration/gleam_lang_stdlib/test/gleam/iterator_test.gleam       1 ms    (ERROR [0, 0] - [574, 0])
test/integration/gleam_lang_stdlib/test/gleam/list_test.gleam           13 ms   (ERROR [848, 35] - [848, 41])
test/integration/gleam_lang_stdlib/test/gleam/queue_test.gleam          4 ms    (ERROR [85, 2] - [172, 22])
test/integration/gleam_lang_stdlib/test/gleam/regex_test.gleam          0 ms    (ERROR [5, 2] - [85, 67])
test/integration/gleam_lang_stdlib/test/gleam/string_test.gleam         3 ms    (ERROR [415, 2] - [983, 50])
test/integration/gleam_lang_stdlib/test/gleam/uri_test.gleam            1 ms    (ERROR [9, 2] - [554, 66])
Total parses: 45; successful parses: 37; failed parses: 8; success percentage: 82.22%

Why is it only at 82.22%? At first I thought my panic change reduced that number

inoas commented 1 year ago

ah ok, probably https://github.com/gleam-lang/tree-sitter-gleam/pull/48 was the source of the issue. With that rebased on main it is back at 100%.

Cool!