Search code examples
eclipsextext

Xtext - Custom made terminal string without quotes


I´m new to Xtext and have a problem.

When I try to create a terminal String without quotes I always get EOF errors.

If I comment out the code for the String without quotes I´dont get an error and everything works fine.

Can someone explain me this? Or give me some hint how I could better solve this?

Thank you very much

    // String without quotes
terminal STRINGWQ: ( ('a'..'z'|'A'..'Z')('a'..'z' | 'A'..'Z' | '_'| '-' | '§' | '?' | '!'| '@'
                                        | '\n' | ':' |'%' | '.' | '*' | '^' | ',' | '&' | '('|')'| '0'..'9'|' ')*);

Rest of Code

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"


Model:
    (elements += GITest)* 
;


GITest:
    KWHeader | KWTestCase
;

// KeyWords Header
KWHeader:
    'Test' '!''?'
    ;

KWTestCase:
    'testcase' int=INT ':' title = ID |
    'Hello' names=ID '!'
;

UPDATE: Data Type Rule

 QSTRING returns ecore::EString: //custom terminal SurveyString
        (('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z'|
           'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'I'|'J'|'K'|'L'|'M'|'N'|'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'|' ')
          ('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z'|
           'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'I'|'J'|'K'|'L'|'M'|'N'|'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'|
           ' '|'_'|'-'|'§'|'?'|'!'|'@'|'%'|'.'|'*'|'^'|','|'&'|'('|')'|'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9')*);

UPDATE 2:

Got it working with Data Type Rule und manipulating ID

Code:

STRINGWQ: ((' ')?ID)((ID)?(INT)? ' ' (ID)?);
terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'/'|';'|','|'#'|'!'|'§'|'$'|'%'|'&'|
              '('|')'|'='|'?'|'\\'|'*'|'+'|'.'|'-'|'>'|'<'|'|'|'['|']'|'{'|'}')*;

But now I have the problem that xtext not recognizes when STRINGWQ ends. So I dont get keyword suggestions in the next line. For example if i dont use STRINGWQ but INT I get suggestions in the next line. But with STRINGWQ I dont. How can I define an end of Data Type Rules? Thank you


Solution

  • This works for me:

    Property:
        id=ID | int=INT | prop=PROPERTY_VALUE | spec=SPECIAL;
    
    PROPERTY_VALUE:
        (':');
    
    SPECIAL:
        (' ' | '/' | ';' | ',' | '!' | '§' | '%' | '&' | '(' | ')' | '?' | '*' | '+' | '.' | '-' | '|' | '[' | ']')
    

    I separated the colon as I need to use PROPERTY_VALUE in another way. But you also could add it to special.