Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Regarding Antlr rule matching
Regarding Antlr rule matching [message #1724669] Thu, 25 February 2016 06:36 Go to next message
Eclipse UserFriend
This is my grammar . There are some ambiguities but I have ignored that for now.




Model:
	greetings=Query;

Query:
	(key=QTypekeyWord)? (aggregation=Aggregation)? (measure=MeasureList) ((groupBy+=Group)? &(condition=Condtition)? &(range=Transition)?) ;


QTypekeyWord:
	qKeyword='plot'
;

Aggregation:
	agg=('average'|'number of'|'total')
;

Condtition:
	con+='for' dimVal=DimensionValue 'as' dim=Dimension ('and' dimValue=DimensionValue 'as' dimen=Dimension)* |
	conTimeCurrent= 'for this' thisTimeGroup=ThisTimeGroup |
	conlastTimePast  ='for last ' lastTimeGroup =LastTimeGroup |
	conlastNTimePast  ='for last 'INT lastNTimeGroup =LastNTimeGroup|
	conDayTimeGroup ='for' dayTimeGroup=DayTimeGroup
;

MeasureList : names+=Measure ("and" names+=Measure)*;

Measure:ID+;


Dimension:ID+;

DimensionValue:
	value=ID+
;

GroupList:
 "by" (dimGroup=Dimension("by" timeGroup+=TimeGroup)? )|timeGroup+= TimeGroup
;

Group:

	"by" ((dimGroup=Dimension("by" timeGroup+=TimeGroup)? )|timeGroup+= TimeGroup)

;

Transition:

	'from' dateStart=Date 'to' dateEnd=Date
;

TimeGroup:
	timeGroup=('day'|'week'|'month'|'quarter'|'year')
;

ThisTimeGroup:
	thisTimeGroup=('year'|'month'|'week')
 ;

LastTimeGroup:
	lastTimeGroup= ('year'|'quarter'|'month'|'week')
;

LastNTimeGroup:
	lastTimeGroup= ('days'|'weeks'|'months')
;

DayTimeGroup:
	dayTimeGroup =('today'|'yesterday')
;




Date:
	d=Day m=Month y=Year ;


Day : INT ;
Month : 'Jan'|'Feb'|'Mar'|'Apr' ;
Year : INT ;





The following test fails .

@Test
	def void testPlotMeasure1ForTime() {

		val query ="plot profit for "
		val result = parseHelper.parse(query)

		var expected =Arrays.asList("profit")

		Assert.assertEquals(result.greetings.key.getQKeyword,"plot")
		Assert.assertEquals(expected,result.greetings.measure.names)


	}



I get the error
expected:<[profit]> but was:<[profit or]>

I expect to have just profit in the measure list as "for" is a keyword in my grammar. The parser removes f and gives "profit or " as measure.

Am I missing something. please suggest.
Re: Regarding Antlr rule matching [message #1724671 is a reply to message #1724669] Thu, 25 February 2016 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Assert.assertTrue(result.eResource.errors.isEmpty)
Re: Regarding Antlr rule matching [message #1724673 is a reply to message #1724671] Thu, 25 February 2016 06:45 Go to previous messageGo to next message
Eclipse UserFriend
p.s.
as said before: never ever ever use spaces in keywords
Re: Regarding Antlr rule matching [message #1724679 is a reply to message #1724673] Thu, 25 February 2016 07:18 Go to previous messageGo to next message
Eclipse UserFriend
Ok Thank You for this Smile .I didn't know it before.Any input on how I can use a string in keywords. The idea is to have my content assist suggest multi word rather than one by one .
Re: Regarding Antlr rule matching [message #1724680 is a reply to message #1724679] Thu, 25 February 2016 07:24 Go to previous messageGo to next message
Eclipse UserFriend
you have to adapt content assist and override komplete keyword
Re: Regarding Antlr rule matching [message #1724781 is a reply to message #1724680] Thu, 25 February 2016 21:53 Go to previous messageGo to next message
Eclipse UserFriend
I have extended IdeContentProposalProvider soI do not have completeKeyword.
Re: Regarding Antlr rule matching [message #1724784 is a reply to message #1724781] Thu, 25 February 2016 23:12 Go to previous messageGo to next message
Eclipse UserFriend
Yes but it can be adapted as well. Simply digg how it handles keywords
Re: Regarding Antlr rule matching [message #1724787 is a reply to message #1724784] Fri, 26 February 2016 00:52 Go to previous messageGo to next message
Eclipse UserFriend
OK ChristianThanks for your help . Smile
I have one question regarding ID. How can I adapt it to support special characters like
Product@!Name
policy # ,etc.

Can I add on to the current definition of ID or create a new type.
Re: Regarding Antlr rule matching [message #1724788 is a reply to message #1724787] Fri, 26 February 2016 01:14 Go to previous messageGo to next message
Eclipse UserFriend
this cannot be generally ansered. either you override ID
or add your own terminal and/or datatype rule.

the intersting point is: is it a good idea to do that?
what will you do with the processed models?
Re: Regarding Antlr rule matching [message #1724790 is a reply to message #1724788] Fri, 26 February 2016 01:40 Go to previous messageGo to next message
Eclipse UserFriend
So My current words are all IDs . There is a possibility of having special characters in it. Just curious whether to enhance ID or create new types.
Re: Regarding Antlr rule matching [message #1724792 is a reply to message #1724790] Fri, 26 February 2016 01:49 Go to previous messageGo to next message
Eclipse UserFriend
it depends. one problem with simply overriding it is e.g. the topic of value conversion. so there is no general answer to that. you may even introduce a datatype rule instead of an ID

MyID hidden() : (ID | "#")+;
Re: Regarding Antlr rule matching [message #1724874 is a reply to message #1724792] Fri, 26 February 2016 11:55 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian .
Is it true that this will math either ID or #

So, Will "policy #" be matched. Similary for words like abc@$! , Should I add individual special characters one by one or include everything negating a-z 0-9 ? I wish to understand in terms of AST efficiency.
Re: Regarding Antlr rule matching [message #1724883 is a reply to message #1724874] Fri, 26 February 2016 13:30 Go to previous messageGo to next message
Eclipse UserFriend
The main point is: do you want to have these strange ids in all places or in some only. The file is first Lexed and them parsed. The lexer does not know anything about context. Thus I cannot lex abc as specialid and as Id. I cannot tell about lexing. Efficient. Maybe you can use.

Terminal STUFF: ....;
MyID: STUFF | ID.

I'd recommend no to take everything into stuff.
Re: Regarding Antlr rule matching [message #1724909 is a reply to message #1724883] Fri, 26 February 2016 20:03 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the explanation Christian.
do you want to have these strange ids in all places or in some only ?
Yes the ids I am referring are basically product names. So ,it could be anything (including !@#$%) and other special characters and they can exist at places where I am currently using IDs.

So, in my java code. I support it including like "SPECIAL_CHAR_PATTERN="^A-Za-z0-9_\\[\\]{}!@#$%^&*()~`<>+,.?/':;\\-\" ";"

I am looking something similar to enhance my ID

[Updated on: Fri, 26 February 2016 20:03] by Moderator

Re: Regarding Antlr rule matching [message #1724919 is a reply to message #1724909] Sat, 27 February 2016 02:01 Go to previous messageGo to next message
Eclipse UserFriend
Did you consider to simply use STRING
Re: Regarding Antlr rule matching [message #1724997 is a reply to message #1724919] Sun, 28 February 2016 22:30 Go to previous messageGo to next message
Eclipse UserFriend
Yes I have tried STRING .
All tests are failing. The content of Measure List is null. Am I missing something.

@Test
	def void testMeasure() {

		val query="comm"
		val result = parseHelper.parse(query)

		var expected =Arrays.asList("comm")
		Assert.assertEquals(expected,result.getMeasureList)

	}


	def List<String> getMeasureList(Model result){

		return result.greetings.measure.names.toList

	}
Re: Regarding Antlr rule matching [message #1725001 is a reply to message #1724997] Mon, 29 February 2016 00:38 Go to previous messageGo to next message
Eclipse UserFriend
In a string your model would be "comm" ????
Re: Regarding Antlr rule matching [message #1725014 is a reply to message #1725001] Mon, 29 February 2016 02:38 Go to previous message
Eclipse UserFriend
yes.
Previous Topic:Xtext web editor -- semantic highlighting
Next Topic:Checking if JvmFormalParameter isAssignableFrom XExpression
Goto Forum:
  


Current Time: Sun Jul 13 16:18:56 EDT 2025

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

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

Back to the top