File Annotation
Not logged in
8de5b49cdf 2010-11-09        kinaba: /**
4198578702 2010-11-07        kinaba:  * Authors: k.inaba
4198578702 2010-11-07        kinaba:  * License: NYSL 0.9982 http://www.kmonos.net/nysl/
4198578702 2010-11-07        kinaba:  *
4198578702 2010-11-07        kinaba:  * Syntax tree for Polemy programming language.
423f308350 2010-11-07        kinaba:  */
4198578702 2010-11-07        kinaba: module polemy.ast;
4198578702 2010-11-07        kinaba: import polemy._common;
3464a035ec 2010-11-20        kinaba: import polemy.failure;
3995a5eb6a 2010-11-21        kinaba: import polemy.layer;
423f308350 2010-11-07        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
b985f3bf91 2010-11-08        kinaba: abstract class AST
423f308350 2010-11-07        kinaba: {
2bdfb8a182 2010-11-21        kinaba: 	LexPosition pos;
423f308350 2010-11-07        kinaba: 	mixin SimpleConstructor;
1c01f44f52 2010-11-13        kinaba: 	mixin SimplePatternMatch;
1c01f44f52 2010-11-13        kinaba: }
1c01f44f52 2010-11-13        kinaba: 
1c01f44f52 2010-11-13        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Int : AST
3995a5eb6a 2010-11-21        kinaba: {
3995a5eb6a 2010-11-21        kinaba: 	BigInt data;
3995a5eb6a 2010-11-21        kinaba: 	mixin SimpleClass;
3995a5eb6a 2010-11-21        kinaba: 	this(LexPosition pos, int n) {super(pos); data = n;}
3995a5eb6a 2010-11-21        kinaba: 	this(LexPosition pos, long n) {super(pos); data = n;}
3995a5eb6a 2010-11-21        kinaba: 	this(LexPosition pos, BigInt n) {super(pos); data = n;}
3995a5eb6a 2010-11-21        kinaba: 	this(LexPosition pos, string n) {super(pos); data = BigInt(n);}
3995a5eb6a 2010-11-21        kinaba: }
3995a5eb6a 2010-11-21        kinaba: 
3995a5eb6a 2010-11-21        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Str : AST
423f308350 2010-11-07        kinaba: {
423f308350 2010-11-07        kinaba: 	string data;
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
80ff567c75 2010-11-08        kinaba: }
80ff567c75 2010-11-08        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Var : AST
80ff567c75 2010-11-08        kinaba: {
3995a5eb6a 2010-11-21        kinaba: 	string name;
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
80ff567c75 2010-11-08        kinaba: }
80ff567c75 2010-11-08        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Lay : AST
80ff567c75 2010-11-08        kinaba: {
3995a5eb6a 2010-11-21        kinaba: 	Layer layer;
3995a5eb6a 2010-11-21        kinaba: 	AST   expr;
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
80ff567c75 2010-11-08        kinaba: }
80ff567c75 2010-11-08        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Let : AST
80ff567c75 2010-11-08        kinaba: {
3995a5eb6a 2010-11-21        kinaba: 	string name;
3995a5eb6a 2010-11-21        kinaba: 	Layer  layer;
b985f3bf91 2010-11-08        kinaba: 	AST    init;
b985f3bf91 2010-11-08        kinaba: 	AST    expr;
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
3f5dc76a75 2010-11-07        kinaba: }
3f5dc76a75 2010-11-07        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class App : AST
3f5dc76a75 2010-11-07        kinaba: {
b985f3bf91 2010-11-08        kinaba: 	AST   fun;
b985f3bf91 2010-11-08        kinaba: 	AST[] args;
3995a5eb6a 2010-11-21        kinaba: 	this(LexPosition pos, AST fun, AST[] args...)
80ff567c75 2010-11-08        kinaba: 		{ super(pos); this.fun=fun; this.args=args.dup; }
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
423f308350 2010-11-07        kinaba: }
423f308350 2010-11-07        kinaba: 
38fcc662be 2010-11-10        kinaba: ///
8e6fa743ee 2010-11-11        kinaba: class Parameter
8e6fa743ee 2010-11-11        kinaba: {
3995a5eb6a 2010-11-21        kinaba: 	string  name;
3995a5eb6a 2010-11-21        kinaba: 	Layer[] layers;
8e6fa743ee 2010-11-11        kinaba: 	mixin SimpleClass;
8e6fa743ee 2010-11-11        kinaba: }
8e6fa743ee 2010-11-11        kinaba: 
8e6fa743ee 2010-11-11        kinaba: ///
6ac127ddd0 2010-11-23        kinaba: class Fun : AST
423f308350 2010-11-07        kinaba: {
8e6fa743ee 2010-11-11        kinaba: 	Parameter[] params;
8e6fa743ee 2010-11-11        kinaba: 	AST         funbody;
80ff567c75 2010-11-08        kinaba: 	mixin SimpleClass;
423f308350 2010-11-07        kinaba: }
423f308350 2010-11-07        kinaba: 
80ff567c75 2010-11-08        kinaba: /// Handy Generator for AST nodes. To use this, mixin EasyAst;
80ff567c75 2010-11-08        kinaba: 
80ff567c75 2010-11-08        kinaba: /*mixin*/
b985f3bf91 2010-11-08        kinaba: template EasyAST()
423f308350 2010-11-07        kinaba: {
38fcc662be 2010-11-10        kinaba: 	///
80ff567c75 2010-11-08        kinaba: 	template genEast(T)
80ff567c75 2010-11-08        kinaba: 		{ T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } }
3f5dc76a75 2010-11-07        kinaba: 
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!Str strl; ///
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!Int intl; ///
8e6fa743ee 2010-11-11        kinaba: 	auto fun(string[] xs, AST ps) {
6ac127ddd0 2010-11-23        kinaba: 		return genEast!Fun(array(map!((string x){return new Parameter(x,[]);})(xs)),ps); }
6ac127ddd0 2010-11-23        kinaba: 	auto funp(Parameter[] xs, AST ps) { return genEast!Fun(xs,ps); } ///
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!Var var; ///
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!Lay lay; ///
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!Let let; ///
6ac127ddd0 2010-11-23        kinaba: 	alias genEast!App call; ///
a7b5d1d95a 2010-11-12        kinaba: 	auto param(string name, string[] lay...) { return new Parameter(name, lay); } ///
423f308350 2010-11-07        kinaba: }