Skip to content

Commit

Permalink
Make skip productions behave like the production they are wrapping.
Browse files Browse the repository at this point in the history
Closes #1586.
  • Loading branch information
rsmmr committed Apr 17, 2024
1 parent 01ea240 commit 88d75f8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
22 changes: 17 additions & 5 deletions spicy/toolchain/include/compiler/detail/codegen/productions/skip.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <hilti/ast/attribute.h>

Expand All @@ -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<std::vector<Production*>> 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; };

Expand Down
8 changes: 8 additions & 0 deletions tests/Baseline/spicy.types.unit.skip-lahead/output
Original file line number Diff line number Diff line change
@@ -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
]
}
11 changes: 11 additions & 0 deletions tests/spicy/types/unit/skip-lahead.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @TEST-EXEC: 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".";
};

0 comments on commit 88d75f8

Please sign in to comment.