Sha256: acb83a0effcc6b8ab9c28e9f11d52bc177b18e515c721a6849ad856be5af91b8

Contents?: true

Size: 758 Bytes

Versions: 17

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true
require 'mustermann'
require 'mustermann/ast/pattern'

module Mustermann
  # Pyramid style pattern implementation.
  #
  # @example
  #   Mustermann.new('/<foo>', type: :pryamid) === '/bar' # => true
  #
  # @see Mustermann::Pattern
  # @see file:README.md#pryamid Syntax description in the README
  class Pyramid < AST::Pattern
    register :pyramid

    on(nil, ?}) { |c| unexpected(c) }

    on(?{) do |char|
      name       = expect(/\w+/, char: char)
      constraint = read_brackets(?{, ?}) if scan(?:)
      expect(?}) unless constraint
      node(:capture, name, constraint: constraint)
    end

    on(?*) do |char|
      node(:named_splat, expect(/\w+$/, char: char), convert: -> e { e.split(?/) })
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
mustermann-contrib-3.0.3 lib/mustermann/pyramid.rb
mustermann-contrib-3.0.2 lib/mustermann/pyramid.rb
mustermann-contrib-3.0.1 lib/mustermann/pyramid.rb
mustermann-contrib-3.0.0 lib/mustermann/pyramid.rb
mustermann-contrib-2.0.2 lib/mustermann/pyramid.rb
mustermann-contrib-2.0.1 lib/mustermann/pyramid.rb
mustermann-contrib-2.0.0 lib/mustermann/pyramid.rb
mustermann-contrib-1.1.2 lib/mustermann/pyramid.rb
mustermann-contrib-1.1.1 lib/mustermann/pyramid.rb
mustermann-contrib-1.1.0 lib/mustermann/pyramid.rb
mustermann-contrib-1.0.3 lib/mustermann/pyramid.rb
mustermann-contrib-1.0.2 lib/mustermann/pyramid.rb
mustermann-contrib-1.0.2.rc2 lib/mustermann/pyramid.rb
mustermann-contrib-1.0.2.rc1 lib/mustermann/pyramid.rb
mustermann-1.0.2.rc1 mustermann-contrib/lib/mustermann/pyramid.rb
mustermann-contrib-1.0.1 lib/mustermann/pyramid.rb
mustermann-contrib-1.0.0 lib/mustermann/pyramid.rb