module WikiThat::Text
Lexer
module for handling raw text @author Bryan T. Meyers
Lexer
module for handling raw text @author Bryan T. Meyers
Public Instance Methods
lex_text(stop = [])
click to toggle source
Continue to lex as inline-text until the specified character or end of line @param [String] stop the character to stop at @returns [String] the text read
# File lib/wiki-that/lexer/tokens/text.rb, line 30 def lex_text(stop = []) buff = '' while not_match?(stop) and not_match? BREAK_SPECIAL if end? break end case current # Inline formatting when *FORMAT_SPECIAL fmt = lex_formatting if match? FORMAT_SPECIAL buff += current advance else if buff.length > 0 append Token.new(:text, buff) buff = '' end append fmt end # Inline links when *LINK_SPECIAL if buff.length > 0 append Token.new(:text, buff) buff = '' end lex_link when *RULE_SPECIAL if buff.length > 0 append Token.new(:text, buff) buff = '' end lex_horizontal_rule when *TAG_SPECIAL if buff.length > 0 append Token.new(:text, buff) buff = '' end lex_tag else buff += current advance end end if buff.length > 0 append Token.new(:text, buff) end end
parse_inline(*stop)
click to toggle source
Continue reading text tokens until a linebreak @param [Symbol] stop the type to stop parsing at
# File lib/wiki-that/parser/elements/text.rb, line 27 def parse_inline(*stop) children = [] until match? stop or match? [:break] or end? case current.type when :format children.push(*parse_format) when :comment, :tag_open children.push(parse_tag) when :rule children.push(parse_rule(true)) when :link_start children.push(parse_link) when :nowiki, :pre children.push(parse_nowiki) when :text children.push(Element.new(:text, current.value)) advance else return children end end children end
parse_text()
click to toggle source
Continue reading text tokens until a linebreak
# File lib/wiki-that/parser/elements/text.rb, line 54 def parse_text text = Element.new(:p) while match? [:break] @line += current.value advance end while match? [:text, :break, :link_start, :format, :comment, :tag_open] if match? [:break] @line += current.value if current.value == 1 text.add_child(Element.new(:text, ' ')) advance else advance break end else text.add_children(*parse_inline) end end text end