Sha256: da4fcdade5ddb9879cdd7497069d66bef0f09aee5ad6694c389583ea7b77c2f9

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

require 'parslet'

module Junoser
  class Transformer < Parslet::Transform
    rule(config: simple(:config)) do
      config.to_s
    end

    rule(config: sequence(:configs)) do
      configs.join("\n")
    end

    rule(arg: simple(:arg)) do
      "arg(#{arg})"
    end

    rule(label: simple(:label)) do
      label.to_s
    end

    rule(label: simple(:label), child: simple(:child)) do
      "#{label}\n#{child}"
    end

    rule(label: simple(:label), child: sequence(:children)) do
      %[#{label}\n#{children.join("\n")}]
    end

    rule(statement: simple(:statement), argument: simple(:argument)) do
      "#{statement} #{argument}"
    end

    rule(statement: simple(:statement), argument: sequence(:arguments)) do
      %[#{statement}\n#{arguments.join("\n")}]
    end

    rule(oneline: simple(:str)) do
      str.gsub "\n", ' '
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
junoser-0.1.2 lib/junoser/transformer.rb
junoser-0.1.1 lib/junoser/transformer.rb
junoser-0.1.0 lib/junoser/transformer.rb