2014-02-26 18:50:16 +00:00
|
|
|
module Oga
|
|
|
|
module ParsingHelpers
|
|
|
|
##
|
|
|
|
# Builds an AST node.
|
|
|
|
#
|
|
|
|
# @param [Symbol] type
|
|
|
|
# @param [Array] cihldren
|
|
|
|
# @return [Oga::AST::Node]
|
|
|
|
#
|
|
|
|
def s(type, *children)
|
|
|
|
return Oga::AST::Node.new(type, children)
|
|
|
|
end
|
2014-02-26 20:36:30 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Lexes a string and returns the tokens.
|
|
|
|
#
|
|
|
|
# @param [String] input
|
2014-03-16 22:42:24 +00:00
|
|
|
# @param [Hash] options
|
2014-02-26 20:36:30 +00:00
|
|
|
# @return [Array]
|
|
|
|
#
|
2014-03-16 22:42:24 +00:00
|
|
|
def lex(input, options = {})
|
|
|
|
return Oga::Lexer.new(options).lex(input)
|
2014-02-26 20:36:30 +00:00
|
|
|
end
|
2014-02-27 00:27:43 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Parses the given HTML and returns an AST.
|
|
|
|
#
|
|
|
|
# @param [String] input
|
|
|
|
# @return [Oga::AST::Node]
|
|
|
|
#
|
|
|
|
def parse_html(input)
|
2014-03-16 22:42:24 +00:00
|
|
|
return Oga::Parser.new(:html => true).parse(input)
|
2014-02-27 00:27:43 +00:00
|
|
|
end
|
2014-02-26 18:50:16 +00:00
|
|
|
end # ParsingHelpers
|
|
|
|
end # Oga
|