Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Request Guidance on Best Practice for Parsing/Content Assist
Request Guidance on Best Practice for Parsing/Content Assist [message #1776811] Tue, 21 November 2017 20:36 Go to next message
Christoff Erasmus is currently offline Christoff ErasmusFriend
Messages: 14
Registered: December 2016
Junior Member
Hello,
What is the best practice for dealing with the code snippet below.

Looking for guidance regarding

  • Parsing
  • Content Assist


Based on the responses I should be able to figure out ( but pointer would be appreciated)

  • Validation
  • QuickFix
  • Value Converter (if required)


KeywordDATE: {KeywordDATFMT} 
	'DATE' ('('
		//2-Digit Year Formats
		(format='*MDY' separator=('/'|'-'|'.'|','|'&')?)  |
		(format='*DMY' separator=('/'|'-'|'.'|','|'&')?)  |
		(format='*YMD' separator=('/'|'-'|'.'|','|'&')?)  |
		(format='*JUL' separator=('/'|'-'|'.'|','|'&')?)  |
		//4-Digit Year Formats
		(format='*ISO' separator=('-')?) |
		(format='*USA' separator=('/')?) |
		(format='*EUR' separator=('.')?) |
		(format='*JIS' separator=('-')?)			 
	')')?;
;

KeywordTIME: {KeywordTIME}
	'TIME' ('('
		(format='*HMS' separator=(':'|'.'|','|'&')?) | 
		(format='*ISO' separator=('.')?)             |
		(format='*USA' separator=(':')?)             |
		(format='*EUR' separator=('.')?)             |
		(format='*JIS' separator=(':')?)			 
	')')?
;
Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776812 is a reply to message #1776811] Tue, 21 November 2017 20:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
Hmmm I don't really get your question. Can you please be more specific

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776890 is a reply to message #1776812] Wed, 22 November 2017 14:49 Go to previous messageGo to next message
Christoff Erasmus is currently offline Christoff ErasmusFriend
Messages: 14
Registered: December 2016
Junior Member
@Christian,

The refactored the snippet (see below) has 2 issues
1) The Content Assist does not recommend either the DATSEP or the TIMSEP as options
2) The .mwe2 workflow gives the following error message :
Quote:

error(208): ../bz.erasmus.x400.xrpgle.xtext/src-gen/bz/erasmus/x400/xrpgle/xtext/parser/antlr/lexer/InternalXRPGLELexer.g:74:1: The following token definitions can never be matched because prior tokens match the same input: RULE_TIMSEP

error(208): ../bz.erasmus.x400.xrpgle.xtext.ide/src-gen/bz/erasmus/x400/xrpgle/xtext/ide/contentassist/antlr/lexer/InternalXRPGLELexer.g:74:1: The following token definitions can never be matched because prior tokens match the same input: RULE_TIMSEP


My question:
What is most "correct" way of dealing with the grammar rule?


The Refactored Code Snippet:
KeywordDATE: {KeywordDATE}
	'DATE' ('(' format=DATFMT (separator=DATSEP)? ')')?
;
enum DATFMT:
	MDY = '*MDY' |
	DMY = '*DMY' |
	YMD = '*YMD' |
	JUL = '*JUL' |
	ISO = '*ISO' |
	USA = '*USA' |
	EUR = '*EUR' |
	JIS = '*JIS'
;
terminal DATSEP returns ecore::EChar:
	'/'|'-'|'.'|','|'&'
;
KeywordTIME: {KeywordTIME}
	'TIME' ('(' format=TIMFMT (separator=TIMSEP)? ')')?
;
enum TIMFMT:
	HMS = '*HMS' |
	ISO = '*ISO' |
	USA = '*USA' |
	EUR = '*EUR' |
	JIS = '*JIS'
;
terminal TIMSEP returns ecore::EChar:
	':'|'.'|','|'&'
;

[Updated on: Wed, 22 November 2017 14:51]

Report message to a moderator

Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776899 is a reply to message #1776890] Wed, 22 November 2017 15:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
this error says your grammar is ambious. there is no general solutiion to this since it depends on the individual case. so a best practice is the wrong thing to ask for. your original snippet did no even contain TIMSEP
but having the same stuff as keywords and as terminals wont work. thus your solution seems legit (grammar snippets quite incomplete)


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776909 is a reply to message #1776899] Wed, 22 November 2017 17:02 Go to previous messageGo to next message
Christoff Erasmus is currently offline Christoff ErasmusFriend
Messages: 14
Registered: December 2016
Junior Member
@Christian,

The ambiguity is caused when DATFMT and TIMFMT is defined together (refer option2 in the grammar below).

Your previous post, confused me a bit. Do you recommend option1 or option2 or maybe a different approach?

My end-goal is to parse the "Date Keyword" from the RPGLE language, but I am struggling with the translation of the info on IBM's knowledge center into xtext grammer.
Links to the Knowledge center:
* Date Keyword - Parsing
* Date Data Type - Validation

More complete grammer
Model:
variabledeclarations+=StandAloneField
;

StandAloneField:
	'DCL-S' name=ID type=DataType keywords+=StandAloneFieldKeywords* (';')? 
;
StandAloneFieldKeywords:
	placeholder= 'StandAloneFieldKeywords'
;
DataType:
//	CharacterDataType	|
//	NumericDataType		|
	DateTimeDataType	
;
DateTimeDataType:
//	KeywordTIMESTAMP |
//	KeywordTIME      |
	KeywordDATE			

;
//---------------------------------------------------------------------------
// Option 1:
KeywordDATE: {KeywordDATE} 
	'DATE' ('('
		//2-Digit Year Formats
		(format='*MDY' separator=('/'|'-'|'.'|','|'&')?) |
		(format='*DMY' separator=('/'|'-'|'.'|','|'&')?) |
		(format='*YMD' separator=('/'|'-'|'.'|','|'&')?) |
		(format='*JUL' separator=('/'|'-'|'.'|','|'&')?) |
		//4-Digit Year Formats
		(format='*ISO' separator=('-')?)	|
		(format='*USA' separator=('/')?)	|
		(format='*EUR' separator=('.')?)	|
		(format='*JIS' separator=('-')?)			 
	')')?
;
KeywordTIME: {KeywordTIME}
	'TIME' ('('
		(format='*HMS' separator=(':'|'.'|','|'&')?)	| 
		(format='*ISO' separator=('.')?)				|
		(format='*USA' separator=(':')?)			 	|
		(format='*EUR' separator=('.')?)			 	|
		(format='*JIS' separator=(':')?)			 
	')')?
;
//------------------------------------------------------------------------
// Option2:
KeywordDATE: {KeywordDATE}
	'DATE' ('(' format=DATFMT (separator=DATSEP)? ')')?
;
enum DATFMT:
	ISO = '*ISO' |
	MDY = '*MDY' |
	DMY = '*DMY' |
	YMD = '*YMD' |
	JUL = '*JUL' |
	USA = '*USA' |
	EUR = '*EUR' |
	JIS = '*JIS'
;
terminal DATSEP returns ecore::EChar:
	'/'|'-'|'.'|','|'&'
;
KeywordTIME: {KeywordTIME}
	'TIME' ('(' format=TIMFMT (separator=TIMSEP)? ')')?
;
enum TIMFMT:
	ISO = '*ISO' |
	HMS = '*HMS' |
	USA = '*USA' |
	EUR = '*EUR' |
	JIS = '*JIS'
;
terminal TIMSEP returns ecore::EChar:
	':'|'.'|','|'&'
;

Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776910 is a reply to message #1776909] Wed, 22 November 2017 17:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
id prefer option 2, maybe replaced by a datatype rule (+ custom content assist) e.g.

// no terminal keyword
TIMSEP returns ecore::EChar:
':'|'.'|','|'&'
;


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776920 is a reply to message #1776811] Wed, 22 November 2017 19:51 Go to previous message
Christoff Erasmus is currently offline Christoff ErasmusFriend
Messages: 14
Registered: December 2016
Junior Member
Thanks for the guidance.
Will give Option2 a shot.
Previous Topic:Error: Cyclic resolution of lazy links
Next Topic:Remove warning/error marker
Goto Forum:
  


Current Time: Tue Apr 24 21:16:26 GMT 2018

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

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