在我目前的项目中,我试图在编辑器中提供代码折叠支持,从xtext语法生成。感谢xtext,当我有两行时,它提供了非常好的代码折叠支持。但是,当它只包含一行时,我无法折叠代码(为清楚起见,我附加了为此规范编写的图像文件和语法)。当一个块有三行时折叠代码是默认行为吗?如何更改默认行为?
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
(vocSpec=VocSpec);
VocSpec:
'structs:' (structs+=Struct)+
'resources:'
'sensors:'
'periodicSensors:' (periodicSensors+=PeriodicSensors)*
'eventDrivenSensors:' (eventSensors+=EventSensors)*
'requestBasedSensors:' (requestSensors+=RequestSensors)*
'tags:' (tags+=Tags)*
'actuators:' (actuators+=Actuator)*
'storages:' (storageService+=StorageService)*
;
Struct:
name=StructEntityName (fields+=Field)+;
Field:
name=ID ':' type+=Type ';'
;
/* Periodic Sensor Definition */
PeriodicSensors:
sensorName=EntityName
(generateInfo+=Generate)+
sampelingDef= SampelingDef
;
SampelingDef:
'sample' 'period' INT 'for' INT ';'
;
/* Event Driven Sensor Definition */
EventSensors:
sensorName=EntityName
(generateInfo+=Generate)+
onConditionDef= OnConditionDef ;
OnConditionDef:
'onCondition' (eventConditions+=EventConditions) ';'
;
/* Request Based Sensor Definition */
RequestSensors:
sensorName=EntityName
(dataAccess+=DataAccessForRequestSensors)+
;
/* Tag Definition */
Tags:
sensorName=EntityName
(generateInfo+=Generate)+
;
EventConditions:
name=ID ('>' | '<' | '=')* (intValue=INT) (nameUnit=Unit) (',' eventConditions+=EventConditions)?
OPERATOR:
opt='>' | opt='<' | opt='=';
DeviceEntityName:
(name=ID);
StructEntityName:
(name=ID);
EntityName:
(name=ID);
//EntityName: (name = ID | name = 'EndUserApp' | name = 'DashBoard') ;
Generate:
'generate' sourceName=SourceName ':' type=Type ';';
SourceName:
name=ID;
/* Actuator Definition */
Actuator:
actuatorName=EntityName
(actions += Action)*
;
Action:
'action' actionName=ActionName '(' (parameters+=Parameters)* ')' ';';
ActionName:
name=ID;
Parameters:
parameterName=ParameterName ':' type=Type;
ParameterName:
name=ID;
/* Storage Service Definition */
StorageService:
storageServiceName=EntityName
((dataAccesses+=DataAccess))*;
DataAccessForRequestSensors:
'generate' sourceName=SourceName ':' dataAccessType=Type
'accessed-by' dataItem=ID ':' type=Type ';'
;
DataAccess:
'generate' sourceName=SourceName ':' dataAccessType=Type
'accessed-by' dataItem=ID ':' type=Type ';'
((actions+=Action))*;
/* Type Definition */
Type:
(primitiveDataType=PrimitiveDataType);
Unit:
name='PPM' | name='miliseconds' | name='seconds' | name='minutes' | name='ppm';
OperationName:
name='AVG_BY_SAMPLE';
PrimitiveDataType:
INTEGER='Integer' | BOOLEAN='boolean' | STRING='String' | LONG='long' | DOUBLE='double' | structDef=[StructEntityName];