Class: Rouge::Lexers::Ddot

Inherits:
RegexLexer
  • Object
show all
Defined in:
lib/rouge/lexers/ddot.rb

Constant Summary collapse

DT2 =

--- lexical tokens (see the Parse Spec's "Token Sequences") ---------- Each is a run of EXACTLY n, neither preceded nor followed by the same character — the lookarounds are what express that. \.{2} alone would happily match the first two dots of ....

/(?<!\.)\.{2}(?!\.)/.freeze
DT4 =
/(?<!\.)\.{4}(?!\.)/.freeze
QUAD =
/(?<!\.)(?:\.{4}|\.{2}[ \t]+\.{2})(?!\.)/.freeze
CM2 =
/(?<!,),,(?!,)/.freeze
SC2 =
/(?<!;);;(?!;)/.freeze
OFF_RE =
%r{(?:ddot\.it/off|!!off)}.freeze
ON_RE =
%r{(?:ddot\.it/on|!!on)}.freeze
BOUND_SRC =

Pins the command NAME: !!office must not read as !!off.

/(?![^\s?#])/.freeze
CMD_RE =

A command needs the slash and a non-empty name; bare ddot.it is not one.

%r{(?:(?:https?://)?ddot\.it/|!!)[^\s?#]+(?:\?[^\s#]*)?(?:\#\S*)?}.freeze
BLOCK_RE =
%r{(?:(?:https?://)?ddot\.it/|!!)block}.freeze
GATE =

The line-shape gate: a line is ddot.it only if it carries a complete operator skeleton — two DT2, or one DT4 / '.. ..'. A lone .. in prose does not qualify, which is what keeps 23-not-a-triple entirely plain.

/(?=[^\n]*(?:#{DT4}|#{DT2}[^\n]*#{DT2}))/.freeze
BLOCK_OPENER =

!!block filling a whole field: it must END its physical line.

/#{BLOCK_RE}(?:(\?end=)(\S+))?[ \t]*(?=\n|\z)/.freeze

Instance Method Summary collapse

Instance Method Details

#open_block(match) ⇒ Object

A !!block opener was matched: emit its parts, remember any ?end= marker, and switch to verbatim.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rouge/lexers/ddot.rb', line 85

def open_block(match)
  raw  = match[0]
  lead = raw[/\A[ \t]*/]
  body = raw[lead.length..].rstrip
  tail = raw[(lead.length + body.length)..]
  token Text, lead unless lead.empty?
  if match[2]
    token Keyword::Pseudo, body[0...body.index('?end=')]
    token Name::Attribute, match[1]
    token Name::Label, match[2]
    @block_end = match[2]
  else
    token Keyword::Pseudo, body
    @block_end = nil
  end
  token Text, tail unless tail.nil? || tail.empty?
  goto :verbatim
end

#reset!Object



70
71
72
73
# File 'lib/rouge/lexers/ddot.rb', line 70

def reset!
  super
  @block_end = nil
end

#slot(match, slot_token) ⇒ Object

Emit a slot's text as slot_token, unless it is exactly a command — then it is a command (tokens.md: "a slot whose text is a command is emitted as command, not subject").



78
79
80
81
# File 'lib/rouge/lexers/ddot.rb', line 78

def slot(match, slot_token)
  text = match[0]
  token(text.match?(/\A#{CMD_RE}\z/) ? Keyword::Pseudo : slot_token, text)
end