Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser changes for supporting relationship expiration #2141

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

josephschorr
Copy link
Member

Step 1 of support for first-class relationship expiration: parser changes

This adds a concept of a "flaggable" lexer which, when detecting a `use (flag)` statement, runs a transformation to change the tokens returned to the parent. This is currently used to rewrite certain identifiers as keywords.
@josephschorr josephschorr requested a review from a team as a code owner November 25, 2024 18:38
@github-actions github-actions bot added area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Nov 25, 2024
Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, had some questions/comments

@@ -11,6 +11,7 @@ const (
NodeTypeError NodeType = iota // error occurred; value is text of error
NodeTypeFile // The file root node
NodeTypeComment // A single or multiline comment
NodeTypeUseFlag // A use flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we worried about shifting the order of subsequent node types?

If not, I'll probably change some of how I'm doing my work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the order shouldn't matter here. All references are by names, and the tests all use the names too

{TokenTypeKeyword, 0, "expiration", ""},
tEOF,
}},
{"use expiration and", "use expiration and", []Lexeme{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What role does and play here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relation viewer: user with caveat and expiration - the and is a keyword in this case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to the new lexer; we no longer had a peek on it

if p.isToken(lexer.TokenTypeIdentifier) {
useFlag, _ = p.consumeIdentifier()
} else {
useName, ok := p.consumeVariableKeyword()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea being that under some schema version, this is potentially already a keyword?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a keyword when the use rule is in place, but not a keyword for invalid rules

@@ -35,7 +35,7 @@ NodeTypeFile
caveat-name = somecaveat
end-rune = 67
input-source = caveats type test
start-rune = 53
start-rune = 58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of surprising - is this because with was previously a part of the caveat definition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

start-rune = 0
NodeTypeError
end-rune = 22
error-message = Unexpected token at root level: TokenTypeIdentifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to make this error more specific without special handling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not easily, no

@josephschorr josephschorr added this pull request to the merge queue Nov 25, 2024
Merged via the queue into authzed:main with commit 7ff8fb1 Nov 25, 2024
22 checks passed
@josephschorr josephschorr deleted the rel-expiration-parser branch November 25, 2024 22:27
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants