Skip to content

Commit ff46a9b

Browse files
Add built-in functions iid() and label() (#427)
## Product change and motivation We add `iid()` and `label()` to the built-in functions in the TypeQL grammar. ## Implementation
1 parent 3011a31 commit ff46a9b

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

dependencies/typedb/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def typedb_behaviour():
1515
git_repository(
1616
name = "typedb_behaviour",
1717
remote = "https://github.com/typedb/typedb-behaviour",
18-
commit = "27d8ada76fe0d066a6035dfdef353408232f807a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_behaviour
18+
commit = "cf13e741844025a8a0210f25dc295ce966e26d16", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_behaviour
1919
)

rust/common/token.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ string_enum! { Function
198198
Abs = "abs",
199199
Ceil = "ceil",
200200
Floor = "floor",
201+
Iid = "iid",
202+
Label = "label",
203+
Len = "len",
201204
Max = "max",
202205
Min = "min",
203206
Round = "round",
204-
Length = "length",
205207
}
206208

207209
string_enum! { Char

rust/parser/expression.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ fn visit_builtin_func_name(node: Node<'_>) -> BuiltinFunctionName {
160160
Rule::ABS => token::Function::Abs,
161161
Rule::CEIL => token::Function::Ceil,
162162
Rule::FLOOR => token::Function::Floor,
163-
Rule::LENGTH => token::Function::Length,
163+
Rule::IID => token::Function::Iid,
164+
Rule::LABEL => token::Function::Label,
165+
Rule::LEN => token::Function::Len,
164166
Rule::MAX => token::Function::Max,
165167
Rule::MIN => token::Function::Min,
166168
Rule::ROUND => token::Function::Round,

rust/parser/typeql.pest

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ operator_offset = { OFFSET ~ integer_literal ~ SEMICOLON }
4646
operator_limit = { LIMIT ~ integer_literal ~ SEMICOLON }
4747
operator_require = { REQUIRE ~ vars ~ SEMICOLON }
4848
operator_distinct = { DISTINCT ~ SEMICOLON }
49-
operator_reduce = { REDUCE ~ reduce_assign ~ ( COMMA ~ reduce_assign )* ~ COMMA? ~ (GROUPBY ~ vars )? ~ SEMICOLON }
49+
operator_reduce = { REDUCE ~ reduce_assign ~ ( COMMA ~ reduce_assign )* ~ COMMA? ~ ( GROUPBY ~ vars )? ~ SEMICOLON }
5050

5151
var_order = { var ~ ORDER? }
52-
reduce_assign = { (reduce_assignment_var ~ ASSIGN ~ reducer) }
52+
reduce_assign = { ( reduce_assignment_var ~ ASSIGN ~ reducer ) }
5353

5454
reduce_assignment_var = { var_optional | var }
5555
reducer = { COUNT ~ ( PAREN_OPEN ~ var ~ PAREN_CLOSE )?
@@ -99,13 +99,13 @@ plays_constraint = { PLAYS ~ type_ref }
9999

100100
// THING STATEMENTS ============================================================
101101
statement_thing = { var ~ COMMA? ~ thing_constraint_list
102-
| thing_relation_anonymous ~ (COMMA? ~ thing_constraint_list)?
102+
| thing_relation_anonymous ~ ( COMMA? ~ thing_constraint_list )?
103103
}
104104
thing_relation_anonymous = { type_ref? ~ relation }
105-
thing_constraint_list = {thing_constraint ~ (COMMA ~ thing_constraint)* ~ COMMA?}
105+
thing_constraint_list = {thing_constraint ~ ( COMMA ~ thing_constraint )* ~ COMMA?}
106106

107107
thing_constraint = { isa_constraint | iid_constraint | has_constraint | links_constraint }
108-
isa_constraint = { ISA_ ~ type_ref ~ (relation | expression | value_literal | expression_struct | comparison)? }
108+
isa_constraint = { ISA_ ~ type_ref ~ ( relation | expression | value_literal | expression_struct | comparison )? }
109109
iid_constraint = { IID ~ iid_value }
110110
has_constraint = { HAS ~ type_ref_list ~ ( comparison | expression_list | var )
111111
| HAS ~ type_ref ~ ( comparison | expression_value | var )
@@ -377,7 +377,7 @@ reserved = { WITH | MATCH | FETCH | UPDATE | DEFINE | UNDEFINE | REDEFINE | INSE
377377
| FIRST | LAST
378378
}
379379

380-
unreserved = { ABS | CEIL | FLOOR | ROUND | LENGTH
380+
unreserved = { ABS | CEIL | FLOOR | ROUND | LEN
381381
| CHECK | FIRST
382382
| COUNT | MAX | MIN | MEAN | MEDIAN | STD | SUM | LIST
383383
| VALUE | SELECT | SORT | LIMIT | OFFSET | GROUP | LIKE | CONTAINS
@@ -517,11 +517,16 @@ POWER = @{ "^" }
517517
MODULO = @{ "%" }
518518

519519
// Incomplete list of function names usable in expressions. The 'expression_function_name' rule references all function names.
520-
builtin_func_name = ${ ABS | CEIL | FLOOR | ROUND | LENGTH | MAX | MIN }
520+
builtin_func_name = ${ ABS
521+
| CEIL | FLOOR | ROUND
522+
| LEN
523+
| MAX | MIN
524+
| LABEL | IID
525+
}
521526
ABS = @{ "abs" ~ WB }
522527
CEIL = @{ "ceil" ~ WB }
523528
FLOOR = @{ "floor" ~ WB }
524-
LENGTH = @{ "length" ~ WB }
529+
LEN = @{ "len" ~ WB }
525530
ROUND = @{ "round" ~ WB }
526531

527532
// GROUP AND AGGREGATE QUERY KEYWORDS

0 commit comments

Comments
 (0)