Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parse part of file and ignore anything else(looking for a way for ignore anything not parsed in xtext)
Parse part of file and ignore anything else [message #1744925] Mon, 03 October 2016 02:14 Go to next message
Jair Garcia is currently offline Jair GarciaFriend
Messages: 4
Registered: September 2016
Junior Member
Hi.

Im working on an island parser for Ruby on rails models.
I'm only interested in parsing part of some classes :

  1. Class definition, i.e. "class Student < Things::Persons". The line always starts with 'class', then class name, then '<' and superclass name.
  2. Table name assignation i.e "set_table_name 'people'", the line always starts with "set_table_name" and then a string.
  3. Class associations i.e: "belongs_to :school", "has_many 'groups', class_name: 'Group'". The line always starts with "belongs_to", "has_many", "has_one" or "has_and_belongs_to_many", then relationship name, and options
  4. Method definition i.e: "def method_name". The line always starts with "def", then method name and params. I don't want to get method params, method content or where it finishes.

2, 3 and 4 can appear in any order in the code.

I have created a xtext parser for get these kind of lines, but ruby language is too complicated.
Some times when I trying to capture a line of code, it get more than one and hides some lines of the lines that I need (one of the four types)
I'm struggling to create more complex rules (and terminals) for keep my important lines and ignore other, but more and more errors appear.

There is a easy way to parse only some rules and ignore anything else.

I attached a code sample (comments starts with #) and my current grammar.

Thanks in advance

  • Attachment: Rails.xtext
    (Size: 4.84KB, Downloaded 63 times)
Sample [message #1744926 is a reply to message #1744925] Mon, 03 October 2016 02:17 Go to previous message
Jair Garcia is currently offline Jair GarciaFriend
Messages: 4
Registered: September 2016
Junior Member
Sample file:


# Single line comment
# Single line comment
=begin
Multiline comment.
=end

require 'external_libraries'
#Class name is Student, superclase ActiveRecord::Base
class Student < ActiveRecord::Base
#Important lines

#relationships
belongs_to :school
has_many :courses, :class_name=>'Group'

#table_name
set_table_name 'table_name'

#method_definition
def self.method1(param1,param2,param3)
a=1+2
end

def method2? param1, param2
param=param1+param2
end

#rubish lines of code
garbage_line :order => 'xx'
other_line
CONSTANT = [1,2,3]
CONSTANT1 = {a:1,b:2}
CONSTANT2 = 1
CONSTANT3 = "a"
validates_presence_of :name, :if => Proc.new{|obj| obj.step_gt_or_eq(2) }
@init||=1
regular_expression||=/[0-9]/
boolean_var = self.start && CONSTANT <= var

end

  • Attachment: sample.rb
    (Size: 0.78KB, Downloaded 43 times)
Previous Topic:Xtext standalone validation issue
Next Topic:How can I get the corresponding GenClass of an EClass
Goto Forum:
  


Current Time: Thu Apr 22 18:21:31 GMT 2021

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

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

Back to the top