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* '}')?
	('Filters' '{' filters+=Filter* '}')?
	('Items' '{' configs+=PersistenceConfiguration* '}')?
	('Aliases' '{' aliases+=AliasConfiguration* '}')?
;

Strategy:
	CronStrategy | name=ID
;

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

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

FilterDetails:
	ThresholdFilter | TimeFilter | EqualsFilter | NotEqualsFilter | IncludeFilter | NotIncludeFilter
;

ThresholdFilter:
	'>' (relative?='%')? value=DECIMAL unit=(UNIT|STRING)?
;

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

EqualsFilter:
	'=' values+=STRING (',' values+=STRING)*
;

NotEqualsFilter:
	'!' values+=STRING (',' values+=STRING)*
;

IncludeFilter:
	'[]' lower=DECIMAL upper=DECIMAL unit=(UNIT|STRING)?
;

NotIncludeFilter:
	'][' lower=DECIMAL upper=DECIMAL unit=(UNIT|STRING)?
;


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

AllConfig:
	{AllConfig}
	'*'
;

ItemConfig:
	item=ID
;

GroupConfig:
	group=ID '*'
;

ItemExcludeConfig:
	'!' itemExclude=ID
;

GroupExcludeConfig:
	'!' groupExclude=ID '*'
;

AliasConfiguration:
	item=ID '->' alias=(ID|STRING)
;

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

UNIT:
	(('^' INT)|'²'|'³'|'/'|'*'|'·'|'°'|'µ'|'%'|'‰'|'Ω'|'Å'|'('|')'|ID)+
;
