Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of record & list bodies. #94

Merged
merged 22 commits into from
May 26, 2024
Merged

Conversation

CabalCrow
Copy link
Contributor

@CabalCrow CabalCrow commented May 26, 2024

Brief Description

Change the node structure of the record & list bodies to better represent the actual syntax of the language. This fixes some bugs as well as make the syntax more consistent & easier to read.

Fixes

  • TS can't properly detect durantion values in records. It is instead deteced as integer & a command node that create an error:
{
    key: 5sec
}
  • TS can't properly detect when value & key begins & allow invald syntax with value & key having no space or any separator in between. The following example is considered valid by TS:
{
    key: 1536another_key: 8549
}

What is changed

  • Records use a new body structure which manages entries & separators in between. This fixes the separator bugs described above & creates new nodes that can be used for highlighting & indenting.
  • Lists also have their structure changed in the same manner (both records & list body acts the same in nushell syntax, with exception to what is actually a record entry key: value vs a list entry value.
  • Record tests are added for the bugs described above. All tests have been updated with the new node syntax.

Details

  • New function is added to grammar js for general body structure. It consist of repeated statement all seperated by a mandotory separator, followed by a final statement with an optional separator.
  • This function is applied to the bodies of lists & records with the corresponding entries.
  • List has an added node for the list_entry itself (before it was just hardcoded into the list rule)
  • Separator is added for entries [,\s\n\r]
  • Comment is added on top of the code to improve LSP parsing of code with tsserver (commonly used by other TS projects for grammar.sj)
  • Tests are updated with new new node syntax - I've individually checked the diffs of all tests to make sure they are working as indented
  • New test has been added to check if records can accept duration input.
  • New test has been added to test if records accept invaild input with no separator between value & key.

Record entries were unable to properly detect duration as a value. The
were viewing it as a number & then a command. In reality the issue was
that the record entry is recursive - so it was thinking of the command
as the start of the new record entry. I fixed that by changing the
record logic altogether by introducing mandatory separators (can be a
space or a newline) between record entries before the final one.
Adapting the new way of managing repetition to lists as well. Currently
broken.
There are new nodes for bodies & entries for records & lists. As well as
a new test testing if duaration now works for records.
Copy link
Collaborator

@fdncred fdncred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mostly looks good but what I don't understand is why the closure-xxx-yyyy tests were removed, except for 007. I expected them to be changed but not removed. Same for export-env-001-smoke-test.

@CabalCrow
Copy link
Contributor Author

It must have been a mistake on my part. Thanks for catching that - I re added the lost tests.

@fdncred fdncred merged commit 4fc9b88 into nushell:main May 26, 2024
3 checks passed
@fdncred
Copy link
Collaborator

fdncred commented May 26, 2024

Thanks

@CabalCrow CabalCrow deleted the record_dur branch May 26, 2024 17:51
fdncred pushed a commit that referenced this pull request May 27, 2024
The separator node introduced in #94 should use lexical precedence
instead of parse precedence. This is a quick fix to that.
Currently I don't know any issues introduced by this, but this could
potentially create an issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants