From 93bd80d1c298ccb5e12913a15eaf66b68be8c706 Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Wed, 8 Jan 2025 16:58:46 -0700 Subject: [PATCH] Implement remaining caveat syntax --- pkg/composableschemadsl/parser/parser.go | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pkg/composableschemadsl/parser/parser.go b/pkg/composableschemadsl/parser/parser.go index 5a35cea780..53b64dd456 100644 --- a/pkg/composableschemadsl/parser/parser.go +++ b/pkg/composableschemadsl/parser/parser.go @@ -794,7 +794,12 @@ func (p *sourceParser) consumeTestRelation() AstNode { relationNode.Connect(dslshape.NodeTestPredicateSubject, subjectNode) // optional caveat consumption - if p.tryConsumeKeyword("with") { + if !p.tryConsumeKeyword("with") { + // If we don't see the caveat marker, we stop parsing + return relationNode + } + + if !p.isKeyword("expiration") { caveatName, ok := p.consumeIdentifier() if !ok { return relationNode @@ -802,15 +807,38 @@ func (p *sourceParser) consumeTestRelation() AstNode { relationNode.MustDecorate(dslshape.NodeTestPredicateCaveatName, caveatName) // optional caveat context - if p.isToken(lexer.TokenTypeLeftBrace) { + if _, ok := p.tryConsume(lexer.TokenTypeColon); ok { caveatContextNode, ok := p.consumeOpaqueBraceExpression() if !ok { return relationNode } relationNode.Connect(dslshape.NodeTestPredicateCaveatContext, caveatContextNode) } + + // This looks a little funky, but it's to account for the fact that we can + // have a caveat or an expiration or both, and that we expect a particular order, + // and means that we don't have to write a loop here to account for the various + // possibilities. + if !p.tryConsumeKeyword("and") { + return relationNode + } } + if p.isKeyword("expiration") { + // Don't have to error check here because we've already + // looked before we leapt + p.consumeKeyword("expiration") + if _, ok := p.consume(lexer.TokenTypeColon); !ok { + return relationNode + } + + // Get the datetime string + dateString, ok := p.consume(lexer.TokenTypeString) + if !ok { + return relationNode + } + relationNode.MustDecorate(dslshape.NodeTestPredicateExpirationTime, dateString.Value) + } return relationNode }