module WikiThat::TableOfContents

Lexer module for handling Table of Contents @author Bryan T. Meyers

Public Instance Methods

lex_toc() click to toggle source

Lex the current text as a NOTOC

# File lib/wiki-that/lexer/tokens/toc.rb, line 29
def lex_toc
  buff  = ''
  count = 0

  while match? TOC_SPECIAL
    buff  += current
    count += 1
    advance
  end
  if count != 2
    append Token.new(:text, buff)
    return
  end

  case current
    when 'N'
      text = 'NOTOC'
    when 'T'
      text = 'TOC'
    else
      append Token.new(:text, buff)
      return
  end
  text.each_char do |c|
    unless current == c
      append Token.new(:text, buff)
      return
    end
    buff += current
    advance
  end

  count = 0
  while match? TOC_SPECIAL
    buff  += current
    count += 1
    advance
  end
  if count != 2
    append Token.new(:text, buff)
    return
  end
  ## Read to the end fo the line. We want to remove this entirely
  until end? or match? BREAK_SPECIAL
    advance
  end
end