Class: Regexp::Syntax::Base
- Inherits:
-
Object
- Object
- Regexp::Syntax::Base
show all
- Includes:
- Token
- Defined in:
- lib/regexp_parser/syntax/base.rb
Overview
A lookup map of supported types and tokens in a given syntax
Constant Summary
Constants included
from Token
Token::All, Token::Map, Token::Types
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
Class Method Details
.inspect ⇒ Object
89
90
91
|
# File 'lib/regexp_parser/syntax/base.rb', line 89
def self.inspect
"#{super} (feature set of #{ancestors[1].to_s.split('::').last})"
end
|
Instance Method Details
#excludes(type, tokens) ⇒ Object
31
32
33
|
# File 'lib/regexp_parser/syntax/base.rb', line 31
def excludes(type, tokens)
Array(tokens).each { |tok| implementations(type).delete(tok) }
end
|
#features ⇒ Object
19
20
21
|
# File 'lib/regexp_parser/syntax/base.rb', line 19
def features
@implements
end
|
#implementations(type) ⇒ Object
23
24
25
|
# File 'lib/regexp_parser/syntax/base.rb', line 23
def implementations(type)
@implements[type] ||= []
end
|
#implements(type, tokens) ⇒ Object
27
28
29
|
# File 'lib/regexp_parser/syntax/base.rb', line 27
def implements(type, tokens)
implementations(type).concat(Array(tokens))
end
|
#implements!(type, token) ⇒ Object
Also known as:
check!
40
41
42
43
|
# File 'lib/regexp_parser/syntax/base.rb', line 40
def implements!(type, token)
raise NotImplementedError.new(self, type, token) unless
implements?(type, token)
end
|
#implements?(type, token) ⇒ Boolean
Also known as:
check?
35
36
37
|
# File 'lib/regexp_parser/syntax/base.rb', line 35
def implements?(type, token)
implementations(type).include?(token)
end
|
#normalize(type, token) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/regexp_parser/syntax/base.rb', line 46
def normalize(type, token)
case type
when :group
normalize_group(type, token)
when :backref
normalize_backref(type, token)
else
[type, token]
end
end
|
#normalize_backref(type, token) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/regexp_parser/syntax/base.rb', line 66
def normalize_backref(type, token)
case token
when :name_ref_ab, :name_ref_sq
%i[backref name_ref]
when :name_call_ab, :name_call_sq
%i[backref name_call]
when :name_recursion_ref_ab, :name_recursion_ref_sq
%i[backref name_recursion_ref]
when :number_ref_ab, :number_ref_sq
%i[backref number_ref]
when :number_call_ab, :number_call_sq
%i[backref number_call]
when :number_rel_ref_ab, :number_rel_ref_sq
%i[backref number_rel_ref]
when :number_rel_call_ab, :number_rel_call_sq
%i[backref number_rel_call]
when :number_recursion_ref_ab, :number_recursion_ref_sq
%i[backref number_recursion_ref]
else
[type, token]
end
end
|
#normalize_group(type, token) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/regexp_parser/syntax/base.rb', line 57
def normalize_group(type, token)
case token
when :named_ab, :named_sq
%i[group named]
else
[type, token]
end
end
|