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

Special characters inside literal strings are not escaped by grammar #29

Open
RobertoRoos opened this issue Nov 28, 2024 · 1 comment
Open

Comments

@RobertoRoos
Copy link
Member

Following #28.

E.g.:

S_GET_CURR_MIN_MAX : STRING := 'CURR:LIM:NEG?;:CURR:LIM:POS?$L';
@Philipp1297
Copy link

I have a potential fix for this problem:

Variable:
CommentAny*
name=ID
(',' ID)*
(address=Address)?
':'
type=VariableType
((arglist=ArgList) | (AssignmentSymbol value=AssignmentValue))?
';'
comment=CommentLine?
;

AssignmentSymbol:
(':=') | ('REF=')
;

VariableType:
(array=VariableTypeArray)?
(pointer=PointerLike 'TO')?
name=BaseType
;

AssignmentValue:
ExpressionSemicolon | Expression | ArgList
;

ExpressionSemicolon:
/'[^']*'/
;

Explanation and Fixes

Issue with arglist and AssignmentSymbol: The problem seems to be in the Variable rule where either arglist or AssignmentSymbol can be matched. This creates ambiguity because only one of these should be valid at any given time.

Order of AssignmentValue: The second fix was to adjust the order of the AssignmentValue alternatives. By prioritizing ExpressionSemicolon, the parser can first check for a semicolon at the end of the expression. If no semicolon is found, it will proceed to evaluate the other options (Expression or ArgList).

Regex for Semicolons in Strings: Finally, the regex for ExpressionSemicolon was updated to allow semicolons within a string. This ensures that strings containing semicolons are parsed correctly without prematurely ending the expression.

Summary

These adjustments aim to resolve the ambiguity between arglist and AssignmentSymbol in the Variable rule, improve the handling of AssignmentValue, and properly account for semicolons within strings. I hope this helps!

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

2 participants