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

Cpp contains string literals that are not identical in grammar #4132

Open
kaby76 opened this issue Feb 22, 2023 · 0 comments
Open

Cpp contains string literals that are not identical in grammar #4132

kaby76 opened this issue Feb 22, 2023 · 0 comments

Comments

@kaby76
Copy link
Contributor

kaby76 commented Feb 22, 2023

Using Tsql, and Version 4.12.0 of the Antlr tool, generate a parser and lexer for both CSharp and Cpp targets. Then, look at the generated TsqlParser files.

In a generated table of Cpp target TsqlParser.cpp auto staticData = std::make_unique<TSqlParserStaticData>( and that in C# PlsqlParser.cs _LiteralNames, the very last entry in the string table "literalNames" for C# is '?', but it is '\\u003F' for the C++ code. U+003F is the Unicode for the ?-character. There is no string literal '\\u003F' in the lexer or parser grammar, just '?', here.

C#:

private static readonly string[] _LiteralNames = {
	null, "'ADD'", "'ALL'", "'ALTER'", "'AND'", "'ANY'", "'AS'", "'ASC'", 
	...
	"'&'", "'^'", "'?'"
};

C++:

auto staticData = std::make_unique<TSqlParserStaticData>(
	std::vector<std::string>{
		"tsql_file", "batch", "batch_level_statement", "sql_clauses", "dml_clause", 
		...
		},
	std::vector<std::string>{
		"", "'ADD'", "'ALL'", "'ALTER'", "'AND'", "'ANY'", "'AS'", "'ASC'", 
		...
		"'/'", "'%'", "'+'", "'-'", "'~'", "'|'", "'&'", "'^'", "'\\u003F'"
		},

The strings literals should be identical across all targets, and identical to the string literal in the grammar. This is necessary if error messages that occur of a parse are to remain identical. In my opinion, the generated C++ code is wrong.

Does this difference have something to do with something with fragment rules?

@kaby76 kaby76 changed the title Cpp and other targets differ in string values from grammar Cpp contains string literals that are not identical in grammar Feb 23, 2023
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

No branches or pull requests

1 participant