Skip to content

Commit

Permalink
Merge for 2.26.6 release (#319)
Browse files Browse the repository at this point in the history
## Usage and product changes

We merge development into master for 2.26.6 release.
  • Loading branch information
typedb-bot authored Feb 15, 2024
2 parents e65f556 + 50df243 commit 9e89657
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 88 deletions.
23 changes: 19 additions & 4 deletions RELEASE_NOTES_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Available through https://crates.io/crates/typeql.
```
cargo add [email protected]-rc0
cargo add [email protected]
```

## TypeQL Grammar and Language Library distributions for Java
Expand All @@ -20,12 +20,12 @@ cargo add [email protected]
<dependency>
<groupId>com.vaticle.typeql</groupId>
<artifactId>typeql-grammar</artifactId>
<version>2.26.6-rc0</version>
<version>2.26.6</version>
</dependency>
<dependency>
<groupId>com.vaticle.typeql</groupId>
<artifactId>typeql-lang</artifactId>
<version>2.26.6-rc0</version>
<version>2.26.6</version>
</dependency>
</dependencies>
```
Expand All @@ -35,7 +35,7 @@ cargo add [email protected]
Available through https://pypi.org

```
pip install typeql-grammar==2.26.6-rc0
pip install typeql-grammar==2.26.6
```


Expand All @@ -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**

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.26.6-rc0
2.26.6
4 changes: 2 additions & 2 deletions dependencies/vaticle/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "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 = "483eac8b122cbafe5ea154580b98aa671e51ea35", # 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
)
60 changes: 36 additions & 24 deletions grammar/TypeQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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] ;
Expand Down
20 changes: 11 additions & 9 deletions java/common/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion java/pattern/statement/builder/PredicateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion java/pattern/statement/builder/ValueStatementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueStatement> {
Expand Down
2 changes: 1 addition & 1 deletion java/query/TypeQLFetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private Label(Either<String, String> 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);
Expand Down
33 changes: 21 additions & 12 deletions rust/common/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use std::sync::OnceLock;

use regex::{Regex, RegexBuilder};

pub fn is_valid_identifier(identifier: &str) -> bool {
static REGEX: OnceLock<Regex> = 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\
Expand All @@ -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<Regex> = 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<Regex> = 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)
Expand Down
56 changes: 30 additions & 26 deletions rust/parser/typeql.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 4 additions & 2 deletions rust/pattern/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions rust/query/typeql_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -164,7 +164,7 @@ impl ProjectionKeyLabel {
}

fn must_quote(s: &str) -> bool {
!is_valid_identifier(s)
!is_valid_label_identifier(s)
}
}

Expand Down
Loading

0 comments on commit 9e89657

Please sign in to comment.