我想创建一个可以与ID匹配的终端,但不完全匹配。 虽然ID是
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
我想要定义的终端是
terminal TYPE: (('a'..'z'|'A'..'Z')?('a'..'z'|'A'..'Z'|'_'|'0'..'9')*)?
因为TYPE可以匹配ID我收到RULE_ID错误,在这种情况下我该怎么办?
______EDIT__________
Domainmodel :
(elements+=XType)*;
terminal TYPE: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
MyID:
TYPE | ID
;
XType:
DataType | Entity;
DataType:
'datatype' name=MyID;
Entity:
'entity' name=MyID ('extends' superType=[Entity])? '{'
(features+=Feature)*
'}';
Feature:
(many?='many')? name=MyID ':' type=[XType];
模型(基于博客示例)
datatype String
entity Blog {
title: String
title2: String
many posts: Post
many Posts: Post
}
entity HasAuthor {
author: String
}
entity Post extends HasAuthor {
title: String
content: String
many comments: Comment
}
entity Comment extends HasAuthor {
content: String
}
答案 0 :(得分:1)
您可以引入数据类型规则
MyID: ID | TYPE;
MyID的值转换器,并在您使用ID的地方使用它
或者您忘记输入并检查验证器内的限制范围
Domainmodel :
(elements+=XType)*;
terminal TYPE: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
MyID:
TYPE | ID
;
XType:
DataType | Entity;
DataType:
'datatype' name=MyID;
Entity:
'entity' name=MyID ('extends' superType=[Entity|MyID])? '{'
(features+=Feature)*
'}';
Feature:
(many?='many')? name=MyID ':' type=[XType|MyID];