-
Notifications
You must be signed in to change notification settings - Fork 32
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
Update grammar.y #43
Comments
@Vexu, the grammar still fails with some source file in the Using the script https://gist.github.com/perillo/a1a731d234b425597a70412a7343b772, these are the errors: compiler source
std source
In the previous list I forgot to add the new tuple type declaration.
Thanks. |
Done in 3aefd84 |
@Vexu, found more errors when checking the Compiler tests
Most of the errors are invalid literals; however an interesting case is: pub fn the_add_function(a: u32, b: u32) u32 {
return a + b;
}
test the_add_function {
if (the_add_function(1, 2) != 3) unreachable;
}
Thanks |
Done in 11ed032, I'm not sure whether this grammar should allow valid numbers or not so I didn't touch them. |
In addition to number literals, the zig parser seems to be able to do additional analysis compared to
|
Those shouldn't be in the grammar IMO. |
Do you think they should be documented in the Zig Language Reference? |
I don't think it's strictly necessary but if you want to mention it somewhere then go ahead. |
@Vexu, in order to check the PEG parser I wrote a tool (in Go, since it was more convenient) that downloads up to 1000 repositories using the GitHub API, and check each For now I found these issues:
|
Found other issues:
Here is the full report: https://gist.github.com/perillo/c33e79e6d95efabaf302ef3c5d5907ad |
Thank you for taking care of the grammar. A few observations:
diff --git a/grammar/grammar.y b/grammar/grammar.y
index ec08094..c5c47be 100644
--- a/grammar/grammar.y
+++ b/grammar/grammar.y
@@ -1,13 +1,12 @@
Root <- skip container_doc_comment? ContainerMembers eof
# *** Top level ***
-ContainerMembers <- ContainerDeclarations (ContainerField COMMA)* (ContainerField / ContainerDeclarations)
+ContainerMembers <- ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
-ContainerDeclarations
- <- TestDecl ContainerDeclarations
- / ComptimeDecl ContainerDeclarations
- / doc_comment? KEYWORD_pub? Decl ContainerDeclarations
- /
+ContainerDeclaration
+ <- TestDecl
+ / ComptimeDecl
+ / doc_comment? KEYWORD_pub? Decl
|
Seconded. Also IMHO
It skips |
Currently,
grammar.y
is out of sync with the actual grammar implemented by thezig
compiler (instd/zig/tokenizer
andstd/zig/parser.zig
).These are the places where
grammar.y
andzig
diverges, found with the improved parser from #42, using files insrc
andlib/std
in thezig
repository.doc-comments not allowed in top-level
comptime
andtest
declaration.Saturating arithmetic is not supported by
grammar.y
.Mixed
doc-comment
andline-comment
is not supported bygrammar.y
.NOTE: I found mixing
doc-comment
andline-comment
confusing, andautodoc
doesn't not handle them correctly.Examples:
std/mem.zig:3760
See: https://ziglang.org/documentation/master/std/#root;mem.doNotOptimizeAway.
std/coff.zig:354
See https://ziglang.org/documentation/master/std/#root;coff.BaseRelocationType.
New
addrspace
keyword.Commit: ziglang/zig@ccc7f9987 (Address spaces: addrspace(A) parsing)
Date: 2021-09-14
Inline switch prong not supported by
grammar.y
.Commit: ziglang/zig@b4d81857f (stage1+2: parse inline switch cases)
Date: 2022-02-13
New packed
struct
syntax.Commit: ziglang/zig@6249a24e8 (stage2: integer-backed packed structs)
Date: 2022-02-23
The text was updated successfully, but these errors were encountered: