JSSpecCompiler: Parse <sup> as raising a number to a power in xspec mode

This commit is contained in:
Dan Klishch 2024-01-20 20:54:03 -05:00 committed by Andrew Kaster
parent 394c9b7006
commit bd26e5dce9
6 changed files with 18 additions and 4 deletions

View file

@ -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,

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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")

View file

@ -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>

View file

@ -17,5 +17,7 @@ TreeList
UnresolvedReference floor
BinaryOperation Division
Var nowNs
MathematicalConstant 1000000
BinaryOperation Power
MathematicalConstant 10
MathematicalConstant 6