<?xml version="1.0"?>
<syntax name="espresso.CoreEdit.TemplateSnippets">
    <zones>
		
		<include collection="template-snippets"/>
		
		<!-- Whitespace -->
		<zone name="ignored">
			<expression>[\s|\n|\r]+</expression>
		</zone>
		
    </zones>
	
	<library>
		
		<collection name="template-snippets">
			
			<!-- ${foo} -->
			<zone name="placeholder">
				<expression>\${([a-zA-Z0-9_.-]+)}</expression>
				<capture number="1" name="identifier"/>
			</zone>
			
			<!-- ${foo:bar} -->
			<zone name="placeholder.with-default">
				<starts-with>
					<expression>\${([a-zA-Z0-9_.-]+):</expression>
					<capture number="1" name="identifier"/>
				</starts-with>
				<ends-with>
					<expression>}</expression>
				</ends-with>
				<subzones name="default-container">
					<include collection="template-snippets"/>
				</subzones>
			</zone>
			
			<!-- ${foo/search/replace/} -->
			<zone name="placeholder.with-transformation">
				<starts-with>
					<expression>\${([a-zA-Z0-9_.-]+)/</expression>
					<capture number="1" name="identifier"/>
				</starts-with>
				<ends-with>
					<expression>/([a-z])?}</expression>
					<capture number="1" name="transformation.options"/>
				</ends-with>
				<subzones>
					<zone name="transformation.search">
						<starts-with>
							<expression>(?&lt;=/)</expression>
						</starts-with>
						<ends-with>
							<expression>(?=/)</expression>
						</ends-with>
						<subzones name="expression" />
					</zone>
					<zone name="transformation.replace">
						<starts-with>
							<expression>/</expression>
						</starts-with>
						<ends-with>
							<expression>(?=/)</expression>
						</ends-with>
						<subzones name="expression" />
					</zone>
				</subzones>
			</zone>
			
			<!-- ${foo attr="val" :bar} -->
			<zone name="placeholder.with-default">
				<starts-with>
					<expression>\${([a-zA-Z0-9_.-]+)</expression>
					<capture number="1" name="identifier"/>
				</starts-with>
				<ends-with>
					<expression>}</expression>
				</ends-with>
				<subzones>
					<zone name="attribute">
						<starts-with>
							<expression> ([a-zA-Z0-9_.-]+)=\"</expression>
							<capture number="1" name="name"/>
						</starts-with>
						<subzones name="value">
							<zone name="escape">
								<expression>\\(.)</expression>
								<capture number="1" name="escaped-string"/>
							</zone>
						</subzones>
						<ends-with>
							<expression>\"</expression>
						</ends-with>
					</zone>
					
					<zone name="default-container">
						<starts-with>
							<expression>(?&lt;=:)</expression>
						</starts-with>
						<ends-with>
							<expression>(?=})</expression>
						</ends-with>
						<subzones>
							<include collection="template-snippets"/>
						</subzones>
					</zone>
				</subzones>
			</zone>
			
			<!-- `literal ${stuff} here` -->
			<zone name="escape">
				<starts-with>
					<expression>`</expression>
				</starts-with>
				<subzones name="escaped-string">
					<zone name="escape">
						<expression>\\(`)</expression>
						<capture number="1" name="escaped-string"/>
					</zone>
				</subzones>
				<ends-with>
					<expression>`</expression>
				</ends-with>
			</zone>
			
			<zone name="escape">
				<expression>\\(.)</expression>
				<capture number="1" name="escaped-string"/>
			</zone>
			
		</collection>
		
	</library>

</syntax>
