star files and Decision can match input such as [message #1828187] |
Wed, 03 June 2020 12:34 |
gary s thompson Messages: 92 Registered: July 2009 |
Member |
|
|
Dear all
sorry some rather a newby, questions which I am sure has been answered many times before. I am trying to implement a parser for STAR files a scientific format, details below
I have the following code:
grammar uk.ac.ccpn.neftools.Star
hidden(WS, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate star "http://www.ac.uk/ccpn/neftools/Star"
Star_file:
blocks+=Data_block*;
terminal SL_COMMENT : '#' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;
terminal fragment NON_BLANK_CHAR:
('!'..'^' | '\''..'~')
;
terminal SAVE:
'save_'
;
terminal DATA_HEADING:
'data_' NON_BLANK_CHAR+
;
terminal DATA_NAME:
'_' NON_BLANK_CHAR+
;
terminal NON_QUOTED_TEXT_STRING:
(!'_') (NON_BLANK_CHAR)+
;
Data_block:
heading = DATA_HEADING (bodies+= Data_block_body)+
;
Data_block_body:
data+=(Data)+
;
Data:
name=DATA_NAME value=NON_QUOTED_TEXT_STRING
;
but have several problems
1. The most pressing
warning(200): ../uk.ac.ccpn.neftools/src-gen/uk/ac/ccpn/neftools/parser/antlr/internal/InternalStar.g:188:2: Decision can match input such as "RULE_DATA_NAME" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../uk.ac.ccpn.neftools.ide/src-gen/uk/ac/ccpn/neftools/ide/contentassist/antlr/internal/InternalStar.g:125:42: Decision can match input such as "RULE_DATA_NAME RULE_NON_QUOTED_TEXT_STRING" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
I have seen plenty of discussion of what the problem is here, and it appears that the tokenizer(?) is finding mutiple ways to tokenize my code (?) I have read that predicates can solve this but don't see quite where I have to change things
2. I don't seem to be allowed to have whitespace at the start of a file before a Data_block
3. I had to re define what IDs and strings are because they don't fit in with the syntax of the star file and especially the character ranges used and the definition of an INT, but I don't really folllow how an ID and a String are defined in common terminals
ID is defined as
terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
and STRING as
terminal STRING:
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
I can understand how id is defined its just text ranges with the first letter not being allowed to be a number, but string seems a bit baffling...
can someone explain and also is what I am doing the right approach
any help gratefully received
regards
Gary
nb I also checked things an antlrworks (image attached)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02973 seconds