From ebe214a7bbbac85a020e41222c9dfde52acdc8d2 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Wed, 17 Apr 2024 10:31:14 +0200 Subject: [PATCH] Make skip productions behave like the production they are wrapping. Closes #1586. --- .../detail/codegen/productions/skip.h | 22 ++++++++++++++----- .../spicy.types.unit.skip-lahead/output | 8 +++++++ tests/spicy/types/unit/skip-lahead.spicy | 11 ++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 tests/Baseline/spicy.types.unit.skip-lahead/output create mode 100644 tests/spicy/types/unit/skip-lahead.spicy diff --git a/spicy/toolchain/include/compiler/detail/codegen/productions/skip.h b/spicy/toolchain/include/compiler/detail/codegen/productions/skip.h index b254c7ed5..b11ee7406 100644 --- a/spicy/toolchain/include/compiler/detail/codegen/productions/skip.h +++ b/spicy/toolchain/include/compiler/detail/codegen/productions/skip.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -26,11 +27,22 @@ class Skip : public Production { const auto& field() const { return _field; } const auto& ctor() const { return _ctor; } - bool isAtomic() const final { return true; }; - bool isEodOk() const final { return _field->attributes()->has("&eod"); }; - bool isLiteral() const final { return false; }; - bool isNullable() const final { return false; }; - bool isTerminal() const final { return true; }; + bool isAtomic() const final { return _ctor ? _ctor->isAtomic() : true; }; + bool isEodOk() const final { return _ctor ? _ctor->isEodOk() : _field->attributes()->has("&eod"); }; + bool isLiteral() const final { return _ctor ? _ctor->isLiteral() : false; }; + bool isNullable() const final { return _ctor ? _ctor->isNullable() : false; }; + bool isTerminal() const final { return _ctor ? _ctor->isTerminal() : true; }; + int64_t tokenID() const final { return _ctor ? _ctor->tokenID() : -1; }; + + std::vector> rhss() const final { + if ( _ctor ) + return _ctor->rhss(); + else + return {}; + }; + + + Expression* expression() const final { return _ctor ? _ctor->expression() : nullptr; } QualifiedType* type() const final { return _void; }; diff --git a/tests/Baseline/spicy.types.unit.skip-lahead/output b/tests/Baseline/spicy.types.unit.skip-lahead/output new file mode 100644 index 000000000..cc7dbd565 --- /dev/null +++ b/tests/Baseline/spicy.types.unit.skip-lahead/output @@ -0,0 +1,8 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +foo::X { + xs: [ + 1 + 2 + 3 + ] +} diff --git a/tests/spicy/types/unit/skip-lahead.spicy b/tests/spicy/types/unit/skip-lahead.spicy new file mode 100644 index 000000000..51a929a6e --- /dev/null +++ b/tests/spicy/types/unit/skip-lahead.spicy @@ -0,0 +1,11 @@ +# @TEST-EXEC: ${SCRIPTS}/printf '\x01\x02\x03.' | spicy-dump %INPUT >output +# @TEST-EXEC: btest-diff output +# +# @TEST-DOC: Check that look-ahead works with skipped literals + +module foo; + +public type X = unit { + xs: uint8[]; + : skip b"."; +};