Xtext with content dependent grammar [message #1738740] |
Fri, 22 July 2016 19:39  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
Re: Xtext with content dependent grammar [message #1738749 is a reply to message #1738747] |
Fri, 22 July 2016 21:20   |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04535 seconds