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

Allow variables to have a leading digit #317

Merged

Conversation

flyingsilverfin
Copy link
Member

@flyingsilverfin flyingsilverfin commented Feb 14, 2024

Usage and product changes

We modify the behaviour of #310 which unified variables and labels to have the same valid identifier syntax, which eliminated the capability of variables to have a leading number. For example, the variable $0 was banned.

This PR reverts this specific behaviour, and enables usage of variables with leading digits:

match
$1_a isa entity;
get;

is made valid again.

Testing specified in typedb/typedb-behaviour#281

Implementation

We split the identifier regexes and grammar rules that validated labels and variables before, to be specific to Variable and Label identifiers.

@typedb-bot
Copy link
Member

typedb-bot commented Feb 14, 2024

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

  • This change is trivial and does not require a code or architecture review.

Code

  • Packages, classes, and methods have a single domain of responsibility.
  • Packages, classes, and methods are grouped into cohesive and consistent domain model.
  • The code is canonical and the minimum required to achieve the goal.
  • Modules, libraries, and APIs are easy to use, robust (foolproof and not errorprone), and tested.
  • Logic and naming has clear narrative that communicates the accurate intent and responsibility of each module (e.g. method, class, etc.).
  • The code is algorithmically efficient and scalable for the whole application.

Architecture

  • Any required refactoring is completed, and the architecture does not introduce technical debt incidentally.
  • Any required build and release automations are updated and/or implemented.
  • Any new components follows a consistent style with respect to the pre-existing codebase.
  • The architecture intuitively reflects the application domain, and is easy to understand.
  • The architecture has a well-defined hierarchy of encapsulated components.
  • The architecture is extensible and scalable.

@flyingsilverfin flyingsilverfin changed the title Allow leading var number Allow variables to have a leading digit Feb 14, 2024
IID_ : '0x' [0-9a-f]+ ;
LABEL_ : TYPE_CHAR_H_ TYPE_CHAR_T_* ;
LABEL_ : IDENTIFIER_LABEL_H IDENTIFIER_LABEL_T* ;
Copy link
Member Author

Choose a reason for hiding this comment

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

TYPE_ prefix was a hangover from the past when "label" was called "type" in the grammar. Fixed here.

LABEL_SCOPED_ = @{ IDENTIFIER ~ ":" ~ IDENTIFIER }
IDENTIFIER = @{ TYPE_CHAR_H_ ~ TYPE_CHAR_T_* ~ WB }
LABEL_ = @{ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_* ~ WB) }
LABEL_SCOPED_ = @{ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_* ) ~ ":" ~ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_* ~ WB) }
Copy link
Member Author

Choose a reason for hiding this comment

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

Duplicated Label pattern here, so we don't end up with WB inside the scoped label? Is this necessary?

grammar/TypeQL.g4 Outdated Show resolved Hide resolved
rust/common/identifier.rs Outdated Show resolved Hide resolved
rust/parser/typeql.pest Show resolved Hide resolved
Comment on lines +360 to +361
LABEL_ = @{ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_* ~ WB) }
LABEL_SCOPED_ = @{ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_*) ~ ":" ~ (IDENTIFIER_LABEL_H_ ~ IDENTIFIER_LABEL_T_*) ~ WB }
Copy link
Member

Choose a reason for hiding this comment

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

We should probably have an IDENTIFIER_LABEL_ rule.

Copy link
Member

Choose a reason for hiding this comment

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

Although the ANTLR grammar reuses LABEL_ instead. If we do that, IDENTIFIER_VAR_ might have to go as well. I'd rather we introduce both in ANTLR though.

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 just canceled them all, so we don't end up with confusion re. ~wb

Copy link
Member

Choose a reason for hiding this comment

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

This can still be @{ LABEL_ ~ ":" ~ LABEL_ }

dependencies/vaticle/repositories.bzl Outdated Show resolved Hide resolved
@flyingsilverfin flyingsilverfin merged commit bf83077 into typedb:development Feb 15, 2024
5 checks passed
@flyingsilverfin flyingsilverfin deleted the allow-leading-var-number branch February 15, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants