mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
JSSpecCompiler: Parse <sup> as raising a number to a power in xspec mode
This commit is contained in:
parent
394c9b7006
commit
bd26e5dce9
6 changed files with 18 additions and 4 deletions
|
@ -253,7 +253,8 @@ protected:
|
||||||
F(MemberAccess) \
|
F(MemberAccess) \
|
||||||
F(Minus) \
|
F(Minus) \
|
||||||
F(Multiplication) \
|
F(Multiplication) \
|
||||||
F(Plus)
|
F(Plus) \
|
||||||
|
F(Power)
|
||||||
|
|
||||||
#define NAME(name) name,
|
#define NAME(name) name,
|
||||||
#define STRINGIFY(name) #name##sv,
|
#define STRINGIFY(name) #name##sv,
|
||||||
|
|
|
@ -106,6 +106,7 @@ void tokenize_string(SpecificationParsingContext& ctx, XML::Node const* node, St
|
||||||
|
|
||||||
enum class TreeType {
|
enum class TreeType {
|
||||||
AlgorithmStep,
|
AlgorithmStep,
|
||||||
|
NestedExpression,
|
||||||
Header,
|
Header,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,6 +176,14 @@ void tokenize_tree(SpecificationParsingContext& ctx, TokenizerState& state, XML:
|
||||||
return;
|
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) {
|
if (tree_type == TreeType::Header && element.name == tag_span) {
|
||||||
auto element_class = get_attribute_by_name(child, attribute_class);
|
auto element_class = get_attribute_by_name(child, attribute_class);
|
||||||
if (element_class != class_secnum)
|
if (element_class != class_secnum)
|
||||||
|
@ -207,7 +216,7 @@ void tokenize_tree(SpecificationParsingContext& ctx, TokenizerState& state, XML:
|
||||||
[&](auto const&) {});
|
[&](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;
|
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_p = "p"sv;
|
||||||
inline constexpr StringView tag_span = "span"sv;
|
inline constexpr StringView tag_span = "span"sv;
|
||||||
inline constexpr StringView tag_specification = "specification"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 tag_var = "var"sv;
|
||||||
|
|
||||||
inline constexpr StringView attribute_aoid = "aoid"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(Plus, 6, Invalid, Plus, Invalid, "plus") \
|
||||||
F(SectionNumber, -1, Invalid, Invalid, Invalid, "section number") \
|
F(SectionNumber, -1, Invalid, Invalid, Invalid, "section number") \
|
||||||
F(String, -1, Invalid, Invalid, Invalid, "string literal") \
|
F(String, -1, Invalid, Invalid, Invalid, "string literal") \
|
||||||
|
F(Superscript, 4, Invalid, Power, Invalid, "subscript") \
|
||||||
F(UnaryMinus, 3, Minus, Invalid, Invalid, "unary minus") \
|
F(UnaryMinus, 3, Minus, Invalid, Invalid, "unary minus") \
|
||||||
F(Undefined, -1, Invalid, Invalid, Invalid, "constant") \
|
F(Undefined, -1, Invalid, Invalid, Invalid, "constant") \
|
||||||
F(Word, -1, Invalid, Invalid, Invalid, "word")
|
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="𝔽"><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>
|
<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>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</emu-alg>
|
</emu-alg>
|
||||||
|
|
|
@ -17,5 +17,7 @@ TreeList
|
||||||
UnresolvedReference floor
|
UnresolvedReference floor
|
||||||
BinaryOperation Division
|
BinaryOperation Division
|
||||||
Var nowNs
|
Var nowNs
|
||||||
MathematicalConstant 1000000
|
BinaryOperation Power
|
||||||
|
MathematicalConstant 10
|
||||||
|
MathematicalConstant 6
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue