Skip to content
jappy edited this page Oct 19, 2011 · 8 revisions

Previous - Grammar Summary | Table of Contents | Next - Document Revisions

Token

A token in Tea is the lowest form of data. It provides a unique piece of the compilation tree. There are two types of tokens: keywords and operators.

Scanner

The scanner is responsible for parsing the textual Tea code and building up a tree of tokens.

Parser

The parser is responsible for taking the scanned token tree and building up a graph of expressions and statements.

TypeChecker

The type checker is responsible for analyzing the parsed tree and determining types. Where in most dynamic languages, types have little influence, Tea requires every piece of data to have an associated type. It uses a visitor pattern.

Optimizer

Optimizers are custom visitors that analyze the type-checked tree to further optimize the parse tree. For example, if expressions that can be determined as always true or false can ignore that expression in the generated class file.

Code Generator

Code generators take the optimized and type-checked tree and generate underlying code. The JavaCodeGenerator for example generates a JVM-based classfile.

Compilers

Compilers are responsible for taking a source file and performing the scanning, parsing, and code generation. There are different compilers for different source locations (HTTP, File, etc).

Class File Format

The class file that gets generated has one of two forms depending on whether substitution blocks are used. For more information on substitution blocks, see the user manual.

Without Substitution Blocks

public class <NameOfTemplate> {
    public static void execute(<Type> Parameter1, <Type> Parameter2) {
        ...
    }
}

For example, consider the simple Tea example below

<% template hello(String name) 'Hello: ' name %>

The resulting class file is essentially equivalent to:

...

Static blocks are used to have higher performance. Because there are no field variables and hence no state, there is no reason to create an instance of the class. Instead, Tea can simply invoke the static method avoiding the overhead of unnecessary garbage.

With Substitution Blocks

When substitution blocks are used, state has to be maintained for the current scope and block. The format is similar, but the static execute block purely delegates to creating an instance of the class, setting the default scope, and then invoking the internal execute method. That internal block has a large switch statement based on the active scope to properly determine the block to execute.

For example, consider this example:

<% template hello(String name)

call layout('Title') {
    'Hello: ' name
}

%>

Results in:

...

Packages and Classes

Type

A type represents a given Java type including primitives and objects. It also contains a nullable state for objects. There are utility functions to convert to and from primitives, to and from nullables, as well as convert types to other types.

Generics

The generics represents the generics notion in JDK5 and allows creating, analyzing, and reading in generics data.

TypeDesc

A type desc is similar to Type, but it uses Strings to identify the types for classfile usage.

MethodDesc

A method desc describes a method for use in the classfile.

Previous - Grammar Summary | Table of Contents | Next - Document Revisions