mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
AK+LibXML+JSSpecCompiler: Move LineTrackingLexer to AK
This is a simple extension of GenericLexer, and is used in more than just LibXML, so let's move it into AK. The move also resolves a FIXME, which is removed in this commit.
This commit is contained in:
parent
08c02ad888
commit
bc301b6f40
8 changed files with 79 additions and 78 deletions
|
@ -14,7 +14,7 @@
|
|||
namespace JSSpecCompiler {
|
||||
|
||||
namespace {
|
||||
Optional<Token> consume_number(XML::LineTrackingLexer& lexer, Location& location)
|
||||
Optional<Token> consume_number(LineTrackingLexer& lexer, Location& location)
|
||||
{
|
||||
u64 start = lexer.tell();
|
||||
|
||||
|
@ -73,14 +73,14 @@ void tokenize_string(SpecificationParsingContext& ctx, XML::Node const* node, St
|
|||
{ "+"sv, TokenType::Plus },
|
||||
};
|
||||
|
||||
XML::LineTrackingLexer lexer(view, node->offset);
|
||||
LineTrackingLexer lexer(view, node->offset);
|
||||
|
||||
while (!lexer.is_eof()) {
|
||||
lexer.ignore_while(is_ascii_space);
|
||||
|
||||
// FIXME: This is incorrect since we count text offset after XML reference resolution. To do
|
||||
// this properly, we need support from XML::Parser.
|
||||
Location token_location = ctx.location_from_xml_offset(lexer.offset_for(lexer.tell()));
|
||||
Location token_location = ctx.location_from_xml_offset(lexer.position_for(lexer.tell()));
|
||||
|
||||
if (auto result = consume_number(lexer, token_location); result.has_value()) {
|
||||
tokens.append(result.release_value());
|
||||
|
|
|
@ -50,12 +50,12 @@ Location SpecificationParsingContext::file_scope() const
|
|||
return { .filename = m_translation_unit->filename() };
|
||||
}
|
||||
|
||||
Location SpecificationParsingContext::location_from_xml_offset(XML::Offset offset) const
|
||||
Location SpecificationParsingContext::location_from_xml_offset(LineTrackingLexer::Position position) const
|
||||
{
|
||||
return {
|
||||
.filename = m_translation_unit->filename(),
|
||||
.line = offset.line,
|
||||
.column = offset.column,
|
||||
.line = position.line,
|
||||
.column = position.column,
|
||||
.logical_location = m_current_logical_scope,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
int step_list_nesting_level() const;
|
||||
|
||||
Location file_scope() const;
|
||||
Location location_from_xml_offset(XML::Offset offset) const;
|
||||
Location location_from_xml_offset(LineTrackingLexer::Position position) const;
|
||||
|
||||
private:
|
||||
TranslationUnitRef m_translation_unit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue