nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
122 stars 27 forks source link

Parser breaks with this syntax #32

Closed marcelarie closed 7 months ago

marcelarie commented 1 year ago

With the type@'type' on the command parameter, the syntax highlighting breaks.

Example of the code:

export def-env main [
    command?: string@'nu-complete rbenv',
    ...args
] {
    let new_env = if $command in ["rehash", "shell"] {
        # implement each on indiviudaly e.g.
        if $command == "shell" {
            { RBENV_VERSION_OLD: $env.RBENV_VERSION RBENV_VERSION: $args.0 }
        } else {
            error make { msg: $"`($command)` command is not supported yet" }
        }
    } else {
        if ($command | is-empty) {
            ^rbenv
        } else {
            ^rbenv $command $args
        }
        {}
    }
    load-env $new_env
}

def 'nu-complete rbenv' [] {
    ^rbenv help
    | lines
    | where ($it | str starts-with "   ")
    | each {|entry| $entry | split row ' ' | get 0 }
}

Screenshoot:

Screenshot 2023-09-24 at 23 38 56
fdncred commented 1 year ago

Thanks for the report! We need more hands on this repo. We only have a couple people who've done 99% of the work. Feel free to get your hands dirty and try to submit a PR.

amtoine commented 1 year ago

not sure i see the same in Neovim :open_mouth: tree-sitter-nu_32

marcelarie commented 1 year ago

I am using neovim too, how strange. Maybe I have some plugin that breaks treesitter.

https://github.com/nushell/tree-sitter-nu/assets/62728887/a38bd21b-3405-488c-977e-ebcdc8cf2611

amtoine commented 1 year ago

:scream:

without looking at the config, the only difference i see is the extra export-env block you have at the top :smirk:

also, do you use the latest version of this TS?

marcelarie commented 1 year ago

I tried deleting that export-env and the result is the same:

Screenshot 2023-09-27 at 12 10 23
marcelarie commented 1 year ago

I use the latest version I think, how can I check it?

siph commented 1 year ago

fwiw this highlighting looks fine with my neovim config as well.

amtoine commented 1 year ago

I use the latest version I think, how can I check it?

not sure, i've installed the queries from this repo manually so i do not have the revision attached to them i fear :confused:

amtoine commented 1 year ago

very strange, i just pulled the query file again and reinstalled the TS parser again with the following two scripts:

and i still do not see this :cry:

petrisch commented 7 months ago

Did you check the :InspectTree for this? Cause with my colorscheme this doesn't break the highlight, however I see an ERROR on this line (26): | where ($it | str starts-with " ") right on the where keyword.

petrisch commented 7 months ago

I don't have a solution, but shouldn't there be optional punctuation, like brakets or parenthesis in the _where_predicate here?

where_command: ($) => seq("where", $._where_predicate),

    _where_predicate: ($) =>
      choice(
        ...TABLE().map(([precedence, opr]) =>
          prec.left(
            precedence,
...

Because this:

[["a" "b"];[3 4] [5 6]] | where ("a" < 4)

or this

[["a" "b"];[3 4] [5 6]] | where "a" < 4

breaks it for me also.

fdncred commented 7 months ago

where can have parentheses or braces since it's a closure.

fdncred commented 7 months ago

I'm not seeing any errors in the OP's script now (except moving from def-env to def --env). So, I'm closing this. image

fdncred commented 7 months ago

oops, actually I do still see an error. Sorry. image @kit494way is this something you'd be interested in fixing?

kit494way commented 7 months ago

yes. I will try.