MetaSharp Syntax

There are two layers of syntax that you need to know, MetaTemplateSyntax and MetaSharpSyntax.

Meta Template Syntax

Template syntax is pretty simple. There are only two things you need to know:
  • Meta Statements
  • Binding Expressions

Meta Statements
They are noted by the presence of an '@' symbol at the start of the line.
@if(x == 0):
Meta statements can only be present in template code. It gets compiled as a literal statement inside of the template itself. The meta statement can be any statement legal in the MetaSharp language. All non-meta lines get compiled as part of the template output rather than in the logic of the template.

Binding Statements
These allow you to bind to the template model or to promote a variable declared in a Meta Statement into the generated code. They are noted by curly braces and can be located anywhere.
public class {Name} as Model:
Binding statements are made up of a Path that is a series of Identifiers seperated by periods and an optional Type for casting separated by the "as" keyword.

Combining the two together can result in something similar to this
@foreach(e in {model.Examples as enumerable}):
   private int _{e.Name};

MetaSharp Syntax
This is a bit more complex. MetaSharp is actually a full fledged .net language. One thing important to know about MetaSharp is that it is intended to compile into CodeDom objects. A single statement or expression can be turned into multiple CodeDom objects however, so more complex statements can be formed.

Note: This section is still under development and is likely to change.

Last edited Mar 18, 2009 at 6:51 AM by justinc, version 1


No comments yet.