Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar
grammar [message #1070748] Thu, 18 July 2013 15:31 Go to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
HI,
Has anyone try to define a grammar rule which could accept any characters?
I am trying, but cannot do it myself:
I want define a single rule for all content, and each line of content would be one element. Then use the framework provided by xtext to do the content assist, coloring, validation and so on...

However, I have no idea to define such a rule:
('a'..'z'|'A'..'Z'|'#'|'!') (.)+ ('\r\n'|'\n')

this could do a similar job, but each line is not recognized in this rule until seeing ('\r\n'|'\n'). so the content assist cannot be applied.

BTW, how can I not to use the default terminal rules? removing "with org.eclipse.xtext.common.Terminals" will lead to the disability of defining new terminal rule.

Many Thanks

sincerely,
YM
Re: grammar [message #1070845 is a reply to message #1070748] Thu, 18 July 2013 20:20 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
Does anyone know how to provide content assist for non-recognized content?
if i use this:
('a'..'z'|'A'..'Z'|'#'|'!') (.)+ ('\r\n'|'\n')

it won't be recognized as an element until ('\r\n'|'\n')

but i want to provide content assist before that~

thanks
Re: grammar [message #1070847 is a reply to message #1070845] Thu, 18 July 2013 20:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

for custom datatype rules and terminals you simply have to override the corresponding method in the proposal provider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar [message #1070849 is a reply to message #1070845] Thu, 18 July 2013 20:24 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
it would be quite limited if I can only provide content assist for recognized element~
Re: grammar [message #1070853 is a reply to message #1070847] Thu, 18 July 2013 20:26 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
But code like this:
if(line.input.startsWith('#')){
val proposal = 'include'
acceptor.accept(createCompletionProposal(proposal, context))
}
does not do the job.

am i wrong ?
Re: grammar [message #1070855 is a reply to message #1070847] Thu, 18 July 2013 20:32 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
hi Chris,
This is my grammar,
LCFGModel:
(elements+=Line)*
;

Line :
input = INPUT
;

terminal INPUT:
START (.)* END
;
terminal END:
'\r\n'|'\n'
;

terminal START:
'!'|'#'|'a'..'z'| 'A'..'Z'
;

Actually i want it to accept any character in each line and process each line with my customized code.

Do you have any other feasible way to do this?

Re: grammar [message #1070859 is a reply to message #1070855] Thu, 18 July 2013 20:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the proposalprovider is the (only) hook.

btw

class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override complete_INPUT(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.complete_INPUT(model, ruleCall, context, acceptor)
		if (context.prefix.startsWith("#")) {
			acceptor.accept(createCompletionProposal("#include",context))
		}
	}
	
}


works for me


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar [message #1070868 is a reply to message #1070859] Thu, 18 July 2013 21:13 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
Great Thanks.

But i have some puzzles:
the complete{TypeName}_{FeatureName} applies to feature of type, and complete_{RuleName} applies to rule. Why does complete_INPUT work instead of completeLine_Input?

what does "context" mean here? anything i have typed in so far?

thank you
Re: grammar [message #1070886 is a reply to message #1070868] Thu, 18 July 2013 22:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi there a multiple methods that apply
The Context gives you Information about where you are
I gutes in your Case the Problem was that your proposal did Not include the #


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar [message #1070895 is a reply to message #1070886] Thu, 18 July 2013 22:44 Go to previous messageGo to next message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
No, proposal "#include" does not work either.

I thought the reason why mine doesn't work is : the rule is not recognized until "\r\n" is typed, then the complete method can be applied.
However, since yours works, i guess this is not the reason.

Nevertheless, THANKS~! Very Happy
Re: grammar [message #1070904 is a reply to message #1070895] Thu, 18 July 2013 23:16 Go to previous message
Yueming Hong is currently offline Yueming HongFriend
Messages: 87
Registered: April 2013
Member
I found the reason:
I used
completeLine_Input(Input input ...) instead of
completeLine_Input(EObject model...)

Sad
Previous Topic:Need some direction to add JsonPath helper into Java file
Next Topic:Unresolved reference in editor when importing
Goto Forum:
  


Current Time: Tue Apr 16 20:55:59 GMT 2024

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

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

Back to the top