Class: Rouge::Token
- Inherits:
-
Object
- Object
- Rouge::Token
- Defined in:
- lib/rouge/token.rb
Defined Under Namespace
Modules: Tokens
Class Method Summary collapse
- .[](qualname) ⇒ Object
- .cache ⇒ Object
- .each_token(&b) ⇒ Object
- .inspect ⇒ Object
- .make_token(name, shortname, &b) ⇒ Object
- .matches?(other) ⇒ Boolean
- .name ⇒ Object
- .parent ⇒ Object
- .qualname ⇒ Object
- .register! ⇒ Object
- .shortname ⇒ Object
- .sub_tokens ⇒ Object
- .token(name, shortname, &b) ⇒ Object
- .token_chain ⇒ Object
Class Method Details
.[](qualname) ⇒ Object
16 17 18 19 20 |
# File 'lib/rouge/token.rb', line 16 def [](qualname) return qualname unless qualname.is_a? ::String Token.cache[qualname] end |
.cache ⇒ Object
8 9 10 |
# File 'lib/rouge/token.rb', line 8 def cache @cache ||= {} end |
.each_token(&b) ⇒ Object
59 60 61 62 63 |
# File 'lib/rouge/token.rb', line 59 def each_token(&b) Token.cache.each do |(_, t)| b.call(t) end end |
.inspect ⇒ Object
22 23 24 |
# File 'lib/rouge/token.rb', line 22 def inspect "<Token #{qualname}>" end |
.make_token(name, shortname, &b) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rouge/token.rb', line 43 def make_token(name, shortname, &b) parent = self Class.new(parent) do @parent = parent @name = name @shortname = shortname register! class_eval(&b) if b end end |
.matches?(other) ⇒ Boolean
26 27 28 |
# File 'lib/rouge/token.rb', line 26 def matches?(other) other.token_chain.include? self end |
.name ⇒ Object
4 |
# File 'lib/rouge/token.rb', line 4 def name; @name; end |
.parent ⇒ Object
5 |
# File 'lib/rouge/token.rb', line 5 def parent; @parent; end |
.qualname ⇒ Object
34 35 36 |
# File 'lib/rouge/token.rb', line 34 def qualname @qualname ||= token_chain.map(&:name).join('.') end |
.register! ⇒ Object
38 39 40 41 |
# File 'lib/rouge/token.rb', line 38 def register! Token.cache[self.qualname] = self parent.sub_tokens[self.name] = self end |
.shortname ⇒ Object
6 |
# File 'lib/rouge/token.rb', line 6 def shortname; @shortname; end |
.sub_tokens ⇒ Object
12 13 14 |
# File 'lib/rouge/token.rb', line 12 def sub_tokens @sub_tokens ||= {} end |
.token(name, shortname, &b) ⇒ Object
54 55 56 57 |
# File 'lib/rouge/token.rb', line 54 def token(name, shortname, &b) tok = make_token(name, shortname, &b) const_set(name, tok) end |
.token_chain ⇒ Object
30 31 32 |
# File 'lib/rouge/token.rb', line 30 def token_chain @token_chain ||= ancestors.take_while { |x| x != Token }.reverse end |