Artifact 73653a45c2c5d30a4037672e8a4a231b50a2fd65
/**
* Authors: k.inaba
* License: NYSL 0.9982 http://www.kmonos.net/nysl/
*
* Syntax tree for Polemy programming language.
*/
module polemy.ast;
import polemy._common;
import polemy.failure;
import polemy.layer;
///
abstract class AST
{
LexPosition pos;
mixin SimpleConstructor;
mixin SimplePatternMatch;
}
///
class IntLiteral : AST
{
BigInt data;
mixin SimpleClass;
this(LexPosition pos, int n) {super(pos); data = n;}
this(LexPosition pos, long n) {super(pos); data = n;}
this(LexPosition pos, BigInt n) {super(pos); data = n;}
this(LexPosition pos, string n) {super(pos); data = BigInt(n);}
}
///
class StrLiteral : AST
{
string data;
mixin SimpleClass;
}
///
class VarExpression : AST
{
string name;
mixin SimpleClass;
}
///
class LayExpression : AST
{
Layer layer;
AST expr;
mixin SimpleClass;
}
///
class LetExpression : AST
{
string name;
Layer layer;
AST init;
AST expr;
mixin SimpleClass;
}
///
class FuncallExpression : AST
{
AST fun;
AST[] args;
this(LexPosition pos, AST fun, AST[] args...)
{ super(pos); this.fun=fun; this.args=args.dup; }
mixin SimpleClass;
}
///
class Parameter
{
string name;
Layer[] layers;
mixin SimpleClass;
}
///
class FunLiteral : AST
{
Parameter[] params;
AST funbody;
mixin SimpleClass;
}
/// Handy Generator for AST nodes. To use this, mixin EasyAst;
/*mixin*/
template EasyAST()
{
///
template genEast(T)
{ T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } }
alias genEast!StrLiteral strl; ///
alias genEast!IntLiteral intl; ///
auto fun(string[] xs, AST ps) {
return genEast!FunLiteral(array(map!((string x){return new Parameter(x,[]);})(xs)),ps); }
auto funp(Parameter[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } ///
alias genEast!VarExpression var; ///
alias genEast!LayExpression lay; ///
alias genEast!LetExpression let; ///
alias genEast!FuncallExpression call; ///
auto param(string name, string[] lay...) { return new Parameter(name, lay); } ///
}