document
production.
# Expect a `document` production.
private fun expect_document: Bool do
var got_doctype = false
var got_element = false
# If the document start with `<`, it may start with a XML declaration,
# a processing instruction, a comment, a `DOCTYPE` declaration, the
# root element or a white space.
if lexer.accept('<') then
if lexer.accept('?') then
if not expect_pi_or_xml_decl then return false
else if lexer.accept('!') then
if lexer.accept('-') then
if not lexer.expect('-',
" at the beginning of a comment") or
not expect_comment then
return false
end
else
if not expect_doctype_decl then return false
got_doctype = true
end
else
if not expect_root then return false
# The `DOCTYPE` declaration *must* come before the root
# element.
got_doctype = true
got_element = true
end
else if not lexer.accept_s then
return lexer.fire_unexpected_char(
". Expecting a white space or `<`")
end
# After the XML declaration (if there is one), the document may contain
# processing instructions, comments, the `DOCTYPE` declaration and
# the root element.
# These productions may be separated by white space.
while not got_element do
if lexer.accept('<') then
if lexer.accept('?') then
if not expect_pi then return false
else if lexer.accept('!') then
if lexer.accept('-') then
if not lexer.expect('-',
" at the beginning of a comment") or
not expect_comment then
return false
end
else if got_doctype then
return lexer.fire_unexpected_char(". Expecting `-`")
else if expect_doctype_decl then
got_doctype = true
else
return false
end
else
if not expect_root then return false
# The `DOCTYPE` declaration *must* come before the root
# element.
got_doctype = true
got_element = true
end
else if not lexer.accept_s then
return lexer.fire_unexpected_char(
". Expecting a white space or `<`")
end
end
return expect_miscs
end
lib/saxophonit/saxophonit.nit:182,2--251,4