Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » New to Xtext Grammar help(UI InternalDsl.g error.)
New to Xtext Grammar help [message #967161] Thu, 01 November 2012 14:42 Go to next message
Adam Chase is currently offline Adam Chase
Messages: 6
Registered: October 2012
Junior Member
I wanted to be the new guy that didn't ask the grammar question, but here I am.

I downloaded AntlrWorks and used it on the InternalDsl.g files (both ui and not) and it was able to generate a parser for both, so I don't know what the problem is exactly. I have selectively commented different parts of this grammar out trying to find the simplest case that doesn't work, but I am finding this approach is not helping me to understand the problem. I am trying to match an existing format, so any suggestions on simplifying the file format are not soo useful to me.

This xtext was downloaded recently via eclipse-SDK-4.2-Xtext-2.3.1-linux-gtk-x86_64.tar.gz

AntlrWorks via antlrworks-1.4.3.jar

..ui/contentassist/antlr/internal/InternalDsl.g:3727:36: Decision can match input such as "'field'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

..ui/contentassist/antlr/internal/InternalDsl.g:3727:36: The following alternatives can never be matched: 2

Any help will be rewarded with gracious praise and whatever karma I can redirect your way.

the relevant parts of the grammar:

Dsl:
elements+=AbstractElement*;

AbstractElement: ParameterSet;

enum FieldDataType :
scalar = "FIELD_IS_UVAL_SCALAR"
|string = "FIELD_IS_STRING"
|psetList = "FIELD_IS_PSET_LIST"
|pset = "FIELD_IS_PSET"
|label = "FIELD_IS_LABEL"
|opaque = "FIELD_IS_OPAQUE"
|checkBox = "FIELD_IS_CHECK_BOX"
|choice = "FIELD_IS_CHOICE_LIST"
|path = "FIELD_IS_PATHNAME"
|unit = "FIELD_IS_UNIT"
|number = "FIELD_IS_NUMBER"
|color = "FIELD_IS_COLOR"
|geometry = "FIELD_IS_GEOMETRY_PSET"
|uval = "FIELD_IS_UVAL"
;

enum PfieldFlag:
eqnAllowed = "FIELD_EQUATION_ALLOWED"
| isInput = "FIELD_INPUT"
| notDiscretized = "FIELD_NOT_DISCRETIZED"
| deleteIfPsetDeleted = "FIELD_DELETE_IF_PSET_DELETED"
| isRequired = "FIELD_REQUIRED"
| isHidden = "FIELD_HIDDEN"
| isSaveFilename = "FIELD_IS_SAVE_FILENAME"
| pointsToOwnFamily = "FIELD_POINTS_TO_OWN_FAMILY"
| useRequiredLabelFont = "FIELD_USE_REQUIRED_LABEL_FONT"
| spaceVaryingAllowed = "FIELD_SPACE_VARYING_ALLOWED"
| timeVaryingAllowed = "FIELD_TIME_VARYING_ALLOWED"
| isDirectory = "FIELD_IS_DIRECTORY"
| offsetPsetAllowed = "FIELD_OFFSET_PSET_ALLOWED"
| hasSecondaryField = "FIELD_HAS_SECONDARY_FIELD"
| noSwitchWarning = "FIELD_NO_SWITCH_WARNING"
;

enum PsetFlag:
allowIncomplete = "PSET_ALLOW_INCOMPLETE"
| notDiscretized = "PSET_NOT_DISCRETIZED"
;


PfieldFlags:
(flags+=PfieldFlag)
| (flags+=PfieldFlag '|')+ flags+=PfieldFlag
;

PsetFlags:
(flags+=PsetFlag )
| (flags+=PsetFlag '|')+ flags+=PsetFlag
;

StringArray:
('[' elements+=STRING ']')
| ('[' (elements+=STRING ',')+ elements+=STRING ']')
;


PsetField: "field" name=ID '{'
(("label" '=' label?=STRING ';')? &
("short_label" '=' short_label?=STRING ';')? &
("label_w_details" '=' label_w_details?=STRING ';')? &
("datatype" '=' dataType?=FieldDataType ';')? &
("unit_class" '=' unitClass?=STRING ';')? &
("default" '=' default?=STRING ';')? &
("indent" '=' indent?=INT ';')? &
("pfamily_identifier" '=' familyIdentifier?=STRING ';')? &
("pset_identifier" '=' psetIdentifier?=STRING ';')? &
("flags" '=' flags?=PfieldFlags ';')? &
("init_val" '=' initVal?=STRING ';')? &
("enabled_if" '=' enabledIf?=StringArray ';')? &
("visible_if" '=' visibleIf?=StringArray ';')? &
("group" '=' group?=STRING ';')? &
("choices" '=' choices?=StringArray ';')? &
("filters" '=' filters?=StringArray ';')? &
("custom_unit0" '=' customUnit?=STRING ';')?)
'}'
;

PsetFieldArray:
('[' fields+=PsetField ']')
| ('[' (fields+=PsetField ',')+ fields+=PsetField ']')
;

ParameterSet:
'parameter_set' name=ID (':' parentPset=[ParameterSet])? '{'
(("label" '=' label?=STRING ';')? &
("short_label" '=' shortlabel?=STRING ';')? &
("fields" '=' fieldArray?=PsetFieldArray ';')? &
("flags" '=' flags?=PsetFlags ';')?)
'}'
';';


Thanks in advance

Re: New to Xtext Grammar help [message #967623 is a reply to message #967161] Thu, 01 November 2012 22:34 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2899
Registered: July 2009
Senior Member
Am 01.11.12 15:42, schrieb Adam Chase:
> PsetFieldArray: ('[' fields+=PsetField ']')
> | ('[' (fields+=PsetField ',')+ fields+=PsetField ']')
> ;

Hi Adam,

this one looks overly complicated to me. Even though it's not exactly
ambiguous, I suggest to rewrite the rule to the simpler variant

PsetFieldArray: '[' fields+=PsetField (',' fields+=PsetField)* ']';

You used the same pattern for PsetFlags and StringArray. I'd rewrite
those, too.

There are other issues, e.g. you use a boolean assignement
fieldArray?=PsetFieldArray which will pretty much discard the rhs of the
assignment. These deserve a clean-up, too.

I hope these tips help.

Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: New to Xtext Grammar help [message #967753 is a reply to message #967623] Fri, 02 November 2012 01:08 Go to previous message
Adam Chase is currently offline Adam Chase
Messages: 6
Registered: October 2012
Junior Member
Thanks Sebastian, the grammar looks cleaner now and my error has gone away. I was using the ?= totally incorrectly. Not sure how I got that idea in my head. Thanks so much for your time.
Previous Topic:Xbase and changed package names ?
Next Topic:Xtend2 fails initializing String[]
Goto Forum:
  


Current Time: Mon Oct 20 11:28:37 GMT 2014

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

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