Skip to main content



      Home
Home » Modeling » TMF (Xtext) » grammar
grammar [message #1070748] Thu, 18 July 2013 11:31 Go to next message
Eclipse UserFriend
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 16:20 Go to previous messageGo to next message
Eclipse UserFriend
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 16:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi

for custom datatype rules and terminals you simply have to override the corresponding method in the proposal provider
Re: grammar [message #1070849 is a reply to message #1070845] Thu, 18 July 2013 16:24 Go to previous messageGo to next message
Eclipse UserFriend
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 16:26 Go to previous messageGo to next message
Eclipse UserFriend
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 16:32 Go to previous messageGo to next message
Eclipse UserFriend
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 16:45 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: grammar [message #1070868 is a reply to message #1070859] Thu, 18 July 2013 17:13 Go to previous messageGo to next message
Eclipse UserFriend
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 18:04 Go to previous messageGo to next message
Eclipse UserFriend
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 #
Re: grammar [message #1070895 is a reply to message #1070886] Thu, 18 July 2013 18:44 Go to previous messageGo to next message
Eclipse UserFriend
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 19:16 Go to previous message
Eclipse UserFriend
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: Wed Jul 02 16:15:52 EDT 2025

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

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

Back to the top