aboutsummaryrefslogtreecommitdiff
path: root/src/machine.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-17 17:25:32 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 13:41:55 +0200
commit378662fa52bbc3e9e4a210f649093dcdadf51afa (patch)
tree44168be8588b8c17fc920839bc93595ea0152aea /src/machine.rs
parente34083e64b764df076c1ef9ec6bf1102b9fbf748 (diff)
feat!: add span and offsets to Doctype
Diffstat (limited to 'src/machine.rs')
-rw-r--r--src/machine.rs119
1 files changed, 60 insertions, 59 deletions
diff --git a/src/machine.rs b/src/machine.rs
index 0755e20..0d99ab8 100644
--- a/src/machine.rs
+++ b/src/machine.rs
@@ -910,11 +910,11 @@ where
State::BogusComment => match slf.read_char()? {
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
Some('\0') => {
@@ -935,6 +935,7 @@ where
}
Some('d' | 'D') if slf.try_read_string("octype", false)? => {
slf.state = State::Doctype;
+ slf.doctype_offset = slf.reader.position() - b"<!doctype".len();
Ok(ControlToken::Continue)
}
Some('[') if slf.try_read_string("CDATA[", true)? => {
@@ -967,7 +968,7 @@ where
Some('>') => {
slf.emit_error(Error::AbruptClosingOfEmptyComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Continue)
}
c => {
@@ -984,12 +985,12 @@ where
Some('>') => {
slf.emit_error(Error::AbruptClosingOfEmptyComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1016,7 +1017,7 @@ where
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1082,7 +1083,7 @@ where
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
c => {
@@ -1095,7 +1096,7 @@ where
State::CommentEnd => match slf.read_char()? {
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Continue)
}
Some('!') => {
@@ -1108,7 +1109,7 @@ where
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1130,12 +1131,12 @@ where
Some('>') => {
slf.emit_error(Error::IncorrectlyClosedComment);
slf.state = State::Data;
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInComment);
- slf.emitter.emit_current_comment();
+ slf.emitter.emit_current_comment(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1159,9 +1160,9 @@ where
}
None => {
slf.emit_error(Error::EofInDoctype);
- slf.emitter.init_doctype(slf.reader.position());
+ slf.emitter.init_doctype(slf.doctype_offset);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1175,28 +1176,28 @@ where
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('\0') => {
slf.emit_error(Error::UnexpectedNullCharacter);
- slf.emitter.init_doctype(slf.reader.position());
+ slf.emitter.init_doctype(slf.doctype_offset);
slf.emitter.push_doctype_name("\u{fffd}");
slf.state = State::DoctypeName;
Ok(ControlToken::Continue)
}
Some('>') => {
slf.emit_error(Error::MissingDoctypeName);
- slf.emitter.init_doctype(slf.reader.position());
+ slf.emitter.init_doctype(slf.doctype_offset);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
- slf.emitter.init_doctype(slf.reader.position());
+ slf.emitter.init_doctype(slf.doctype_offset);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
- slf.emitter.init_doctype(slf.reader.position());
+ slf.emitter.init_doctype(slf.doctype_offset);
slf.emitter
.push_doctype_name(ctostr!(x.to_ascii_lowercase()));
slf.state = State::DoctypeName;
@@ -1210,7 +1211,7 @@ where
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
Some('\0') => {
@@ -1221,7 +1222,7 @@ where
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1234,13 +1235,13 @@ where
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some('p' | 'P') if slf.try_read_string("ublic", false)? => {
@@ -1266,13 +1267,13 @@ where
}
Some('"') => {
slf.emit_error(Error::MissingWhitespaceAfterDoctypePublicKeyword);
- slf.emitter.init_doctype_public_id();
+ slf.emitter.init_doctype_public_id(slf.reader.position());
slf.state = State::DoctypePublicIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
slf.emit_error(Error::MissingWhitespaceAfterDoctypePublicKeyword);
- slf.emitter.init_doctype_public_id();
+ slf.emitter.init_doctype_public_id(slf.reader.position());
slf.state = State::DoctypePublicIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
@@ -1280,13 +1281,13 @@ where
slf.emit_error(Error::MissingDoctypePublicIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1300,12 +1301,12 @@ where
State::BeforeDoctypePublicIdentifier => match slf.read_char()? {
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('"') => {
- slf.emitter.init_doctype_public_id();
+ slf.emitter.init_doctype_public_id(slf.reader.position());
slf.state = State::DoctypePublicIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
- slf.emitter.init_doctype_public_id();
+ slf.emitter.init_doctype_public_id(slf.reader.position());
slf.state = State::DoctypePublicIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
@@ -1313,13 +1314,13 @@ where
slf.emit_error(Error::MissingDoctypePublicIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1344,13 +1345,13 @@ where
slf.emit_error(Error::AbruptDoctypePublicIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1372,13 +1373,13 @@ where
slf.emit_error(Error::AbruptDoctypePublicIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1393,25 +1394,25 @@ where
}
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
Some('"') => {
slf.emit_error(Error::MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers);
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
slf.emit_error(Error::MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers);
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1426,23 +1427,23 @@ where
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
Some('"') => {
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1460,13 +1461,13 @@ where
}
Some('"') => {
slf.emit_error(Error::MissingWhitespaceAfterDoctypeSystemKeyword);
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
slf.emit_error(Error::MissingWhitespaceAfterDoctypeSystemKeyword);
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
@@ -1474,13 +1475,13 @@ where
slf.emit_error(Error::MissingDoctypeSystemIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1494,12 +1495,12 @@ where
State::BeforeDoctypeSystemIdentifier => match slf.read_char()? {
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('"') => {
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierDoubleQuoted;
Ok(ControlToken::Continue)
}
Some('\'') => {
- slf.emitter.init_doctype_system_id();
+ slf.emitter.init_doctype_system_id(slf.reader.position());
slf.state = State::DoctypeSystemIdentifierSingleQuoted;
Ok(ControlToken::Continue)
}
@@ -1507,13 +1508,13 @@ where
slf.emit_error(Error::MissingDoctypeSystemIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1538,13 +1539,13 @@ where
slf.emit_error(Error::AbruptDoctypeSystemIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1566,13 +1567,13 @@ where
slf.emit_error(Error::AbruptDoctypeSystemIdentifier);
slf.emitter.set_force_quirks();
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(x) => {
@@ -1584,13 +1585,13 @@ where
Some(whitespace_pat!()) => Ok(ControlToken::Continue),
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
None => {
slf.emit_error(Error::EofInDoctype);
slf.emitter.set_force_quirks();
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
c @ Some(_) => {
@@ -1603,7 +1604,7 @@ where
State::BogusDoctype => match slf.read_char()? {
Some('>') => {
slf.state = State::Data;
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Continue)
}
Some('\0') => {
@@ -1611,7 +1612,7 @@ where
Ok(ControlToken::Continue)
}
None => {
- slf.emitter.emit_current_doctype();
+ slf.emitter.emit_current_doctype(slf.reader.position());
Ok(ControlToken::Eof)
}
Some(_) => Ok(ControlToken::Continue),