-
Notifications
You must be signed in to change notification settings - Fork 154
BSV Language Reference Grammar Issues #764
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
Comments
Hi, I also implemented a tree-sitter parser for BSV and noticed these issues in the reference guide! There are undocumented or incorrect grammar rules/specifications in the reference guide, such as elements like function types and namespaced identifiers While my implementation lacks unit tests for the grammars, I use the tree-sitter parser for syntax highlighting in my Neovim, which works almost perfectly. I thought you might find my implementation useful. |
Very cool to hear about these parsers. And thank you for bringing discrepancies to our attention! Yes, corrections to the grammar would be great. (Or potentially corrections to BSC.) For the two questions you have, I think I would need to see some examples, to understand what we're talking about. For (2): BSC does support pattern matching of bindings using the
These declare new variable names; if you tried to precede the binding with a type declaration for the names, BSC would report an error:
However, in the testsuite directory
I was not aware of this syntax! It may be a vestige of the first days of BSV, when the parser was being written and the language (and style of coding) was being invented, by taking the BH code base and seeing how one would write in BSV. I don't have a sense of whether anyone writes BSV code with it now? A limitation of I haven't yet looked into question 1 -- if you have more detail on that, that'd be helpful. I do often use the syntax |
These are some examples of the discrepancies I found in the grammar, along with some proposed fixes. @yuyuranium, feel free to add to this list if you found something I hadn't. It is possible that I have misunderstood the spec grammar in some places and that some of the below issues are not actually issues, in which case please point this out.
I think section 9 on variable declarations and statements would benefit from a cleanup. For example, the Finally, just a comment about function/method syntax; the following is not a grammar bug. In |
Hi, @quark17
It could even be written as:
As you mentioned, the functionality is not complete. Besides structs or nested tuples/structs, I've also discovered that [] cannot be used within {}. I would greatly appreciate if this feature could be preserved or if an alternative syntax might be considered in future updates.
I would like to be able to write something similar to the following, or have corresponding syntax implemented in the future.
In this example, using "match" would require mkWoscReg and mkRoReg to have fixed types, when I actually need flexibility to change the reg_inst type. Additionally, operators are repeatedly passed with appended information. Although we could work around this by using different variable names each line. |
While implementing a tree-sitter parser for BSV, I noticed a few minor issues with the grammar description in the BSV Language Reference Guide. Some examples:
packageStmt
rule is missing theexternCImport
choice.methodDef
rule does not allow an emptymethodFormals
list.actionStmt
andactionValueStmt
misses a;
at the end of theregWrite
choice.Besides such minor bugs, there is another question if the BSV Language Reference should be changed to align more closely with the actual bsc compiler implementation. For example:
methodDef
rule, but bsc does not. This method declaration is accepted without warning by bsc:method a getOutput;
{b, i, .*} <- mkSub;
If there is interest, I can put together a PR with fixes to the BSV Language Reference Guide, either just the first type of issue or both.
The text was updated successfully, but these errors were encountered: