From be904983ff3761cdc491f256aa213b458014002f Mon Sep 17 00:00:00 2001 From: Callum Moffat Date: Mon, 8 Jul 2024 13:02:48 -0400 Subject: [PATCH] Run the formatter --- lib/src/constants.dart | 178 ++++++++++++++++++--------------- lib/src/html_input_stream.dart | 12 ++- lib/src/tokenizer.dart | 16 ++- test/parser_feature_test.dart | 3 +- 4 files changed, 116 insertions(+), 93 deletions(-) diff --git a/lib/src/constants.dart b/lib/src/constants.dart index d8273be..797b274 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -394,40 +394,52 @@ const mathmlTextIntegrationPointElements = [ ]; class Charcode { - static const int kNull = 0x00; - /// '\t' - static const int kTab = 0x09; - /// '\n' - static const int kLineFeed = 0x0A; - static const int kFormFeed = 0x0C; - /// '\r' - static const int kCarriageReturn = 0x0D; - /// ' ' - static const int kSpace = 0x20; - /// '"' - static const int kDoubleQuote = 0x22; - /// '&' - static const int kAmpersand = 0x26; - /// "'" - static const int kSingleQuote = 0x27; - /// '-' - static const int kHyphen = 0x2D; - /// '<' - static const int kLessThan = 0x3C; - /// '=' - static const int kEquals = 0x3D; - /// '>' - static const int kGreaterThan = 0x3E; - /// '`' - static const int kGraveAccent = 0x60; + static const int kNull = 0x00; + + /// '\t' + static const int kTab = 0x09; + + /// '\n' + static const int kLineFeed = 0x0A; + static const int kFormFeed = 0x0C; + + /// '\r' + static const int kCarriageReturn = 0x0D; + + /// ' ' + static const int kSpace = 0x20; + + /// '"' + static const int kDoubleQuote = 0x22; + + /// '&' + static const int kAmpersand = 0x26; + + /// "'" + static const int kSingleQuote = 0x27; + + /// '-' + static const int kHyphen = 0x2D; + + /// '<' + static const int kLessThan = 0x3C; + + /// '=' + static const int kEquals = 0x3D; + + /// '>' + static const int kGreaterThan = 0x3E; + + /// '`' + static const int kGraveAccent = 0x60; } const spaceCharacters = { - Charcode.kSpace, - Charcode.kLineFeed, - Charcode.kCarriageReturn, - Charcode.kTab, - Charcode.kFormFeed + Charcode.kSpace, + Charcode.kLineFeed, + Charcode.kCarriageReturn, + Charcode.kTab, + Charcode.kFormFeed }; bool isWhitespace(String? char) { @@ -457,58 +469,58 @@ const List tableInsertModeElements = [ // TODO(jmesserly): remove these in favor of the test functions const asciiLetters = { - 0x41, - 0x42, - 0x43, - 0x44, - 0x45, - 0x46, - 0x47, - 0x48, - 0x49, - 0x4A, - 0x4B, - 0x4C, - 0x4D, - 0x4E, - 0x4F, - 0x50, - 0x51, - 0x52, - 0x53, - 0x54, - 0x55, - 0x56, - 0x57, - 0x58, - 0x59, - 0x5A, - 0x61, - 0x62, - 0x63, - 0x64, - 0x65, - 0x66, - 0x67, - 0x68, - 0x69, - 0x6A, - 0x6B, - 0x6C, - 0x6D, - 0x6E, - 0x6F, - 0x70, - 0x71, - 0x72, - 0x73, - 0x74, - 0x75, - 0x76, - 0x77, - 0x78, - 0x79, - 0x7A, + 0x41, + 0x42, + 0x43, + 0x44, + 0x45, + 0x46, + 0x47, + 0x48, + 0x49, + 0x4A, + 0x4B, + 0x4C, + 0x4D, + 0x4E, + 0x4F, + 0x50, + 0x51, + 0x52, + 0x53, + 0x54, + 0x55, + 0x56, + 0x57, + 0x58, + 0x59, + 0x5A, + 0x61, + 0x62, + 0x63, + 0x64, + 0x65, + 0x66, + 0x67, + 0x68, + 0x69, + 0x6A, + 0x6B, + 0x6C, + 0x6D, + 0x6E, + 0x6F, + 0x70, + 0x71, + 0x72, + 0x73, + 0x74, + 0x75, + 0x76, + 0x77, + 0x78, + 0x79, + 0x7A, }; const _zeroCode = 48; diff --git a/lib/src/html_input_stream.dart b/lib/src/html_input_stream.dart index 2c07f86..ee2ee79 100644 --- a/lib/src/html_input_stream.dart +++ b/lib/src/html_input_stream.dart @@ -258,6 +258,7 @@ class HtmlInputStream { return String.fromCharCodes(_chars.sublist(start, _offset)); } + String charsUntil1(int charCode, [bool opposite = false]) { final start = _offset; int? c; @@ -267,19 +268,24 @@ class HtmlInputStream { return String.fromCharCodes(_chars.sublist(start, _offset)); } + String charsUntil2(int charCode1, int charCode2, [bool opposite = false]) { final start = _offset; int? c; - while ((c = peekCodeUnit()) != null && (charCode1 == c! || charCode2 == c) == opposite) { + while ((c = peekCodeUnit()) != null && + (charCode1 == c! || charCode2 == c) == opposite) { _offset += 1; } return String.fromCharCodes(_chars.sublist(start, _offset)); } - String charsUntil3(int charCode1, int charCode2, int charCode3, [bool opposite = false]) { + + String charsUntil3(int charCode1, int charCode2, int charCode3, + [bool opposite = false]) { final start = _offset; int? c; - while ((c = peekCodeUnit()) != null && (charCode1 == c! || charCode2 == c || charCode3 == c) == opposite) { + while ((c = peekCodeUnit()) != null && + (charCode1 == c! || charCode2 == c || charCode3 == c) == opposite) { _offset += 1; } diff --git a/lib/src/tokenizer.dart b/lib/src/tokenizer.dart index 95c0bdd..2d9b906 100644 --- a/lib/src/tokenizer.dart +++ b/lib/src/tokenizer.dart @@ -419,7 +419,8 @@ class HtmlTokenizer implements Iterator { // have already been appended to lastFourChars and will have broken // any sequences } else { - final chars = stream.charsUntil3(Charcode.kAmpersand, Charcode.kLessThan, Charcode.kNull); + final chars = stream.charsUntil3( + Charcode.kAmpersand, Charcode.kLessThan, Charcode.kNull); _addToken(CharactersToken('$data$chars')); } return true; @@ -778,7 +779,8 @@ class HtmlTokenizer implements Iterator { } else if (data == eof) { state = dataState; } else { - final chars = stream.charsUntil3(Charcode.kLessThan, Charcode.kHyphen, Charcode.kNull); + final chars = stream.charsUntil3( + Charcode.kLessThan, Charcode.kHyphen, Charcode.kNull); _addToken(CharactersToken('$data$chars')); } return true; @@ -1176,7 +1178,8 @@ class HtmlTokenizer implements Iterator { state = dataState; } else { _attributeValue.write(data); - _attributeValue.write(stream.charsUntil2(Charcode.kDoubleQuote, Charcode.kAmpersand)); + _attributeValue.write( + stream.charsUntil2(Charcode.kDoubleQuote, Charcode.kAmpersand)); } return true; } @@ -1198,7 +1201,8 @@ class HtmlTokenizer implements Iterator { state = dataState; } else { _attributeValue.write(data); - _attributeValue.write(stream.charsUntil2(Charcode.kSingleQuote, Charcode.kAmpersand)); + _attributeValue.write( + stream.charsUntil2(Charcode.kSingleQuote, Charcode.kAmpersand)); } return true; } @@ -1400,7 +1404,9 @@ class HtmlTokenizer implements Iterator { _addToken(currentToken!); state = dataState; } else { - currentStringToken.add(data!).add(stream.charsUntil2(Charcode.kHyphen, Charcode.kNull)); + currentStringToken + .add(data!) + .add(stream.charsUntil2(Charcode.kHyphen, Charcode.kNull)); } return true; } diff --git a/test/parser_feature_test.dart b/test/parser_feature_test.dart index ecf8ecf..8349b41 100644 --- a/test/parser_feature_test.dart +++ b/test/parser_feature_test.dart @@ -251,8 +251,7 @@ On line 4, column 3 of ParseError: Unexpected DOCTYPE. Ignored. expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars'); expect(parser.errors[0].message, 'Unexpected non-space characters. Expected DOCTYPE.'); - expect( - parser.errors[0].toString(), + expect(parser.errors[0].toString(), 'Unexpected non-space characters. Expected DOCTYPE.'); });