List of key or reserved words?

Working on a schema and when I enter:

type sub attribute, value string;

displays red, I think signaling it is a keyword.

When trying to run the query I got a "extraneous input ‘type’ expecting.

Is there a quick reference for reserved words? (Type comes up a lot in XML but here I can use wtype (word type), ctype( (clause type) without much difficulty.)

Further confused because it did accept:

rule sub attribute, value string;

if type is a reserved word, shouldn’t rule be as well?

Thanks!

Patrick

Hi Patrick,

There’s no single list of reserved words, but you can check out the TypeQL grammar file, which contains the rules for TypeQL words. I’ve copied in the relevant portion of that file below:

// LITERAL INPUT VALUES ========================================================

schema_native         :   RULE            ;

type_native           :   THING           |   ENTITY          |   ATTRIBUTE
                      |   RELATION        |   ROLE            ;

value_type            :   LONG            |   DOUBLE          |   STRING
                      |   BOOLEAN         |   DATETIME        ;
value                 :   STRING_         |   BOOLEAN_
                      |   DATE_           |   DATETIME_
                      |   signed_long     |   signed_double   ;

signed_long           :   sign?  LONG_    ;
signed_double         :   sign?  DOUBLE_  ;
sign                  :   ADD             |  SUBTRACT         ;

// UNRESERVED KEYWORDS =========================================================
// Most of TypeQL syntax should not be reserved from being used as identifiers

unreserved            : VALUE | EXPR_FUNC_NAME
                      | MIN | MAX | MEDIAN | MEAN | STD | SUM | COUNT
                      | GET | SORT | LIMIT | OFFSET | GROUP | CONTAINS
                      ;

// TYPEQL SYNTAX KEYWORDS =======================================================

// QUERY COMMAND KEYWORDS

MATCH           : 'match'       ;   GET             : 'get'         ;
DEFINE          : 'define'      ;   UNDEFINE        : 'undefine'    ;
INSERT          : 'insert'      ;   DELETE          : 'delete'      ;
COMPUTE         : 'compute'     ;

// NATIVE TYPE KEYWORDS

THING           : 'thing'       ;   ENTITY          : 'entity'      ;
ATTRIBUTE       : 'attribute'   ;   RELATION        : 'relation'    ;
ROLE            : 'role'        ;   RULE            : 'rule'        ;

// DELETE AND GET QUERY MODIFIER KEYWORDS

OFFSET          : 'offset'      ;   LIMIT           : 'limit'       ;
SORT            : 'sort'        ;   ORDER_          : ASC | DESC    ;
ASC             : 'asc'         ;   DESC            : 'desc'        ;

// TYPE VARIABLE CONSTRAINT KEYWORDS

TYPE            : 'type'        ;
ABSTRACT        : 'abstract'    ;   SUB_            : SUB | SUBX    ;
SUB             : 'sub'         ;   SUBX            : 'sub!'        ;
OWNS            : 'owns'        ;
REGEX           : 'regex'       ;   AS              : 'as'          ;
PLAYS           : 'plays'       ;   RELATES         : 'relates'     ;
WHEN            : 'when'        ;   THEN            : 'then'        ;

// TYPE ANNOTATIONS

ANNOTATION_KEY            : '@key';
ANNOTATION_UNIQUE         : '@unique';

// THING VARIABLE CONSTRAINT KEYWORDS

IID             : 'iid'         ;   ISA_            : ISA | ISAX    ;
ISA             : 'isa'         ;   ISAX            : 'isa!'        ;
HAS             : 'has'         ;   VALUE           : 'value'       ;
IS              : 'is'          ;

// OPERATOR KEYWORDS

OR              : 'or'          ;   NOT             : 'not'         ;

// PREDICATE KEYWORDS

EQ              : '=='          ;   NEQ             : '!='          ;
GT              : '>'           ;   GTE             : '>='          ;
LT              : '<'           ;   LTE             : '<='          ;
LIKE            : 'like'        ;   CONTAINS        : 'contains'    ;

// ASSIGNMENT AND EXPRESSION KEYWORDS

ASSIGN          : '='           ;
ADD             : '+'           ;   SUBTRACT        : '-'           ;
DIVIDE          : '/'           ;   MULTIPLY        : '*'           ;
POWER           : '^'           ;   MODULO          : '%'           ;
PAREN_OPEN      : '('           ;   PAREN_CLOSE     : ')'           ;

// Incomplete list of function names usable in expressions. The 'func_name' rule references all function names.
EXPR_FUNC_NAME  :  'floor' | 'ceil' | 'round' | 'abs'               ;

// GROUP AND AGGREGATE QUERY KEYWORDS (also used by COMPUTE QUERY)

GROUP           : 'group'       ;   COUNT           : 'count'       ;
MAX             : 'max'         ;   MIN             : 'min'         ;
MEAN            : 'mean'        ;   MEDIAN          : 'median'      ;
STD             : 'std'         ;   SUM             : 'sum'         ;

// VALUE TYPE KEYWORDS

LONG            : 'long'        ;   DOUBLE          : 'double'      ;
STRING          : 'string'      ;   BOOLEAN         : 'boolean'     ;
DATETIME        : 'datetime'    ;

// LITERAL VALUE KEYWORDS
BOOLEAN_        : TRUE | FALSE  ; // order of lexer declaration matters
TRUE            : 'true'        ;
FALSE           : 'false'       ;
STRING_         : '"'  (~["\\] | ESCAPE_SEQ_ )* '"'
                | '\'' (~['\\] | ESCAPE_SEQ_ )* '\''    ;
LONG_           : [0-9]+                                ;
DOUBLE_         : [0-9]+ '.' [0-9]+                     ;
DATE_           : DATE_FRAGMENT_                        ;
DATETIME_       : DATE_FRAGMENT_ 'T' TIME_              ;


Any keyword that appears in the ANTLR grammar definition above as a literal string, and that isn’t in the “unreserved” list, can be considered reserved.

Sorry I don’t have a simpler reference for you, but I hope that helps!

-Skip