Request Guidance on Best Practice for Parsing/Content Assist [message #1776811] |
Tue, 21 November 2017 15:36  |
Eclipse User |
|
|
|
Hello,
What is the best practice for dealing with the code snippet below.
Looking for guidance regarding
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 #1776909 is a reply to message #1776899] |
Wed, 22 November 2017 12:02   |
Eclipse User |
|
|
|
@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:
':'|'.'|','|'&'
;
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04470 seconds