Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Problems parsing ruby on rails files with xtext(Problems parsing ' '* and equals symbol.)
Problems parsing ruby on rails files with xtext [message #1743033] Fri, 09 September 2016 13:46 Go to next message
Eclipse UserFriend
Hi
I'm parsing Ruby on rails models with xtext.

I'm having problems parsing the las 3 lines of this sample (when there is no space between foreign_key and equals symbol (=).

belongs_to :school,:foreign_key => "model_id"
belongs_to "school", :foreign_key =>:model_id
belongs_to "school", :foreign_key =>"model_id"
belongs_to :school,:foreign_key=> "model_id"
belongs_to "school", :foreign_key=>:model_id
belongs_to "school", :foreign_key =>"school_id"


The xtext file is:


Main:
belongs_to+=BelongsTo*
;

BelongsTo returns BelongsTo:
'belongs_to' RWS+ name=(RUBY_SYMBOL|RUBY_STRING) (RWS*','RWS* ('foreign_key:'|':foreign_key'RWS*'=>')RWS*foreign_key=(RUBY_SYMBOL|RUBY_STRING))? (RWS*'\r'? '\n')
;

terminal RUBY_STRING: '"' -> '"'|"'"->"'";
terminal RUBY_METHOD_NAME: ('a'..'z'|'_') ('a'..'z'|'_'|'0'..'9')*'='?;
terminal RUBY_SYMBOL:':'RUBY_METHOD_NAME;
terminal RWS:(' '|'\t');


Thanks in advance, for any idea
  • Attachment: MyDsl.xtext
    (Size: 0.54KB, Downloaded 94 times)
  • Attachment: samples.mydsl
    (Size: 0.27KB, Downloaded 88 times)
Re: Problems parsing ruby on rails files with xtext [message #1743042 is a reply to message #1743033] Fri, 09 September 2016 16:06 Go to previous messageGo to next message
Eclipse UserFriend
you may try something like

Main:
  belongs_to+=BelongsTo*
;

BelongsTo returns BelongsTo:
  'belongs_to' RWS+ name=(RUBY_SYMBOL|RUBY_STRING) (RWS*','RWS* ('foreign_key:'|':foreign_key'RWS* ('=''>') )RWS*foreign_key=(RUBY_SYMBOL|RUBY_STRING))? (RWS*'\r'? '\n')
;

RUBY_METHOD_NAME: RUBY_METHOD_NAME_PREFIX ;
RUBY_SYMBOL:':'RUBY_METHOD_NAME;

terminal RUBY_STRING: '"' -> '"'|"'"->"'";
terminal RUBY_METHOD_NAME_PREFIX: ('a'..'z'|'_') ('a'..'z'|'_'|'0'..'9')*;
terminal RWS:(' '|'\t');
Re: Problems parsing ruby on rails files with xtext [message #1743043 is a reply to message #1743042] Fri, 09 September 2016 16:11 Go to previous messageGo to next message
Eclipse UserFriend
or

Main:
belongs_to+=BelongsTo*
;

BelongsTo returns BelongsTo:
'belongs_to' RWS+ name=(RUBY_SYMBOL|RUBY_STRING) (RWS*','RWS* ('foreign_key:'|':foreign_key'RWS*'=''>')RWS*foreign_key=(RUBY_SYMBOL|RUBY_STRING))? (RWS*'\r'? '\n')
;

terminal RUBY_STRING: '"' -> '"'|"'"->"'";
terminal RUBY_METHOD_NAME: ('a'..'z'|'_') ('a'..'z'|'_'|'0'..'9')*;
RUBY_SYMBOL:':'RUBY_METHOD_NAME '='?;
terminal RWS:(' '|'\t');
Re: Problems parsing ruby on rails files with xtext [message #1743053 is a reply to message #1743043] Fri, 09 September 2016 22:47 Go to previous message
Eclipse UserFriend
It works well

I had a misconception about terminals/rules use.

Thanks a lot
Previous Topic:Help with grammar
Next Topic:Parsing of language fragments
Goto Forum:
  


Current Time: Wed Jul 02 07:28:04 EDT 2025

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

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

Back to the top