Project

lineparser

0.0
No commit activity in last 3 years
No release in over 3 years
Lineparser is suited to parsing configuration files, however it can parse any type of text file which has repeating patterns identified by a heading etc.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.9, >= 0.9.1
 Project Readme

Introducing the Lineparser gem

require 'lineparser'

lines =<<LINES
resources: posts
# winning
#
post
  model
    Post
      orange 123
      fff
comments
  model
    Comment
      orange 576
      ggg
LINES

patterns = [
  [:root, 'resources: :resources', :resources],
  [:root, ':resource', :resource],
    [:resource, 'model', :model],
      [:model, ':class_name', :model_class],
        [:model_class, /orange (\w+)/, :model_class_attribute],
  [:all, /#/, :comment]
]

lp = LineParser.new patterns
r = lp.parse lines

output observed:

[
  [:resources, {":resources"=>"posts"}, ["resources: posts"], nil], 
  [:comment, {:captures=>[]}, ["# winning"], nil], 
  [:comment, {:captures=>[]}, ["#"], nil], 
  [:resource, {":resource"=>"post"}, ["post", ["model", ["Post", ["orange 123"], ["fff"]]]], [
    [:model, {}, ["model", ["Post", ["orange 123"], ["fff"]]], [
      [:model_class, {":class_name"=>"Post"}, ["Post", ["orange 123"], ["fff"]], [
        [:model_class_attribute, {:captures=>["123"]}, ["orange 123"], nil]
      ]]
    ]]
  ]],
  [:resource, {":resource"=>"comments"}, ["comments", ["model", ["Comment", ["orange 576"], ["ggg"]]]], [
    [:model, {}, ["model", ["Comment", ["orange 576"], ["ggg"]]], [
      [:model_class, {":class_name"=>"Comment"}, ["Comment", ["orange 576"], ["ggg"]], [
        [:model_class_attribute, {:captures=>["576"]}, ["orange 576"], nil]
      ]]
    ]]
  ]]
] 

Resources

lineparser linetree parser configuration