Sha256: f778d2de3f87be5adddd1d3f9dfca76723ed10b9546a5a83798f1f4da4b50287

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

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

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

    on(nil, ??, ?+, ?*, ?)) { |c| unexpected(c) }
    on(?:) { |c| node(:capture) { scan(/\w+/) } }
    on(?() { |c| node(:splat, constraint: read_brackets(?(, ?))) }

    suffix ??, after: :capture do |char, element|
      unexpected(char) unless element.is_a? :capture
      node(:optional, element)
    end

    suffix ?*, after: :capture do |match, element|
      node(:named_splat, element.name)
    end

    suffix ?+, after: :capture do |match, element|
      node(:named_splat, element.name, constraint: ".+")
    end

    suffix ?(, after: :capture do |match, element|
      element.constraint = read_brackets(?(, ?))
      element
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

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