NAME

Squirrel::Template::Expr - expression handling for Squirrel::Template


SYNOPSIS

  # code that uses it
  my $parser = Squirrel::Template::Expr::Parser->new;
  my $expr = $parser->parse($expr_text);
  my $tokens = Squirrel::Template::Expr::Tokenizer->new($expr_text);
  my $expr = $parser->parse_tokens($tokenizer);
  # and possibly process more tokens here
  my $eval = Squirrel::Template::Expr::Parser->new($templater);
  my $value = $eval->process($expr);
  my $value = $eval->process($expr, "LIST");
  my $arrayref = $eval->process(\@exprs);
  # Expressions
  <:= somevalue + 10 :>
  <:.if somevalue == 10 :>


DESCRIPTION

Squirrel::Template::Expr provides expression parsing and evaluation for newer style tags for the Squirrel::Template manpage.


EXPRESSION SYNTAX

Operators

Listed highest precedence first.

Literals

Numbers can be represented in several formats:

Strings can be either " or ' delimited.

Simple quote delimited strings allow no escaping, and may not contain single quotes. The contents are treated literally.

Double quoted strings allow escaping as follows:


Squirrel::Template::Expr::Parser

Squirrel::Template::Expr::Parser provides parsing for expressions.


Methods

new()

Create a new parser object.

parse($text)

Parse $text as an expression. Parsing must reach the end of the text or an exception will be thrown.

parse_tokens($tokenizer)

Process tokens from $tokenizer, a Squirrel::Template::Expr::Tokenizer object. The caller can call these method several times with the same $tokenizer to parse components of a statement, and should ensure the eof token is visible after the final component.


Squirrel::Template::Expr::Tokenizer

Split text into tokens. Token parsing is occasionally context sensitive.

Methods

new($text)

Create a new tokenizer for parsing $text.

get()
get($context)

Retrieve a token from the stream, consuming it. If a term is expected $context should be set to 'TERM'.

unget()

Push a token back into the stream.

peek()
peek($context)

Retrieve the next token from the stream without consuming it.

peektype()
peektype($context)

Retrieve the type of the next token from the stream without consuming it.


Squirrel::Template::Expr::Eval

Used to evaluate an expression returned by Squirrel::Template::Expr::parse().

Methods

new($templater)

Create a new evaluator. $templater should be a the Squirrel::Template manpage object.


SEE ALSO

the Squirrel::Template manpage


AUTHOR

Tony Cook <tony@develop-help.com>