grammar org.openhab.core.model.persistence.Persistence with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate persistence "https://openhab.org/model/Persistence"

PersistenceModel:
	{PersistenceModel}
	'Strategies' '{' strategies+=Strategy* 
		('default' '=' defaults+=[Strategy|ID] (',' defaults+=[Strategy|ID])*)?
	'}'
	('Filters' '{' filters+=Filter* '}')?
	('Items' '{' configs+=PersistenceConfiguration* '}')?
;

Strategy:
	CronStrategy | name=ID
;

CronStrategy returns Strategy:
	{CronStrategy}
	 name=ID ':' cronExpression=STRING
;

Filter:
	name=ID ':' definition=FilterDetails
;

FilterDetails:
	ThresholdFilter | TimeFilter
;

ThresholdFilter:
	'>' value=DECIMAL percent?='%'
;

TimeFilter:
	value=INT unit=('s' | 'm' | 'h' | 'd') 
;

PersistenceConfiguration:
	items+=(AllConfig | ItemConfig | GroupConfig) (',' items+=(AllConfig | ItemConfig | GroupConfig))* ('->' alias=STRING)? 
	((':' ('strategy' '=' strategies+=[Strategy|ID] (',' strategies+=[Strategy|ID])*)? 
		 ('filter' '=' filters+=[Filter|ID] (',' filters+=[Filter|ID])*)?) 
		| ';')
;

AllConfig:
	{AllConfig}
	'*'
;

ItemConfig:
	item=ID
;

GroupConfig:
	group=ID '*'
;

DECIMAL returns ecore::EBigDecimal :
	INT ('.' INT)?
;
