diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h index 28afd0a52f..9937c96083 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h @@ -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, diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp index e855075440..cd1e8f186b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp @@ -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; } } diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h index 469ad32138..a2b173cdcf 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h @@ -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; diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Token.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Token.h index 0b6a48b552..066cbcc19b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Token.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Token.h @@ -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") diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml index 3e99dd81d2..1b2c231f64 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml @@ -24,7 +24,7 @@ 𝔽 ( floor - (nowNs / 1000000)). + (nowNs / 106)). diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml.expectation b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml.expectation index d8d93a437d..cdc17c6de0 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml.expectation +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-single-function-simple.xml.expectation @@ -17,5 +17,7 @@ TreeList UnresolvedReference floor BinaryOperation Division Var nowNs - MathematicalConstant 1000000 + BinaryOperation Power + MathematicalConstant 10 + MathematicalConstant 6