mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
JSSpecCompiler: Parse <sup> as raising a number to a power in xspec mode
This commit is contained in:
parent
394c9b7006
commit
bd26e5dce9
Notes:
sideshowbarker
2024-07-17 20:19:08 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/bd26e5dce9 Pull-request: https://github.com/SerenityOS/serenity/pull/23123 Reviewed-by: https://github.com/ADKaster ✅
6 changed files with 18 additions and 4 deletions
|
@ -253,7 +253,8 @@ protected:
|
|||
F(MemberAccess) \
|
||||
F(Minus) \
|
||||
F(Multiplication) \
|
||||
F(Plus)
|
||||
F(Plus) \
|
||||
F(Power)
|
||||
|
||||
#define NAME(name) name,
|
||||
#define STRINGIFY(name) #name##sv,
|
||||
|
|
|
@ -106,6 +106,7 @@ void tokenize_string(SpecificationParsingContext& ctx, XML::Node const* node, St
|
|||
|
||||
enum class TreeType {
|
||||
AlgorithmStep,
|
||||
NestedExpression,
|
||||
Header,
|
||||
};
|
||||
|
||||
|
@ -175,6 +176,14 @@ void tokenize_tree(SpecificationParsingContext& ctx, TokenizerState& state, XML:
|
|||
return;
|
||||
}
|
||||
|
||||
if (element.name == tag_sup) {
|
||||
tokens.append({ TokenType::Superscript, ""sv, move(child_location) });
|
||||
tokens.append({ TokenType::ParenOpen, ""sv, move(child_location) });
|
||||
tokenize_tree(ctx, state, child, TreeType::NestedExpression);
|
||||
tokens.append({ TokenType::ParenClose, ""sv, move(child_location) });
|
||||
return;
|
||||
}
|
||||
|
||||
if (tree_type == TreeType::Header && element.name == tag_span) {
|
||||
auto element_class = get_attribute_by_name(child, attribute_class);
|
||||
if (element_class != class_secnum)
|
||||
|
@ -207,7 +216,7 @@ void tokenize_tree(SpecificationParsingContext& ctx, TokenizerState& state, XML:
|
|||
[&](auto const&) {});
|
||||
}
|
||||
|
||||
if (tokens.size() && tokens.last().type == TokenType::MemberAccess)
|
||||
if (tree_type == TreeType::AlgorithmStep && tokens.size() && tokens.last().type == TokenType::MemberAccess)
|
||||
tokens.last().type = TokenType::Dot;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ inline constexpr StringView tag_ol = "ol"sv;
|
|||
inline constexpr StringView tag_p = "p"sv;
|
||||
inline constexpr StringView tag_span = "span"sv;
|
||||
inline constexpr StringView tag_specification = "specification"sv;
|
||||
inline constexpr StringView tag_sup = "sup"sv;
|
||||
inline constexpr StringView tag_var = "var"sv;
|
||||
|
||||
inline constexpr StringView attribute_aoid = "aoid"sv;
|
||||
|
|
|
@ -46,6 +46,7 @@ constexpr i32 closing_bracket_precedence = 18;
|
|||
F(Plus, 6, Invalid, Plus, Invalid, "plus") \
|
||||
F(SectionNumber, -1, Invalid, Invalid, Invalid, "section number") \
|
||||
F(String, -1, Invalid, Invalid, Invalid, "string literal") \
|
||||
F(Superscript, 4, Invalid, Power, Invalid, "subscript") \
|
||||
F(UnaryMinus, 3, Minus, Invalid, Invalid, "unary minus") \
|
||||
F(Undefined, -1, Invalid, Invalid, Invalid, "constant") \
|
||||
F(Word, -1, Invalid, Invalid, Invalid, "word")
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<emu-xref aoid="𝔽"><a href="https://tc39.es/ecma262/#𝔽">𝔽</a></emu-xref>
|
||||
(
|
||||
<emu-xref aoid="floor"><a href="https://tc39.es/ecma262/#eqn-floor">floor</a></emu-xref>
|
||||
(<var>nowNs</var> / 1000000)).
|
||||
(<var>nowNs</var> / 10<sup>6</sup>)).
|
||||
</li>
|
||||
</ol>
|
||||
</emu-alg>
|
||||
|
|
|
@ -17,5 +17,7 @@ TreeList
|
|||
UnresolvedReference floor
|
||||
BinaryOperation Division
|
||||
Var nowNs
|
||||
MathematicalConstant 1000000
|
||||
BinaryOperation Power
|
||||
MathematicalConstant 10
|
||||
MathematicalConstant 6
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue