Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » star files and Decision can match input such as
star files and Decision can match input such as [message #1828187] Wed, 03 June 2020 12:34 Go to next message
gary s thompson is currently offline gary s thompsonFriend
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)















Re: star files and Decision can match input such as [message #1828209 is a reply to message #1828187] Thu, 04 June 2020 06:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Data_block:
heading = DATA_HEADING (bodies+= Data_block_body)+
;

Data_block_body:
data+=(Data)+
;

if you have two data. will these become two Data_block_body or two (bodies+= Data_block_body)+


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: star files and Decision can match input such as [message #1828215 is a reply to message #1828187] Thu, 04 June 2020 08:56 Go to previous message
gary s thompson is currently offline gary s thompsonFriend
Messages: 92
Registered: July 2009
Member
Dear Christian

Thank you so much, I was barking up completely the wrong tree and this solves the problem. As you explained the original syntax from the original paper had a degenerate definition.

<data_block_body>              ::= (data | save_frame)+
<data>                         ::= data_name data_value | <data_loop>
<data_block>                   ::= <data_heading> <data_block_body>+
<data_name>                    ::= _<non_blank_char>+
<data_heading>                 ::= data_<non_blank_char>+
<save_frame>                   ::= <save_heading> <data>+


I now have
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 STRING:
			'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
			"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
		;
terminal SL_COMMENT : '#' !('\n'|'\r')* ('\r'? '\n')?;

terminal WS         : (' '|'\t'|'\r'|'\n')+;

terminal ANY_OTHER: .;


//TODO: the range here isn't quite right it doesn't include '
terminal fragment NON_BLANK_CHAR:
	('!'..'^' | '\''..'~')	
;




terminal SAVE:
 	'save_'
;

terminal DATA_HEADING:
 	'data_' NON_BLANK_CHAR+
;  

terminal SAVE_HEADING:
	SAVE  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|Save_frame
;

Data:
	name=DATA_NAME value=NON_QUOTED_TEXT_STRING
;

Save_frame:
	heading=SAVE_HEADING (data+=Data)+ SAVE
;



and this works. So on to finding out that causes my no white space problem, which seems to be quite odd. I am allowed two spaces in front of a heading or a comment at the start of a file but not one!

regards
Gary
Previous Topic:[solved] Indentation of elements in EList using formatting2 API
Next Topic:How to add a JvmFormalParameter with Java Ellipsis Type
Goto Forum:
  


Current Time: Thu Apr 25 21:34:59 GMT 2024

Powered by FUDForum. Page generated in 0.03803 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top