Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Some small fixes #5

Open
mingodad opened this issue Feb 13, 2024 · 0 comments
Open

Some small fixes #5

mingodad opened this issue Feb 13, 2024 · 0 comments

Comments

@mingodad
Copy link

Trying to compare this parser with https://github.com/c3lang/c3c/tree/master/resources/grammar and https://mingodad.github.io/parsertl-playground/playground/ (select C3c parser from Examples then click Parse to see a parse tree for the content in Input source) I found some differences between the error reported by this parser and the others (this parser also helped spot problems in others).

But still there is some changes made in https://github.com/c3lang/c3c/blob/da292e41bd0c315d3cad0d3b2b7d7d49e76cd271/resources/grammar/grammar.y#L210 that are not present here and in several places that have something like [^1] is flagged as error by this parser/grammar.

Also there is another project like your (but without showing as clone here https://github.com/cbuttner/tree-sitter-c3 and probably both could join efforts.

---------------------------------- grammar.js ----------------------------------
index 056bf36..f4ea46c 100644
@@ -156,7 +156,7 @@ module.exports = grammar({
 
     raw_string_literal: $ => seq(
       '`',
-      alias(token.immediate(repeat(prec(1, /(``)*[^`]+(``)*/))), $.raw_string_content),
+      alias(token.immediate(repeat(prec(1, /(``|[^`])/))), $.raw_string_content),
       '`',
     ),
 
@@ -164,6 +164,9 @@ module.exports = grammar({
       seq('x\'', repeat1(HEX), '\''),
       seq('x"',  repeat1(HEX), '"'),
       seq('x`',  repeat1(HEX), '`'),
+      seq('b64\'', repeat1(B64), '\''),
+      seq('b64"',  repeat1(B64), '"'),
+      seq('b64`',  repeat1(B64), '`'),
     )),
 
     // Comments
@@ -440,8 +443,7 @@ module.exports = grammar({
     ),
     struct_body: $ => seq(
       '{',
-      // NOTE Allowing empty struct to not be too strict.
-      repeat($.struct_member_declaration),
+      repeat1($.struct_member_declaration),
       '}',
     ),
     struct_declaration: $ => seq(
@@ -1103,7 +1105,7 @@ module.exports = grammar({
       $._base_expr,
     )),
 
-    string_expr: $ => repeat1($.string_literal),
+    string_expr: $ => repeat1(choice($.string_literal, $.raw_string_literal)),
     bytes_expr: $ => repeat1($.bytes_literal),
     paren_expr: $ => seq('(', $._expr, ')'),
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant