Sha256: 5b55a7a47d202acc821163d0410b2cd539a275c06cde8cf1d92bfef8a61a0c38

Contents?: true

Size: 799 Bytes

Versions: 1

Compression:

Stored size: 799 Bytes

Contents

module Todoloo
  class Transformer < Parslet::Transform
    rule(file: subtree(:x)) { x.compact }

    rule(lines: subtree(:x)) { x }

    rule(line: {code: subtree(:x)}) { nil }

    rule(line: {code: subtree(:x), comment: subtree(:y)}) { y }

    # Discard lines with only code and comments without tasks
    rule(line: {code: subtree(:x), comment: simple(:y)}) { nil }

    rule(line: {comment: subtree(:x)}) { x }

    rule(line: {comment: simple(:x)}) { nil }

    rule(type: simple(:type), topics: sequence(:topics), description: sequence(:description)) do
      {type: type, topics: topics, description: description.empty? ? "" : (raise "must be empty")}
    end

    rule(topic: simple(:x)) { x.to_s }

    rule(task: subtree(:task)) { task }

    rule([{text: simple(:x)}]) { x }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
todoloo-0.0.4 lib/todoloo/transformer.rb