Skip to content
jappy edited this page Oct 15, 2011 · 3 revisions

Previous - Embedding Tea | Table of Contents | Next - Tea Templates

The lexical structure of Tea is based on Java's. The chapter titled "Lexical Structure" in The Java Language Specification, defines most of Tea’s lexical structure.

Tea templates are defined in the unicode character set and the language is case-sensitive, just like Java. Tea uses Java's style and early processing of unicode escapes. Comments and white space are the same. Tea identifiers do not allow '$' characters, but are otherwise the same. String and number literals are very similar.

A template is composed of code and text regions. Code regions are delimited by "<%" and "%>" symbols. Any text not in the code region is output by the template as-is with only one minor conversion. All line break separator codes in text regions are converted to linefeeds '\n' (ASCII 10). No string escapes (including unicode escapes) are processed in text regions. Here is a template that mixes code and text regions:

<% template MyTemplate(PageInfo page) %>
<html><head><title><% page.title %></title></head>
<body>
<h1><% page.heading %></h1>
<table>
	<% foreach (item in page.list) { %>
		<tr><td><% item.name %></td><td><% item.desc %></td></tr>
	<% } %>
</table>
</body>
</html>

The code delimiter symbols are not actually Tea lexemes, but are instead processed in an initial preprocessing step that identifies text as being in a code region or not. The Tea scanner converts text regions into string literals. Put another way, text regions are simply multi-line string literals delimited by "%>" and "<%" symbols (see section 3.2.3 String Literals).

3.1 - Keywords

The following are the keywords in the Tea language. The reserved words "null", "true", "false", and "isa", discussed in the next sections, are not considered to be keywords.

Keyword:

and   
as   
break   
call   
continue   
define   
else   
foreach   
if   
import   
in   
not
or
reverse
template

3.2 - Literals

Literal ::=  NullLiteral |  
             BooleanLiteral |   
             StringLiteral |
             IntegerLiteral |  
             FloatingPointLiteral

3.2.1 - Null Literal

NullLiteral ::= null

3.2.2 - Boolean Literals

BooleanLiteral ::= true | false

3.2.3 - String Literals

StringLiteral ::=  " [StringCharacters] " |  
                   ' [StringCharacters] '

Tea string literals are for the most part, just like Java's. The first difference is that they may be delimited by apostrophes instead of quotes. Apostrophes are used by Java to delimit character literals, but Tea does not have character literals.

The other difference is that octal escapes are not supported in strings, although \0 (the null character) is.

3.2.4 Integer Literals

IntegerLiteral ::= DecimalIntegerLiteral |
                   HexIntegerLiteral

Tea integer literals are just like Java integer literals except Tea does not support octal integer literals. As a result, decimal integer literals may start with any number of '0' digits.

3.2.5 - Floating Point Literals

The only difference between Tea’s floating-point literals and Java’s is that the decimal point must always have a digit before and after it.

3.3 - Separators

(	)	{	}	[	]
;	,	.	=>

3.4 - Operators

=	#	##	..	...	isa
==	!=	<	>	<=	>=
+	-	*	/	%	&

3.4.1 - Ellipsis Operator

The ellipsis operator "..." is used when declaring that templates require a substitution parameter, and it is used where block substitutions should be placed. In Tea, the ellipsis means, "more statements may follow."

Previous - Embedding Tea | Table of Contents | Next - Tea Templates