typedb / typeql

TypeQL: the power of programming, in your database
https://typedb.com
Mozilla Public License 2.0
220 stars 46 forks source link

Misleading syntax errors generically using "expecting {'match', 'define', 'undefine', 'insert', 'compute'}" #262

Open jmsfltchr opened 5 years ago

jmsfltchr commented 5 years ago

Description

In many cases, TypeQL returns syntax errors that correctly identify the location of the syntax error, but make a generic and incorrect suggestion for how to fix it.

Environment

TypeDB version (and platform): Core 1.4 upwards

Reproducible Examples

  1. Correct query: insert $e isa d-entity, has d-key 1;, missing a comma

    insert $e isa d-entity has d-key 1;
    Error: syntax error at line 1: 
    insert $e isa d-entity has d-key 1;
                       ^
    mismatched input 'has' expecting {'match', 'define', 'undefine', 'insert', 'compute'}
    All uncommitted data is cleared
  2. Correct query: define my-bool sub attribute, datatype boolean;

    define my-bool sub attribute, datatype bool;
    Error: syntax error at line 1: 
    define my-bool sub attribute, datatype bool;
                                       ^
    mismatched input 'bool' expecting {'match', 'define', 'undefine', 'insert', 'compute'}
    All uncommitted data is cleared
  3. Correct query: insert $m isa my-bool; $m false;

    insert $m isa my-bool false; 
    Error: syntax error at line 1: 
    insert $m isa my-bool false; 
                      ^
    mismatched input 'false' expecting {'match', 'define', 'undefine', 'insert', 'compute'}
    All uncommitted data is cleared
  4. This example even gives an even stranger message. Correct query: define $m isa my-entity, has name; name sub attribute, datatype string;

    define my-entity, has name; name sub attribute, datatype string;
    Error: syntax error at line 1: 
    define my-entity, has name; name sub attribute, datatype string;
                ^
    no viable alternative at input ','
    syntax error at line 1: 
    define my-entity, has name; name sub attribute, datatype string;
                ^
    mismatched input ',' expecting {'match', 'define', 'undefine', 'insert', 'compute'}
    All uncommitted data is cleared
  5. Query : define rel sub relation, relates has; (uses a keyword as role)

    
    define
    rel sub relation, relates has;

[TQL03] TypeQL Error: There is a syntax error at line 2: rel sub relation, relates has; ^ mismatched input 'has' expecting {'get', 'thing', 'entity', 'attribute', 'relation', 'role', 'rule', 'offset', 'limit', 'sort', 'value', 'contains', 'group', 'count', 'max', 'min', 'mean', 'median', 'std', 'sum', VAR, LABEL}



## Expected Output

In each case, the suggestion `expecting {'match', 'define', 'undefine', 'insert', 'compute'}` is misleading. In all of these cases using these options is not valid. Ideally, the user should be prompted with all of the possible options that they could use instead at the point where their syntax is incorrect. At the least, they should be simply told the location of their syntax error, and not misguided. 
flyingsilverfin commented 1 year ago

Still worth fixing!