0
此建立交叉引用的是我想要什么,我试图解析XTEXT一个泛型类型
type Number(); // define a type called "Number" with no member variables
type Point(Number x, Number y); // define a type called Point with member variables
// and something with generic types
type Pair[T, V](T first, V second);
// and even something cyclic:
type LinkedList[T](T payload, LinkedList[T] rest);
这是我的XTEXT语法,允许其:
TypeDecl returns SSType:
'type' name=TypeName
('[' typeParams += TypeName (',' typeParams += TypeName)* ']')?
'(' (args += Arg (',' args += Arg)*)? ')' ';'
;
TypeName returns SSTypeName:
name=ID
;
Type:
tn = [SSTypeName] ('[' typeParams += Type (',' typeParams += Type)* ']')?
;
Arg:
type = Type argName = ID
;
其中一期工程,但在接受的方面过于自由。如果有东西被声明为一个通用的(例如上面例子中的LinkedList),它应该只能用作通用的(例如LinkedList[Number]
而不是LinkedList
),理想情况下类型参数的arity将被强制执行。
当然,如果某些东西被声明为不是泛型类型(例如Number),那么给它的类型参数应该是无效的。东西
例如,它会错误地接受:
type Wrong1(Number[Blah] a); // number doesn't have type arguments
type Wrong2(Pair a); // Pair has type arguments
type Wrong3(Pair[Number, Number, Number] a); // wrong arity
任何建议,意见,就如何做到这一点正确的代码或提示将不胜感激。
从代码完成的角度来看呢?当某人键入一个泛型类型时,我希望编辑器知道他们必须输入类型参数。就像它不应该建议“Pair”一样,它应该建议“Pair [T,V]” – Heptic
您必须为此目的自定义内容帮助(例如,在应用提议之后,为T,V包括占位符提供有意义的值) 。 –