mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
JSSpecCompiler: Parse enumerators in xspec mode
This commit is contained in:
parent
3d365326af
commit
990e30f458
13 changed files with 69 additions and 0 deletions
|
@ -185,6 +185,15 @@ void tokenize_tree(SpecificationParsingContext& ctx, TokenizerState& state, XML:
|
|||
return;
|
||||
}
|
||||
|
||||
if (element.name == tag_emu_const) {
|
||||
auto maybe_contents = get_text_contents(child);
|
||||
if (!maybe_contents.has_value())
|
||||
report_error("malformed <emu-const> subtree, expected single text child node");
|
||||
|
||||
tokens.append({ TokenType::Enumerator, maybe_contents.value_or(""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)
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace JSSpecCompiler {
|
|||
|
||||
inline constexpr StringView tag_emu_alg = "emu-alg"sv;
|
||||
inline constexpr StringView tag_emu_clause = "emu-clause"sv;
|
||||
inline constexpr StringView tag_emu_const = "emu-const"sv;
|
||||
inline constexpr StringView tag_emu_import = "emu-import"sv;
|
||||
inline constexpr StringView tag_emu_intro = "emu-intro"sv;
|
||||
inline constexpr StringView tag_emu_val = "emu-val"sv;
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
TranslationUnitRef SpecificationParsingContext::translation_unit()
|
||||
{
|
||||
return m_translation_unit;
|
||||
}
|
||||
|
||||
DiagnosticEngine& SpecificationParsingContext::diag()
|
||||
{
|
||||
return m_translation_unit->diag();
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
TranslationUnitRef translation_unit();
|
||||
DiagnosticEngine& diag();
|
||||
|
||||
template<typename Func>
|
||||
|
|
|
@ -316,6 +316,8 @@ TextParseErrorOr<Tree> TextParser::parse_expression()
|
|||
}
|
||||
}
|
||||
VERIFY(expression);
|
||||
} else if (token.type == TokenType::Enumerator) {
|
||||
expression = m_ctx.translation_unit()->get_node_for_enumerator_value(token.data);
|
||||
} else if (token.type == TokenType::Number) {
|
||||
expression = make_ref_counted<MathematicalConstant>(MUST(Crypto::BigFraction::from_string(token.data)));
|
||||
} else if (token.type == TokenType::String) {
|
||||
|
|
|
@ -30,6 +30,7 @@ constexpr i32 closing_bracket_precedence = 18;
|
|||
F(Comma, 17, Invalid, Comma, Invalid, "','") \
|
||||
F(Division, 5, Invalid, Division, Invalid, "division") \
|
||||
F(Dot, -1, Invalid, Invalid, Invalid, "punctuation mark '.'") \
|
||||
F(Enumerator, -1, Invalid, Invalid, Invalid, "enumerator") \
|
||||
F(Equals, 10, Invalid, CompareEqual, Invalid, "equals") \
|
||||
F(ExclamationMark, 3, AssertCompletion, Invalid, Invalid, "exclamation mark") \
|
||||
F(FunctionCall, 2, Invalid, FunctionCall, Invalid, "function call token") \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue