Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Regarding Antlr rule matching
Regarding Antlr rule matching [message #1724669] Thu, 25 February 2016 11:36 Go to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 11:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Assert.assertTrue(result.eResource.errors.isEmpty)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724673 is a reply to message #1724671] Thu, 25 February 2016 11:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
p.s.
as said before: never ever ever use spaces in keywords


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724679 is a reply to message #1724673] Thu, 25 February 2016 12:18 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 12:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you have to adapt content assist and override komplete keyword

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724781 is a reply to message #1724680] Fri, 26 February 2016 02:53 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
I have extended IdeContentProposalProvider soI do not have completeKeyword.
Re: Regarding Antlr rule matching [message #1724784 is a reply to message #1724781] Fri, 26 February 2016 04:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes but it can be adapted as well. Simply digg how it handles keywords

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724787 is a reply to message #1724784] Fri, 26 February 2016 05:52 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 06:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724790 is a reply to message #1724788] Fri, 26 February 2016 06:40 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 06:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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 | "#")+;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724874 is a reply to message #1724792] Fri, 26 February 2016 16:55 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724909 is a reply to message #1724883] Sat, 27 February 2016 01:03 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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: Sat, 27 February 2016 01:03]

Report message to a moderator

Re: Regarding Antlr rule matching [message #1724919 is a reply to message #1724909] Sat, 27 February 2016 07:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Did you consider to simply use STRING

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1724997 is a reply to message #1724919] Mon, 29 February 2016 03:30 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
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 05:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
In a string your model would be "comm" ????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Antlr rule matching [message #1725014 is a reply to message #1725001] Mon, 29 February 2016 07:38 Go to previous message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
yes.
Previous Topic:Xtext web editor -- semantic highlighting
Next Topic:Checking if JvmFormalParameter isAssignableFrom XExpression
Goto Forum:
  


Current Time: Fri Apr 19 01:41:02 GMT 2024

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

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

Back to the top