nushell / tree-sitter-nu

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

Allow unquoted values in val_record #136

Closed blindFS closed 2 weeks ago

blindFS commented 3 weeks ago

This PR fixes situations where record value is an unquoted string

image

Also cleaned list_entry rule a little bit since signed numbers, flags and unquoted string start with +/- are more easy to distinguish.

blindFS commented 3 weeks ago

BTW, I don't know whether this is desired:

image

But it makes unquoted strings easier to parse and current grammar works in the same way. If so, _expr_unary_minus doesn't make much sense then.

fdncred commented 3 weeks ago

Is you screenshot the "before" or "after" this PR?

x is supposed to be a string here

❯ {k: a}
╭───┬───╮
│ k │ a │
╰───┴───╯
❯ {k: a} | describe -d | table -e
╭─────────┬────────────────╮
│ type    │ record         │
│         │ ╭───┬────────╮ │
│ columns │ │ k │ string │ │
│         │ ╰───┴────────╯ │
╰─────────┴────────────────╯
blindFS commented 3 weeks ago

@fdncred The screenshot with error is before this PR, should be fine after this.

(nu_script [0, 0] - [3, 0]
  (pipeline [0, 0] - [3, 0]
    (pipe_element [0, 0] - [2, 1]
      (val_record [0, 0] - [2, 1]
        (record_body [1, 2] - [2, 0]
          entry: (record_entry [1, 2] - [1, 8]
            key: (identifier [1, 2] - [1, 3])
            value: (val_string [1, 5] - [1, 8])))))))
blindFS commented 3 weeks ago

_expr_unary_minus however is left as it was, which is not exactly current nushell's behaviour. It's not related to $.val_record, just some random stuff found during the code cleansing.

fdncred commented 2 weeks ago

Thanks