Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext with content dependent grammar
Xtext with content dependent grammar [message #1738740] Fri, 22 July 2016 19:39 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Hi, all
I woud like to use xtext with content dependent grammar.
I will create grammar like any symbols, but parse it in the validator and formatter.
In this way I will use xtext abilities to bind my editor with eclipse infrastructure.

There are my questions:
1) Do I can to to throw error or warning have only error message and start and and position in the text. Something like this error("My message", startPos,endPos) if yes may I ask to provide me some examples?
2) Do I can to create custom formatter with break my code, insert tabs after some position in the text? And I also want examples if I can
3) Do I can to create custom code hilighting. Something like folowing hilight(startPos:Int, endPos:Int,color)

Regards,
Vladimir
Re: Xtext with content dependent grammar [message #1738747 is a reply to message #1738740] Fri, 22 July 2016 20:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14654
Registered: July 2009
Senior Member
Hi,

i am not sure if i get your questions

(1) have a look at org.eclipse.xtext.validation.AbstractDeclarativeValidator.acceptError(String, EObject, int, int, String, String...)
(2) can you come up with a example grammar and a expected output - but generally it is possible to indent blocks
formatter = {
	generateStub = true
}

class MyDslFormatter extends AbstractFormatter2 {
	
	@Inject extension MyDslGrammarAccess

	def dispatch void format(Domainmodel domainmodel, extension IFormattableDocument document) {
		// TODO: format HiddenRegions around keywords, attributes, cross references, etc. 
		for (Type elements : domainmodel.getElements()) {
			elements.format;
		}
	}

	def dispatch void format(Entity entity, extension IFormattableDocument document) {
		entity.regionFor.keyword(entityAccess.entityKeyword_0).prepend[newLine]
		entity.regionFor.keyword(entityAccess.leftCurlyBracketKeyword_3).append[newLine]
		entity.regionFor.keyword(entityAccess.rightCurlyBracketKeyword_5).prepend[newLine]
		interior(
			entity.regionFor.keyword(entityAccess.leftCurlyBracketKeyword_3).append[newLine],
			entity.regionFor.keyword(entityAccess.rightCurlyBracketKeyword_5).prepend[newLine]
		
		) [indent]
		for (Feature features : entity.getFeatures()) {
			features.format;
		}
	}
	
	def dispatch void format(Feature f, extension IFormattableDocument document) {
		f.prepend[newLine]
	}
	
	def dispatch void format(DataType dt, extension IFormattableDocument document) {
		dt.regionFor.keyword(dataTypeAccess.datatypeKeyword_0).prepend[newLine]
	}
	
}

(3)
yes you can. this is called semantic highlighting. http://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#highlighting


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext with content dependent grammar [message #1738749 is a reply to message #1738747] Fri, 22 July 2016 21:20 Go to previous messageGo to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Thank you for the quick reply

Generally I need to develop grammar when rules of the parsing of current block contains in the previous block

For example, if I have
a|b|<<BLOCK|c
a, b is contend independent part of the grammar. But during parsing
I can see that block c will starts from <<BLOCK and ends with BLOCK. So, my grammar is content dependent.
I already have parser for my grammar, but woud like to use xtext from formatting. And I'm afraid that my blocks is just lexems.
So, is it good idea to decide do I need make formatting depends of each lexems? Or maybe there is more elegant solution?

[Updated on: Fri, 22 July 2016 21:22]

Report message to a moderator

Re: Xtext with content dependent grammar [message #1738750 is a reply to message #1738749] Fri, 22 July 2016 21:37 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14654
Registered: July 2009
Senior Member
what about using a custom lexer that is stateful?

( i actually do not have a real idea what your lexing / parsing problem is)
can you give a better example


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 22 July 2016 21:38]

Report message to a moderator

Previous Topic:Xtext Cell Editor
Next Topic:Cross-reference: a set of constants of Enum
Goto Forum:
  


Current Time: Fri Mar 01 03:55:21 GMT 2024

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

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

Back to the top