|
|
|
|
Re: Regular Expression and newline [message #897406 is a reply to message #894380] |
Mon, 23 July 2012 22:19  |
Eclipse User |
|
|
|
Sorry to bother you guys again, but i got another problem.
this is my new xtext file. I a currently having issues with adding comments or having some random whitespaces within such a gla file.
grammar de.sabram.upb.specs.Gla hidden(WS, ML_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate gla "//www.sabram.de/upb/specs/Gla"
File:
specifications+=Specification(('\n' |'\r' )specifications+=Specification)*;
Specification returns Specifications:
( tokenName = ID ':')?
pattern=Pattern
('('auxiliaryScannerName=AuxiliaryScannerName')')?
('['tokenProcessorName=TokenProcessorName']')?
;
Pattern: CannedExpression | RegularExpression;
CannedExpression returns Pattern:
value=('ADA_COMMENT' | 'ADA_IDENTIFIER' | 'AWK_COMMENT' | 'C_COMMENT' | 'C_CHAR_CONSTANT' | 'C_FLOAT'
| 'C_IDENTIFIER' | 'C_INTEGER' | 'C_INT_DENOTATION' | 'C_STRING_LIT' | 'MODULA_INTEGER' | 'MODULA2_COMMENT'
| 'MODULA3_COMMENT' | 'MODULA2_CHARINT' | 'MODULA2_INTEGER' | 'MODULA2_LITERALDQ' | 'MODULA2_LITERALSQ'
| 'PASCAL_COMMENT' | 'PASCAL_IDENTIFIER' | 'PASCAL_INTEGER' | 'PASCAL_REAL' | 'PASCAL_STRING' | 'SPACES' | 'TAB' | 'NEW_LINE')
;
RegularExpression returns Pattern: value=REGEX;
AuxiliaryScannerName:
value=('auxEOF'| 'coordAdjust'| 'auxNewLine' | 'auxTab' | 'auxEOL'| 'auxPascalString' | 'auxPascalComment'
| 'auxNoEOL' | 'auxCString' | 'auxCChar' | 'auxCComment' | 'auxM2String'| 'auxM3Comment' | 'Ctext')
;
TokenProcessorName:
value=('c_mkchar' | 'c_mkint' | 'c_mkstr' | 'EndOfText' | 'lexerr' | 'mkidn'| 'mkint' | 'mkstr' | 'modula_mkint')
;
/********************************************************************
******** TERMINALS
******** No rules below this line, only terminals
********************************************************************/
/*
* RegularExpression Terminal for Eli/GLA. Beginning with a $ followed by the body of a regularExpression
* the regularExpression is split into seperate parts, to make it readable
* - all possible digits: REGEX_NUMBER
* - all possible characters: REGEX_DIGIT
* - all possible cardinality operators : REGEX_CARDINALITY
* - all possible symbols within a regular expression
*/
terminal REGEX: '$' REGEX_BODY+;
terminal fragment REGEX_BODY: (REGEX_STRING|REGEX_DIGIT|REGEX_CARDINALITY|REGEX_SYMBOL);
terminal fragment REGEX_DIGIT: ('0'..'9');
terminal fragment REGEX_STRING: ('a'..'z'|'A'..'Z');
terminal fragment REGEX_CARDINALITY: ('*'|'+'|'-'|'?');
terminal fragment REGEX_SYMBOL: (','|'.'|'\''|':'|'\"'|'>'|'<'|'/'|'_'|'='|';'|'('|')'|'&'|'!'|'#'|'%'|'['|']'|'\\');
/*
* TERMINALS OUT OF DEFAULT
*/
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;
terminal ML_COMMENT: '/*' -> '*/';
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;
The editor doesnt accept such an input
/*
* this is a small gla Example file
* which simply defines 3 different tokens by using CannedExpressions
*/
Identifier: C_IDENTIFIER
Number: C_INTEGER
C_COMMENT
my problem in this example is the multiple \t characters in front of C_COMMENT or a random \t or simple space after a line like Identifier: C_IDENTIFIER.
Am I using the WS rule wrong? Took the hidden(WS,ML_COMMENT) out of the xtext default terminals and was expecting to ignore whitespaces and multiline comments.
I really appreciate your help.
Best greetings, Paolo
Edit somehow i wasn't able to copy the whole code because this forum doesn't accept "links" which are too long and don't point to eclipse. So the generate gla part is missing the "http:"
[Updated on: Mon, 23 July 2012 22:21] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.26780 seconds