From d06b540c30585787dff296d4026e8b7d7b4f9aef Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Tue, 30 Jan 2024 14:07:12 +0000 Subject: [PATCH 01/11] //tool/sync:dependencies vaticle/dependencies@9b751b9 --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 9ac3fd510..08c8eb331 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,12 +21,12 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "cd00aa9bc16bc2eb857b9b5e4d7a301bf19908dc", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "9b751b94caabf99e638017761b64deb0ff7c8548", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "483eac8b122cbafe5ea154580b98aa671e51ea35", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "0fe63b93c9427be2712c556d00b64c38a893ac76", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From e6d376a6a434da19b9a27715b720c791db2cb374 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Wed, 31 Jan 2024 10:55:16 +0000 Subject: [PATCH 02/11] //tool/sync:dependencies vaticle/dependencies@a97a8cf --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 08c8eb331..db6bb4bbe 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,12 +21,12 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "9b751b94caabf99e638017761b64deb0ff7c8548", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "a97a8cf4d764384d5ea09621f836856dfe0845c8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "0fe63b93c9427be2712c556d00b64c38a893ac76", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "c0f62db436eeb1b98730ee713f0df2d5edaceab9", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From ff2a1d654d76a35426f846943ae3d78a671e6f2b Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Wed, 31 Jan 2024 11:46:46 +0000 Subject: [PATCH 03/11] //tool/sync:dependencies vaticle/dependencies@248b115 --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index db6bb4bbe..ee4b10a54 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,12 +21,12 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "a97a8cf4d764384d5ea09621f836856dfe0845c8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "248b1154d713ad7afec6703a9007ad079d707e7b", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "c0f62db436eeb1b98730ee713f0df2d5edaceab9", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "06a1cbf0e9276692ead450bd582f5f17c66a0cdf", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 7c9327ce91ffa96eba21deacf1ceba7cfa531f8f Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Tue, 6 Feb 2024 14:28:27 +0000 Subject: [PATCH 04/11] //tool/sync:dependencies vaticle/dependencies@e0e7b9d --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index ee4b10a54..1013a52a3 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,12 +21,12 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "248b1154d713ad7afec6703a9007ad079d707e7b", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "e0e7b9ddd9acbe43b470ca2178a221b9f5db2381", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "06a1cbf0e9276692ead450bd582f5f17c66a0cdf", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "6b81167f7ec05e579d4c4d1c1f397e18f04853ab", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 465d28b496d586a342e5efabd15fb47f49b65bd4 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Tue, 13 Feb 2024 14:16:59 +0000 Subject: [PATCH 05/11] //tool/sync:dependencies vaticle/typedb-behaviour@031ab43 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 1013a52a3..b23dda3a5 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,5 +28,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "6b81167f7ec05e579d4c4d1c1f397e18f04853ab", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "031ab431f14f86b0ceed3b12bed8267f88868c72", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 23d6d34df276d94e8b77bc0d5a5eb31e1aec5f09 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Wed, 14 Feb 2024 16:40:09 +0000 Subject: [PATCH 06/11] //tool/sync:dependencies vaticle/typedb-behaviour@9608d28 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index b23dda3a5..6d3eb46ff 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,5 +28,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "031ab431f14f86b0ceed3b12bed8267f88868c72", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "9608d2861617d27b78ce65cce7e74683b820756a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From c33a43ea380c60425f0c3ad62e2ad14b08003eff Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Wed, 14 Feb 2024 17:36:54 +0000 Subject: [PATCH 07/11] //tool/sync:dependencies vaticle/typedb-behaviour@5c8b8a1 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 6d3eb46ff..a05c6bf36 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,5 +28,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "9608d2861617d27b78ce65cce7e74683b820756a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "5c8b8a15134a9b82f285f9405498e2409163de59", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From bf830772903e71f7aaec84dd9a4ea6114e111536 Mon Sep 17 00:00:00 2001 From: Joshua Send Date: Thu, 15 Feb 2024 09:47:21 +0000 Subject: [PATCH 08/11] Allow variables to have a leading digit (#317) ## 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 https://github.com/vaticle/typedb-behaviour/pull/281 ## Implementation We split the identifier regexes and grammar rules that validated labels and variables before, to be specific to `Variable` and `Label` identifiers. --- dependencies/vaticle/repositories.bzl | 2 +- grammar/TypeQL.g4 | 60 +++++++++++-------- java/common/Reference.java | 20 ++++--- .../builder/ConceptStatementBuilder.java | 1 - .../statement/builder/PredicateBuilder.java | 2 +- .../builder/ValueStatementBuilder.java | 2 +- java/query/TypeQLFetch.java | 2 +- rust/common/identifier.rs | 33 ++++++---- rust/parser/typeql.pest | 56 +++++++++-------- rust/pattern/label.rs | 6 +- rust/query/typeql_fetch.rs | 4 +- rust/variable/variable.rs | 4 +- 12 files changed, 110 insertions(+), 82 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index a05c6bf36..6d3eb46ff 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,5 +28,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "5c8b8a15134a9b82f285f9405498e2409163de59", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "9608d2861617d27b78ce65cce7e74683b820756a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) diff --git a/grammar/TypeQL.g4 b/grammar/TypeQL.g4 index 35b731ef7..4ede9b92a 100644 --- a/grammar/TypeQL.g4 +++ b/grammar/TypeQL.g4 @@ -332,35 +332,47 @@ DATETIME_ : DATE_FRAGMENT_ 'T' TIME_ ; VAR_CONCEPT_ : VAR_CONCEPT_ANONYMOUS_ | VAR_CONCEPT_NAMED_ ; VAR_CONCEPT_ANONYMOUS_ : '$_' ; -VAR_CONCEPT_NAMED_ : '$' TYPE_CHAR_H_ TYPE_CHAR_T_* ; -VAR_VALUE_ : '?' TYPE_CHAR_H_ TYPE_CHAR_T_* ; +VAR_CONCEPT_NAMED_ : '$' IDENTIFIER_VAR_H_ IDENTIFIER_VAR_T_* ; +VAR_VALUE_ : '?' IDENTIFIER_VAR_H_ IDENTIFIER_VAR_T_* ; IID_ : '0x' [0-9a-f]+ ; -LABEL_ : TYPE_CHAR_H_ TYPE_CHAR_T_* ; +LABEL_ : IDENTIFIER_LABEL_H_ IDENTIFIER_LABEL_T_* ; LABEL_SCOPED_ : LABEL_ ':' LABEL_ ; // FRAGMENTS OF KEYWORDS ======================================================= -fragment TYPE_CHAR_H_ : 'A'..'Z' | 'a'..'z' - | '\u00C0'..'\u00D6' - | '\u00D8'..'\u00F6' - | '\u00F8'..'\u02FF' - | '\u0370'..'\u037D' - | '\u037F'..'\u1FFF' - | '\u200C'..'\u200D' - | '\u2070'..'\u218F' - | '\u2C00'..'\u2FEF' - | '\u3001'..'\uD7FF' - | '\uF900'..'\uFDCF' - | '\uFDF0'..'\uFFFD' - ; -fragment TYPE_CHAR_T_ : TYPE_CHAR_H_ - | '0'..'9' - | '_' - | '-' - | '\u00B7' - | '\u0300'..'\u036F' - | '\u203F'..'\u2040' - ; +fragment IDENTIFIER_DIGIT_ : '0'..'9' ; +fragment IDENTIFIER_CONNECTOR_ : '_' + | '-' + | '\u00B7' + | '\u0300'..'\u036F' + | '\u203F'..'\u2040' + ; +fragment IDENTIFIER_CHAR_ :'A'..'Z' | 'a'..'z' + | '\u00C0'..'\u00D6' + | '\u00D8'..'\u00F6' + | '\u00F8'..'\u02FF' + | '\u0370'..'\u037D' + | '\u037F'..'\u1FFF' + | '\u200C'..'\u200D' + | '\u2070'..'\u218F' + | '\u2C00'..'\u2FEF' + | '\u3001'..'\uD7FF' + | '\uF900'..'\uFDCF' + | '\uFDF0'..'\uFFFD' + ; +fragment IDENTIFIER_VAR_H_ : IDENTIFIER_DIGIT_ + | IDENTIFIER_CHAR_ + ; +fragment IDENTIFIER_VAR_T_ : IDENTIFIER_DIGIT_ + | IDENTIFIER_CHAR_ + | IDENTIFIER_CONNECTOR_ + ; +fragment IDENTIFIER_LABEL_H_ : IDENTIFIER_CHAR_ ; +fragment IDENTIFIER_LABEL_T_ : IDENTIFIER_CHAR_ + | IDENTIFIER_DIGIT_ + | IDENTIFIER_CONNECTOR_ + ; + fragment DATE_FRAGMENT_ : YEAR_ '-' MONTH_ '-' DAY_ ; fragment MONTH_ : [0-1][0-9] ; fragment DAY_ : [0-3][0-9] ; diff --git a/java/common/Reference.java b/java/common/Reference.java index e02a4226c..e31754e95 100644 --- a/java/common/Reference.java +++ b/java/common/Reference.java @@ -36,7 +36,7 @@ public abstract class Reference { - private static final String IDENTIFIER_START = "A-Za-z" + + private static final String IDENTIFIER_CHAR = "A-Za-z" + "\\u00C0-\\u00D6" + "\\u00D8-\\u00F6" + "\\u00F8-\\u02FF" + @@ -48,16 +48,18 @@ public abstract class Reference { "\\u3001-\\uD7FF" + "\\uF900-\\uFDCF" + "\\uFDF0-\\uFFFD"; - private static final String IDENTIFIER_TAIL = IDENTIFIER_START + - "0-9" + - "_" + + private static final String IDENTIFIER_DIGIT = "0-9"; + private static final String IDENTIFIER_CONNECTOR = "_" + "\\-" + "\\u00B7" + "\\u0300-\\u036F" + "\\u203F-\\u2040"; - public static final Pattern IDENTIFIER_REGEX = Pattern.compile( - "^[" + IDENTIFIER_START + "][" + IDENTIFIER_TAIL + "]*$" + public static final Pattern IDENTIFIER_VAR = Pattern.compile( + "^[" + IDENTIFIER_CHAR + IDENTIFIER_DIGIT + "][" + IDENTIFIER_CHAR + IDENTIFIER_DIGIT + IDENTIFIER_CONNECTOR + "]*$" + ); + public static final Pattern IDENTIFIER_LABEL = Pattern.compile( + "^[" + IDENTIFIER_CHAR + "][" + IDENTIFIER_CHAR + IDENTIFIER_DIGIT + IDENTIFIER_CONNECTOR + "]*$" ); final Type type; @@ -155,7 +157,7 @@ public static abstract class Name extends Reference { Name(Type type, String name, boolean isVisible) { super(type, isVisible); - if (!IDENTIFIER_REGEX.matcher(name).matches()) { + if (!IDENTIFIER_VAR.matcher(name).matches()) { throw TypeQLException.of(INVALID_VARIABLE_NAME.message(name)); } this.name = name; @@ -241,9 +243,9 @@ public static class Label extends Reference { Label(String label, @Nullable String scope) { super(Type.LABEL, false); - if (!IDENTIFIER_REGEX.matcher(label).matches()) { + if (!IDENTIFIER_LABEL.matcher(label).matches()) { throw TypeQLException.of(INVALID_TYPE_LABEL.message(label)); - } else if (scope != null && !IDENTIFIER_REGEX.matcher(scope).matches()) { + } else if (scope != null && !IDENTIFIER_LABEL.matcher(scope).matches()) { throw TypeQLException.of(INVALID_TYPE_LABEL.message(scope)); } this.label = label; diff --git a/java/pattern/statement/builder/ConceptStatementBuilder.java b/java/pattern/statement/builder/ConceptStatementBuilder.java index 98c61ec23..6ff5adc35 100644 --- a/java/pattern/statement/builder/ConceptStatementBuilder.java +++ b/java/pattern/statement/builder/ConceptStatementBuilder.java @@ -21,7 +21,6 @@ package com.vaticle.typeql.lang.pattern.statement.builder; -import com.vaticle.typeql.lang.common.Reference; import com.vaticle.typeql.lang.common.TypeQLVariable; import com.vaticle.typeql.lang.pattern.constraint.ConceptConstraint; import com.vaticle.typeql.lang.pattern.statement.ConceptStatement; diff --git a/java/pattern/statement/builder/PredicateBuilder.java b/java/pattern/statement/builder/PredicateBuilder.java index 995aebe5a..6c5eec347 100644 --- a/java/pattern/statement/builder/PredicateBuilder.java +++ b/java/pattern/statement/builder/PredicateBuilder.java @@ -22,9 +22,9 @@ package com.vaticle.typeql.lang.pattern.statement.builder; import com.vaticle.typeql.lang.common.TypeQLToken; +import com.vaticle.typeql.lang.common.TypeQLVariable; import com.vaticle.typeql.lang.pattern.constraint.Predicate; import com.vaticle.typeql.lang.pattern.statement.Statement; -import com.vaticle.typeql.lang.common.TypeQLVariable; import java.time.LocalDateTime; import java.util.function.BiFunction; diff --git a/java/pattern/statement/builder/ValueStatementBuilder.java b/java/pattern/statement/builder/ValueStatementBuilder.java index f07cd93b9..b27d1f2a7 100644 --- a/java/pattern/statement/builder/ValueStatementBuilder.java +++ b/java/pattern/statement/builder/ValueStatementBuilder.java @@ -21,8 +21,8 @@ package com.vaticle.typeql.lang.pattern.statement.builder; -import com.vaticle.typeql.lang.pattern.expression.Expression; import com.vaticle.typeql.lang.pattern.constraint.ValueConstraint; +import com.vaticle.typeql.lang.pattern.expression.Expression; import com.vaticle.typeql.lang.pattern.statement.ValueStatement; public interface ValueStatementBuilder extends PredicateBuilder { diff --git a/java/query/TypeQLFetch.java b/java/query/TypeQLFetch.java index 614e53f53..8bc399f94 100644 --- a/java/query/TypeQLFetch.java +++ b/java/query/TypeQLFetch.java @@ -330,7 +330,7 @@ private Label(Either quotedOrUnquoted) { } public static Label of(String label) { - if (Reference.IDENTIFIER_REGEX.matcher(label).matches()) { + if (Reference.IDENTIFIER_LABEL.matcher(label).matches()) { return unquoted(label); } else { return quoted(label); diff --git a/rust/common/identifier.rs b/rust/common/identifier.rs index bfef540b4..07d88a0e6 100644 --- a/rust/common/identifier.rs +++ b/rust/common/identifier.rs @@ -23,10 +23,7 @@ use std::sync::OnceLock; use regex::{Regex, RegexBuilder}; -pub fn is_valid_identifier(identifier: &str) -> bool { - static REGEX: OnceLock = OnceLock::new(); - let regex = REGEX.get_or_init(|| { - let identifier_start = "A-Za-z\ +const IDENTIFIER_CHAR: &str = "A-Za-z\ \\u00C0-\\u00D6\ \\u00D8-\\u00F6\ \\u00F8-\\u02FF\ @@ -38,17 +35,29 @@ pub fn is_valid_identifier(identifier: &str) -> bool { \\u3001-\\uD7FF\ \\uF900-\\uFDCF\ \\uFDF0-\\uFFFD"; - let identifier_tail = format!( - "{}\ - 0-9\ - _\ +const IDENTIFIER_CONNECTOR: &str = "_\ \\-\ \\u00B7\ \\u0300-\\u036F\ - \\u203F-\\u2040", - identifier_start - ); - let identifier_pattern = format!("^[{}][{}]*$", identifier_start, identifier_tail); + \\u203F-\\u2040"; +const IDENTIFIER_DIGIT: &str = "0-9"; + +pub fn is_valid_label_identifier(identifier: &str) -> bool { + static REGEX: OnceLock = OnceLock::new(); + let regex = REGEX.get_or_init(|| { + let identifier_tail = format!("{}{}{}", IDENTIFIER_CHAR, IDENTIFIER_CONNECTOR, IDENTIFIER_DIGIT); + let identifier_pattern = format!("^[{}][{}]*$", IDENTIFIER_CHAR, identifier_tail); + RegexBuilder::new(&identifier_pattern).build().unwrap() + }); + regex.is_match(identifier) +} + +pub fn is_valid_var_identifier(identifier: &str) -> bool { + static REGEX: OnceLock = OnceLock::new(); + let regex = REGEX.get_or_init(|| { + let identifier_head = format!("{}{}", IDENTIFIER_CHAR, IDENTIFIER_DIGIT); + let identifier_tail = format!("{}{}{}", IDENTIFIER_CHAR, IDENTIFIER_DIGIT, IDENTIFIER_CONNECTOR); + let identifier_pattern = format!("^[{}][{}]*$", identifier_head, identifier_tail); RegexBuilder::new(&identifier_pattern).build().unwrap() }); regex.is_match(identifier) diff --git a/rust/parser/typeql.pest b/rust/parser/typeql.pest index c0a818e37..d9fe343d2 100644 --- a/rust/parser/typeql.pest +++ b/rust/parser/typeql.pest @@ -354,37 +354,41 @@ DATETIME_ = @{ DATE_FRAGMENT_ ~ "T" ~ TIME_ ~ WB } VAR_ = ${ VAR_CONCEPT_ | VAR_VALUE_ } VAR_CONCEPT_ = @{ VAR_CONCEPT_ANONYMOUS_ | VAR_CONCEPT_NAMED_ } VAR_CONCEPT_ANONYMOUS_ = @{ "$_" ~ WB } -VAR_CONCEPT_NAMED_ = @{ "$" ~ IDENTIFIER } -VAR_VALUE_ = @{ "?" ~ IDENTIFIER } +VAR_CONCEPT_NAMED_ = @{ "$" ~ IDENTIFIER_VAR_H_ ~ IDENTIFIER_VAR_T_* ~ WB } +VAR_VALUE_ = @{ "?" ~ (IDENTIFIER_VAR_H_ ~ IDENTIFIER_VAR_T_* ~ WB) } IID_ = @{ "0x" ~ ASCII_HEX_DIGIT+ ~ WB } -LABEL_ = @{ IDENTIFIER } -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 } // FRAGMENTS OF KEYWORDS ======================================================= -TYPE_CHAR_H_ = @{ ASCII_ALPHA - | '\u{00C0}'..'\u{00D6}' - | '\u{00D8}'..'\u{00F6}' - | '\u{00F8}'..'\u{02FF}' - | '\u{0370}'..'\u{037D}' - | '\u{037F}'..'\u{1FFF}' - | '\u{200C}'..'\u{200D}' - | '\u{2070}'..'\u{218F}' - | '\u{2C00}'..'\u{2FEF}' - | '\u{3001}'..'\u{D7FF}' - | '\u{F900}'..'\u{FDCF}' - | '\u{FDF0}'..'\u{FFFD}' - } -TYPE_CHAR_T_ = @{ TYPE_CHAR_H_ - | ASCII_DIGIT - | "_" - | "-" - | "\u{00B7}" - | '\u{0300}'..'\u{036F}' - | '\u{203F}'..'\u{2040}' - } +IDENTIFIER_CHAR_ = @{ ASCII_ALPHA + | '\u{00C0}'..'\u{00D6}' + | '\u{00D8}'..'\u{00F6}' + | '\u{00F8}'..'\u{02FF}' + | '\u{0370}'..'\u{037D}' + | '\u{037F}'..'\u{1FFF}' + | '\u{200C}'..'\u{200D}' + | '\u{2070}'..'\u{218F}' + | '\u{2C00}'..'\u{2FEF}' + | '\u{3001}'..'\u{D7FF}' + | '\u{F900}'..'\u{FDCF}' + | '\u{FDF0}'..'\u{FFFD}' + } +IDENTIFIER_CONNECTOR_ = @{ "_" + | "-" + | "\u{00B7}" + | '\u{0300}'..'\u{036F}' + | '\u{203F}'..'\u{2040}' + } + +IDENTIFIER_LABEL_H_ = @{ IDENTIFIER_CHAR_ } +IDENTIFIER_LABEL_T_ = @{ IDENTIFIER_LABEL_H_ | ASCII_DIGIT | IDENTIFIER_CONNECTOR_ } + +IDENTIFIER_VAR_H_ = @{ IDENTIFIER_CHAR_ | ASCII_DIGIT } +IDENTIFIER_VAR_T_ = @{ IDENTIFIER_VAR_H_ | IDENTIFIER_CONNECTOR_ } + DATE_FRAGMENT_ = @{ YEAR_ ~ "-" ~ MONTH_ ~ "-" ~ DAY_ } MONTH_ = @{ ('0'..'1') ~ ASCII_DIGIT } DAY_ = @{ ('0'..'3') ~ ASCII_DIGIT } diff --git a/rust/pattern/label.rs b/rust/pattern/label.rs index 079e0457c..00b0f6fd4 100644 --- a/rust/pattern/label.rs +++ b/rust/pattern/label.rs @@ -22,7 +22,9 @@ use std::fmt; -use crate::common::{error::TypeQLError, identifier::is_valid_identifier, token, validatable::Validatable, Result}; +use crate::common::{ + error::TypeQLError, identifier::is_valid_label_identifier, token, validatable::Validatable, Result, +}; #[derive(Debug, Clone, Eq, PartialEq)] pub struct Label { @@ -71,7 +73,7 @@ impl Validatable for Label { } fn validate_label(label: &str) -> Result { - if !is_valid_identifier(label) { + if !is_valid_label_identifier(label) { Err(TypeQLError::InvalidTypeLabel { label: label.to_owned() })? } else { Ok(()) diff --git a/rust/query/typeql_fetch.rs b/rust/query/typeql_fetch.rs index 7bba265f8..8a0042a8e 100644 --- a/rust/query/typeql_fetch.rs +++ b/rust/query/typeql_fetch.rs @@ -26,7 +26,7 @@ use itertools::Itertools; use crate::{ common::{ error::{collect_err, TypeQLError}, - identifier::is_valid_identifier, + identifier::is_valid_label_identifier, string::indent, token, validatable::Validatable, @@ -164,7 +164,7 @@ impl ProjectionKeyLabel { } fn must_quote(s: &str) -> bool { - !is_valid_identifier(s) + !is_valid_label_identifier(s) } } diff --git a/rust/variable/variable.rs b/rust/variable/variable.rs index ab39bf7f6..8204836f2 100644 --- a/rust/variable/variable.rs +++ b/rust/variable/variable.rs @@ -23,7 +23,7 @@ use std::{fmt, fmt::Formatter, hash::Hash}; use crate::{ - common::{error::TypeQLError, identifier::is_valid_identifier, validatable::Validatable, Result}, + common::{error::TypeQLError, identifier::is_valid_var_identifier, validatable::Validatable, Result}, variable::{ConceptVariable, ValueVariable}, }; @@ -119,7 +119,7 @@ impl fmt::Display for VariableRef<'_> { } pub(crate) fn validate_variable_name(name: &str) -> Result { - if !is_valid_identifier(name) { + if !is_valid_var_identifier(name) { Err(TypeQLError::InvalidVariableName { name: name.to_owned() })? } Ok(()) From 0960ffc960b0b4d10556987a8882ae5a6d557ce4 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Thu, 15 Feb 2024 13:27:55 +0000 Subject: [PATCH 09/11] //tool/sync:dependencies vaticle/typedb-behaviour@0d000e4 --- dependencies/vaticle/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 6d3eb46ff..517117691 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -28,5 +28,5 @@ def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "9608d2861617d27b78ce65cce7e74683b820756a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "0d000e49669f9812c9de7322e82188084c88cfd7", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 52bb07d6f10c768793a5261ac06742fc360c4122 Mon Sep 17 00:00:00 2001 From: vaticle-bot Date: Thu, 15 Feb 2024 14:47:10 +0000 Subject: [PATCH 10/11] //tool/sync:dependencies vaticle/dependencies@08d4e3b --- dependencies/vaticle/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/vaticle/repositories.bzl b/dependencies/vaticle/repositories.bzl index 517117691..bad6c6a32 100644 --- a/dependencies/vaticle/repositories.bzl +++ b/dependencies/vaticle/repositories.bzl @@ -21,12 +21,12 @@ def vaticle_dependencies(): git_repository( name = "vaticle_dependencies", remote = "https://github.com/vaticle/dependencies", - commit = "e0e7b9ddd9acbe43b470ca2178a221b9f5db2381", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies + commit = "08d4e3bafb5a90db76eb5188be6f90bee564eb01", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies ) def vaticle_typedb_behaviour(): git_repository( name = "vaticle_typedb_behaviour", remote = "https://github.com/vaticle/typedb-behaviour", - commit = "0d000e49669f9812c9de7322e82188084c88cfd7", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour + commit = "f996fb7322eabfaafdbbf203a59fdc27fd6babf0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour ) From 50df243455f85a40e11a974469f1d777bebfefca Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:29:18 +0300 Subject: [PATCH 11/11] Update VERSION to 2.26.6 and create release notes (#318) ## Usage and product changes We update VERSION to 2.26.6 and create release notes. --- RELEASE_NOTES_LATEST.md | 23 +++++++++++++++++++---- VERSION | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/RELEASE_NOTES_LATEST.md b/RELEASE_NOTES_LATEST.md index a25c7a8a9..e79b46b9c 100644 --- a/RELEASE_NOTES_LATEST.md +++ b/RELEASE_NOTES_LATEST.md @@ -3,7 +3,7 @@ Available through https://crates.io/crates/typeql. ``` -cargo add typeql@2.26.6-rc0 +cargo add typeql@2.26.6 ``` ## TypeQL Grammar and Language Library distributions for Java @@ -20,12 +20,12 @@ cargo add typeql@2.26.6-rc0 com.vaticle.typeql typeql-grammar - 2.26.6-rc0 + 2.26.6 com.vaticle.typeql typeql-lang - 2.26.6-rc0 + 2.26.6 ``` @@ -35,7 +35,7 @@ cargo add typeql@2.26.6-rc0 Available through https://pypi.org ``` -pip install typeql-grammar==2.26.6-rc0 +pip install typeql-grammar==2.26.6 ``` @@ -62,6 +62,21 @@ pip install typeql-grammar==2.26.6-rc0 ## Code Refactors +- **Allow variables to have a leading digit** + + 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 https://github.com/vaticle/typedb-behaviour/pull/281 + + - **Merge typedb-common repository into typeql** diff --git a/VERSION b/VERSION index 74111246f..16b932673 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.26.6-rc0 +2.26.6