grammar org.openhab.core.model.Items

// disabled due to conflicts between the custom ID rule and the common INT rule
// with org.eclipse.xtext.common.Terminals

hidden(WS, ML_COMMENT, SL_COMMENT)

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

generate items "https://openhab.org/model/Items"

ItemModel:
	{ItemModel} (items+=ModelItem)*
;

ModelItem:
	type=ModelItemType ('(' args+=(ID|STRING) (',' args+=(ID|STRING))* ')')?
	name=ID
	(label=STRING)?
	('<' icon=Icon '>')?
	('(' groups+=ID (',' groups+=ID)* ')')?
	('[' tags+=(ID|STRING) (',' tags+=(ID|STRING))* ']')?
	('{' bindings+=ModelBinding (',' bindings+=ModelBinding)* '}')?
;

// Supports item types with up to 4 colon-separated segments, e.g., Group:Number:Dimension:MAX
ModelItemType:
   ID (':' ID (':' ID (':' ID )?)?)?
;

ModelBinding:
    type=ID '=' configuration=STRING
    ('['
        properties+=ModelProperty? (',' properties+=ModelProperty)*
    ']')?
;

ModelProperty:
    key=ID '=' value+=ValueType (',' value+=ValueType)*
;

ValueType returns ecore::EJavaObject:
    STRING | NUMBER | BOOLEAN
;

BOOLEAN returns ecore::EBoolean:
    'true' | 'false'
;

NUMBER returns ecore::EBigDecimal:
    ('-')? ID ('.' ID )?
;

Icon:
	(ID ':' (ID ':')?)? ID
;

terminal ID: '^'?('a'..'z'|'A'..'Z'|'_'|'0'..'9') ('a'..'z'|'A'..'Z'|'_'|'-'|'0'..'9')*;

terminal STRING:
			'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
			"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

terminal ML_COMMENT: '/*' -> '*/';

terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;

terminal WS: (' '|'\t'|'\r'|'\n')+;

terminal ANY_OTHER: .;
