Mismatched character [message #1838634] |
Tue, 02 March 2021 12:49  |
Eclipse User |
|
|
|
I'm trying to develop a DSL that uses JSON. But I've run into a problem with the following grammar:
grammar org.xtext.example.mydsl.MyDsl hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
'[' objects += Object (',' objects += Object)* ']'
;
Object:
'{' '"name"' ':' '"' name = STRING '"' ',' '"type"' ':' '"object"' ',' '"isOptional"' ':' value = BOOLEAN ',' '"dataType"' ':' '"' dataType = PredefinedType '"' '}'
;
PredefinedType:
type = ('String' | 'int' | 'float' | 'boolean')
;
terminal STRING: "'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'";
terminal BOOLEAN: 'true' | 'false';
terminal ML_COMMENT : '/*' -> '*/';
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;
The DSL:
[
{
"name": "'Test'",
"type": "object",
"isOptional": false,
"dataType" : "int"
}
]
It gives error "mismatched charachter 'n' expections 's'" at int. It want me to write isOptional instead of int. I've tried changed '"isOptional"' to '"optional"' in the grammar, which fixes the issue. But I'm curious about why I get the error, and why changing the keyword fixes it. Any ideas?
[Updated on: Tue, 02 March 2021 12:51] by Moderator
|
|
|
|
|
|
|
|
Re: Mismatched character [message #1838801 is a reply to message #1838800] |
Fri, 05 March 2021 03:59  |
Eclipse User |
|
|
|
dataType = ([DefinedType|STRING] | PREDEFINED_TYPE is an antipattern.
without a stacktrace hard to jude
maybe
dataType =AbstractDataType
AbstractDataType: PrimiteDataType | DataTypeRef;
PrimiteDataType: type= PREDEFINED_TYPE;
DataTypeRef: ref=[DefinedType|STRING];
|
|
|
Powered by
FUDForum. Page generated in 0.04740 seconds