Basic lexing + parsing of doctypes.

We're doing these the lazy way. I can't be bothered writing patterns/rules for
4 different formats for something such as doctypes.
This commit is contained in:
Yorick Peterse committed 2014-02-27 01:27:51 +01:00
1 parent d7d20b4c23
commit 2c82f88f6c
5 files changed
+94 -20

No files matched your search

+14
View File
@@ -132,4 +132,18 @@ describe Oga::Lexer do
]
end
end
context 'doctypes' do
example 'lex the HTML5 doctype' do
lex('<!DOCTYPE html>').should == [
[:T_DOCTYPE, '<!DOCTYPE html>', 1, 1]
]
end
example 'lex a random doctype' do
lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
[:T_DOCTYPE, '<!DOCTYPE HTML PUBLIC "foobar" "baz">', 1, 1]
]
end
end
end
+18
View File
@@ -0,0 +1,18 @@
require 'spec_helper'
describe Oga::Parser::HTML do
context 'doctypes' do
example 'parse the HTML5 doctype' do
doctype = '<!DOCTYPE html>'
parse_html(doctype).should == s( :document, s(:doctype, doctype))
end
example 'parse an HTML 4 strict doctype' do
doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ' \
'"http://www.w3.org/TR/html4/strict.dtd">'
parse_html(doctype).should == s(:document, s(:doctype, doctype))
end
end
end
+10
View File
@@ -20,5 +20,15 @@ module Oga
def lex(input)
return Oga::Lexer.new.lex(input)
end
##
# Parses the given HTML and returns an AST.
#
# @param [String] input
# @return [Oga::AST::Node]
#
def parse_html(input)
return Oga::Parser::HTML.new.parse(input)
end
end # ParsingHelpers
end # Oga