Dot '.' is not allowed inside double quote in Xtext [message #1862984] |
Wed, 10 January 2024 06:02 |
Unbiased Coder Messages: 3 Registered: January 2024 |
Junior Member |
|
|
I have been actively working on configuring terminal rules within Xtext and encountered a puzzling inconsistency concerning the usage of dots within strings enclosed by different quotation marks.
In the existing terminal rule for STRING in Xtext, I've noticed that dots are restricted within strings encapsulated by double quotes, as defined by the grammar rules. However, what perplexes me is that dots seem to be permitted and operational within strings enclosed by single quotes.
For instance, consider the following snippet from the current terminal rule:
terminal STRING:
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
Now, when utilizing this rule, I encountered the following behavior:
"This is.dot" results in rejection or errors due to the dot within the double quotes.
However, 'This.is.dot' is accepted and functions appropriately within the single quotes.
This discrepancy prompts my query regarding the reasoning behind disallowing dots within double quotes while permitting them within single quotes according to the existing terminal rule.
Could you kindly provide insights or propose an alteration to the terminal rule that would allow dots within strings enclosed by both double quotes and single quotes?
I kindly request insights or guidance on this matter. Additionally, if possible, could you provide clarification or elucidation with respect to this behavior?
Thank you very much for your time and consideration.
|
|
|
|
|
|
|
Re: Dot '.' is not allowed inside double quote in Xtext [message #1863111 is a reply to message #1863021] |
Wed, 17 January 2024 03:59 |
Unbiased Coder Messages: 3 Registered: January 2024 |
Junior Member |
|
|
Hi ,
I have three terminal rules in my grammar, each involving double quotes and potentially conflicting with each other. The rules are as follows:
1. terminal PATH: '"' (((ESCAPE)? CUSTOMID)+ '.' CUSTOMID) '"' ;
terminal CUSTOMID : '^'? ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '-' | '0'..'9' | WS)*;
terminal ESCAPE: ('\\' | '\\\\' | '/');
2. terminal VISUAL_STRING: '"%' INT '.' INT 'f"'?;
3. terminal STRING:
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
The challenge arises when attempting to handle dot inside double quote for the STRING rule as dot inside double quote is possible for both PATH and VISUAL_STRING. This creates ambiguity and confusion within the grammar, particularly because dots are allowed in a similar pattern for both PATH and VISUAL_STRING. As a result, an error is occurring when a dot is used inside double quotes for a STRING due to this ambiguity.
Is there a way that all three rules can coexist without breaking any functionality?
[Updated on: Wed, 17 January 2024 04:08] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04290 seconds