Class: Picoglob::Compiler Private
- Inherits:
-
Object
- Object
- Picoglob::Compiler
- Defined in:
- lib/picoglob/compiler.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Compiles a bash-style glob pattern into a Ruby Regexp source string.
Supported syntax:
* any run of non-separator characters
** any run of characters, including separators (globstar)
? any single non-separator character
[abc] [a-z] character class; [!...] or [^...] negates
{a,b,c} brace alternation (one of the comma-separated alternatives)
{1..3} numeric brace range expansion -> {1,2,3}
@(a|b) exactly one of the patterns (extglob)
?(a|b) zero or one of the patterns (extglob)
*(a|b) zero or more of the patterns (extglob)
+(a|b) one or more of the patterns (extglob)
!(a|b) anything except the patterns (extglob)
\x escape the next character (literal)
Instance Method Summary collapse
- #compile(pattern) ⇒ Regexp private
-
#initialize(separator: "/", dot: false, extglob: true, nocase: false) ⇒ Compiler
constructor
private
A new instance of Compiler.
Constructor Details
#initialize(separator: "/", dot: false, extglob: true, nocase: false) ⇒ Compiler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Compiler.
30 31 32 33 34 35 |
# File 'lib/picoglob/compiler.rb', line 30 def initialize(separator: "/", dot: false, extglob: true, nocase: false) @sep = separator @dot = dot @extglob = extglob @nocase = nocase end |
Instance Method Details
#compile(pattern) ⇒ Regexp
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 46 47 |
# File 'lib/picoglob/compiler.rb', line 39 def compile(pattern) @chars = pattern.chars @pos = 0 body = parse_sequence(top_level: true) raise ParseError, "unexpected #{current.inspect}" unless eof? src = "\\A#{body}\\z" Regexp.new(src, @nocase ? Regexp::IGNORECASE : nil) end |