How can I parse a group of items that can be in any order, but only allow 1 of each rule?
With the sql grammar in code for create table there is the 'null/not null' rule. A new rule for something such as 'character set utf8' would be easy to add if it always comes either before or after the 'null/not null' rule. How to handle when it can be in
either place though?
I tried modifying the sql grammar code slightly like this:
createTableStmt.Rule = CREATE + TABLE + Id + "(" + fieldDefList + ")" + constraintListOpt;
fieldDefList.Rule = MakePlusRule(fieldDefList, comma, fieldDef);
fieldDef.Rule = Id + typeName + typeParamsOpt + typeOptList;
typeParamsOpt.Rule = "(" + number + ")" | "(" + number + comma + number + ")" | Empty;
typeOptList.Rule = MakeStarRule(typeOptList, typeOpt);
typeOpt.Rule = nullSpecOpt | charsetOpt;
nullSpecOpt.Rule = NULL | NOT + NULL;
charsetOpt.Rule = CHARACTER + SET + charset_type;
But then something like this parses successfully allowing two nullSpecOpt rules:
create table test (
charCol VARCHAR(10) NOT NULL CHARACTER SET utf8 NOT NULL
What is the right way to only allow 1 of each rule in a list and in any order?