Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialization/Formatter Problem
Serialization/Formatter Problem [message #1005415] Fri, 25 January 2013 11:04 Go to next message
Christian Schlegel is currently offline Christian SchlegelFriend
Messages: 4
Registered: September 2012
Junior Member
Hi!

I have a problem i am not getting around. I created a DSL from an existing Ecore model. I also added an external lexer like in the mwe2 project to make use of sematic predicates. Everthing is working as expected, that means textual model editor and creation of underlying EMF-model and vice versa. The only thing is, that if i serialize an EMF-model, no whitspaces are added between tokens and the formatter does nothing. The whole model is serialized as one big character-sequence.

My question - what is causing this and how to fix it. Did i miss anything in my workflow?

I am using Xtext 2.3.1.

module r3d.targetlanguage.android.Android

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/r3d/targetlanguage/android/Android.xtext"
var file.extensions = "java"
var projectName = "r3d.targetlanguage.android"
var runtimeProject = "../${projectName}"
var uiProject = "${runtimeProject}.ui"

Workflow {
	bean = StandaloneSetup {
		scanClassPath  = true
		platformUri = "${runtimeProject}/.."
		registerGeneratedEPackage = "r3d.metamodel.androidApplicationModel.AndroidApplicationModelPackage"
//	 	registerGenModelFile = "platform:/resource/r3d.metamodel.androidApplication/metamodel/androidApplicationModel.genmodel"
	
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}/src-gen"
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}.ui/src-gen"
	}

	component = Generator {
		pathRtProject = runtimeProject
		pathUiProject = "${runtimeProject}.ui"
		projectNameRt = projectName
		projectNameUi = "${projectName}.ui"
		language = {
			uri = grammarURI
			fileExtensions = file.extensions

			// Java API to access grammar elements (required by several other fragments)
			fragment = grammarAccess.GrammarAccessFragment {}

			// generates Java API for the generated EPackages
			// fragment = ecore.EcoreGeneratorFragment {}

			// the serialization component
			fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

			// a custom ResourceFactory for use with EMF 
			fragment = resourceFactory.ResourceFactoryFragment {
				fileExtensions = file.extensions
			}
			
//			// the Antlr parser
//			fragment = parser.antlr.XtextAntlrGeneratorFragment {
//				options = {
//					classSplitting = true
//				}
//			}
			
			// the Antlr parser with external lexer
			fragment = parser.antlr.ex.rt.AntlrGeneratorFragment {}
			fragment = parser.antlr.ex.ExternalAntlrLexerFragment {
					lexerGrammar = "r3d.targetlanguage.android.lexer.AndroidLexer"
					runtime = true
					antlrParam = "-lib"
					antlrParam = "${runtimeProject}/src-gen/r3d/targetlanguage/android/parser/antlr/lexer"
			}

			// the Ecore2Xtext specific terminal converter
			fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment {}

			// java-based API for validation 
			fragment = validation.JavaValidatorFragment {
			// composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
			// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}

			// scoping and exporting API
			fragment = scoping.ImportURIScopingFragment {}
			fragment = exporting.SimpleNamesFragment {}

			// scoping and exporting API 

			// fragment = scoping.ImportNamespacesScopingFragment {}
			// fragment = exporting.QualifiedNamesFragment {}


			// formatter API 
			fragment = ecore2xtext.FormatterFragment {}

			// labeling API 
			fragment = labeling.LabelProviderFragment {}

			// outline API 
            fragment = outline.OutlineTreeProviderFragment {}
            fragment = outline.QuickOutlineFragment {}

			// java-based API for content assistance 
			fragment = contentAssist.JavaBasedContentAssistFragment {}
			
//			// antlr parser generator tailored for content assist 
//			fragment = parser.antlr.XtextAntlrUiGeneratorFragment {
//				options = {
//					classSplitting = true
//				}
//			}

			// antlr parser generator for content assist (and highlighting) with external lexer
			fragment = org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment	{}
//			fragment = parser.antlr.ex.ExternalAntlrLexerFragment {
//					lexerGrammar = "r3d.targetlanguage.android.ui.highlighting.AndroidHighlightingLexer"
//					highlighting = true
//			}
			fragment = parser.antlr.ex.ExternalAntlrLexerFragment {
					lexerGrammar = "r3d.targetlanguage.android.ui.contentassist.AndroidContentAssistLexer"
					contentAssist = true
					antlrParam = "-lib"
					antlrParam = "${uiProject}/src-gen/r3d/targetlanguage/android/ui/contentassist/antlr/lexer"
			}

			

			// provides a compare view
            fragment = compare.CompareFragment {
                fileExtensions = file.extensions
            }

			fragment = builder.BuilderIntegrationFragment {}

			// project wizard (optional) 

			// fragment = projectWizard.SimpleProjectWizardFragment {
			//		generatorProjectName = "${projectName}.generator" 
			//		modelFileExtension = file.extensions
			// }

			// quickfix API 
			fragment = quickfix.QuickfixProviderFragment {}
		}
	}
}
Re: Serialization/Formatter Problem [message #1005492 is a reply to message #1005415] Fri, 25 January 2013 16:52 Go to previous message
Christian Schlegel is currently offline Christian SchlegelFriend
Messages: 4
Registered: September 2012
Junior Member
Hi again!

After troubleshooting the whole day, i found the bug (maybe it is not). Because of my external lexer, i redefined simple terminal rules like whitespaces and did not import the xtext default terminals in my xtext grammar. Because i do not like shortcuts i renamed the WS terminal rule to WHITESPACE. This caused the "formatterTokenStream.hiddenTokenHelper" in "org.eclipse.xtext.parsetree.reconstr.Serializer#60" to have an "wsRule" with null. Thus, no whitespces where put between tokens on serialization. After i renamed the temrinal rule to WS, "wsRule" (from above) is defined and serilization and formatting works well.

So my questions are - is it allowd to rename the WS terminal rule at all in an xtext grammar? Maybe is this a special case, only if one uses an external lexer? Or is this a general bug and should i report it?

Edit: Ok. Now i recognized the function setWhitespaceRule in the FormatterConfig and everthing is clear. Stupid me!

[Updated on: Fri, 25 January 2013 19:26]

Report message to a moderator

Previous Topic:Compile Xtext-generated DSL from command line
Next Topic:Access to Resource URI within QuickfixProvider
Goto Forum:
  


Current Time: Fri Apr 26 15:26:28 GMT 2024

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

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

Back to the top