Sha256: c666552ade839e26cd2d6f016e216426fcce303449cee33f83def88d1af8dcf4

Contents?: true

Size: 862 Bytes

Versions: 2

Compression:

Stored size: 862 Bytes

Contents

require 'parslet'

class YamlQuery::Parser < Parslet::Parser
  def initialize(delimiter)
    @delimiter = delimiter
  end
  rule(:key) { match("[^\s#{@delimiter}!<>&= ]").repeat(1) >> space? }

  rule(:space) { match('\s').repeat(1) }
  rule(:space?) { space.maybe }

  rule(:delimiter) { match("\\#{@delimiter}") >> space? }
  rule(:delimiter?) { delimiter.maybe >> space? }

  rule(:operator) { match('[&!=><]') >> match('=').maybe >> space? }
  rule(:argument) { match('.').repeat(1) }
  rule(:argument?) { argument.maybe }

  rule(:keypath) { key.as(:key) >> delimiter? }
  rule(:expression) { operator.as(:operator) >> argument?.as(:arg) }
  rule(:expression?) { expression.maybe }
  rule(:rooty) { keypath.repeat(1).as(:keys) >> expression? }
  root(:rooty)
end

class YamlQuery::Transform < Parslet::Transform
  rule(:key => simple(:x)) { String(x) }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yamlquery-0.0.2 lib/yamlquery/parser.rb
yamlquery-0.0.1 lib/yamlquery/parser.rb