|
|
Re: Request Guidance on Best Practice for Parsing/Content Assist [message #1776890 is a reply to message #1776812] |
Wed, 22 November 2017 14:49 |
Christoff Erasmus Messages: 32 Registered: December 2016 |
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 #1776909 is a reply to message #1776899] |
Wed, 22 November 2017 17:02 |
Christoff Erasmus Messages: 32 Registered: December 2016 |
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:
':'|'.'|','|'&'
;
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05857 seconds