beggining to stablish the EBNF of spider assembly

This commit is contained in:
2026-07-19 22:43:23 -06:00
parent b30a59accd
commit 3a44ec594a
7 changed files with 114 additions and 121 deletions
+9 -19
View File
@@ -3,23 +3,13 @@
#include <spider/compiler/common.hpp>
#include <spider/compiler/text/utf8.hpp>
#include <spider/compiler/text/TextReader.hpp>
namespace spider {
struct TokenContext {
std::u32string_view input;
size_t cursor = 0;
bool has_more() const { return cursor < input.size(); }
char32_t peek() const { return input[cursor]; }
void advance(size_t n = 1) { cursor += n; }
};
/**
* @brief The structural payload returned by every parsing component execution.
*/
* @brief The structural payload returned by every parsing component execution.
*/
struct TokenResult {
/** @brief Indicates if the token composition successfully matched the input boundary. */
@@ -58,7 +48,7 @@ namespace spider {
* @return TokenResult Containing verification state and the parsed copy of matching data.
* @note Pure virtual; implementation details handle node-specific combinator semantics.
*/
virtual TokenResult test(TokenContext& ctx) const = 0;
virtual TokenResult test(TextReader& ctx) const = 0;
public:
@@ -111,7 +101,7 @@ namespace spider {
* @brief Validates match of the backing u32string exactly at the context cursor pointer.
* @details Advances the context cursor precisely by literal length on success; zero state mutation on failure.
*/
TokenResult test(TokenContext& ctx) const override;
TokenResult test(TextReader& ctx) const override;
};
/**
@@ -135,7 +125,7 @@ namespace spider {
* @details Implements a strict transaction boundary: if any internal element fails, the index
* backtracks entirely to its starting cursor value before returning failure.
*/
TokenResult test(TokenContext& ctx) const override;
TokenResult test(TextReader& ctx) const override;
/** @brief Intrusive override for fluid cascading sequencing (`rule1 & rule2 & rule3`). */
SeqToken operator&(const Token& tok) override;
@@ -158,7 +148,7 @@ namespace spider {
* @brief Scans through alternatives, resolving immediately on the first candidate that passes.
* @details Safely rolls back changes to the context cursor point between failed alternative attempts.
*/
TokenResult test(TokenContext& ctx) const override;
TokenResult test(TextReader& ctx) const override;
/** @brief Intrusive override for cascading alternation chains (`ruleA | ruleB | ruleC`). */
OrToken operator|(const Token& tok) override;
@@ -181,7 +171,7 @@ namespace spider {
* @brief Evaluates target presence. Returns success true regardless of sub-rule evaluation outcome.
* @details If the nested rule fails, the context cursor rolls back to initial state, returning empty matches.
*/
TokenResult test(TokenContext& ctx) const override;
TokenResult test(TextReader& ctx) const override;
/** @brief Stub override providing standard compliance with the base Token interface signature. */
OptToken operator~() override;
@@ -205,7 +195,7 @@ namespace spider {
* @details Includes internal safety loops checking cursor delta advancement to guarantee infinite
* empty-matching sub-loops do not cause thread lockups.
*/
TokenResult test(TokenContext& ctx) const override;
TokenResult test(TextReader& ctx) const override;
/** @brief Stub override providing standard compliance with the base Token interface signature. */
RepToken operator*() override;