Ray Wu
Ray Wu

Reputation: 1033

xtext custom validator error marking

I have a table

CREATE TABLE demo {
   a int,
   b int, 
   PRIMARY KEY (a, b, c)
};

Each row is a

Columns
  : k=ID v=ComparatorType (is_pk?=K_PRIMARY K_KEY)?
  | is_pk?=K_PRIMARY K_KEY '(' cs+=ID (',' cs+=ID )* ')'
;

I invoke my error function like this

error('PRIMARY KEYS id need to declare in advance', 
  MyPackage.Literals.COLUMNS__CS,
  PRIMARY_KEYS_DONT_EXIST)  

It could find the grammar error but xtext will mark error at first element of PRIMARY KEY row, which is a in my example. Is there any way to mark the error at c or whole (a, b, c) ?

Upvotes: 0

Views: 933

Answers (1)

Sebastian Zarnekow
Sebastian Zarnekow

Reputation: 6729

You can pass the index which should be marked as an additional argument to the error function. If you want to mark not only the c, you can of course create more than one error for each index.

Upvotes: 1

Related Questions