/// This module was generated by the StaticLang tool from
/// Goldie v0.4: http://www.semitwist.com/goldie/

// Goldie: GOLD Engine for D
// Written in the D programming language.

module samples.calculatorStatic.calc.token;

version = GoldieStaticLang;

import std.string;
import std.traits;

import semitwist.treeout;
import semitwist.util.all;

import goldie.base;
import goldie.exception;
import goldie.lang;



version(GoldieStaticLang)
{
	import goldie.token;
	import samples.calculatorStatic.calc.lang;

	public template Token_calc()
	{
		alias Base_Token_calc Token_calc;
	}

	public template Token_calc(string staticName=null)
	{
		static if(staticName == "(")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == ")")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "*")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "+")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "-")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "/")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "<Add Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName) Token_calc;
		else static if(staticName == "<Mult Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName) Token_calc;
		else static if(staticName == "<Negate Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName) Token_calc;
		else static if(staticName == "<Value>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName) Token_calc;
		else static if(staticName == "EOF")
			alias _Token_calc!(SymbolType.EOF, staticName) Token_calc;
		else static if(staticName == "Error")
			alias _Token_calc!(SymbolType.Error, staticName) Token_calc;
		else static if(staticName == "Number")
			alias _Token_calc!(SymbolType.Terminal, staticName) Token_calc;
		else static if(staticName == "Whitespace")
			alias _Token_calc!(SymbolType.Whitespace, staticName) Token_calc;
		else
			static assert(false,
				"Invalid token: Token_calc!('"~staticName~"')");
	}

	public template Token_calc(SymbolType staticSymbolType, string staticName)
	{
		static if(staticSymbolType == SymbolType.EOF && staticName == "EOF")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Error && staticName == "Error")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Whitespace && staticName == "Whitespace")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "-")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "(")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == ")")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "*")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "/")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "+")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.Terminal && staticName == "Number")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.NonTerminal && staticName == "<Add Exp>")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.NonTerminal && staticName == "<Mult Exp>")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.NonTerminal && staticName == "<Negate Exp>")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else static if(staticSymbolType == SymbolType.NonTerminal && staticName == "<Value>")
			alias _Token_calc!(staticSymbolType, staticName) Token_calc;
		else
			static assert(false,
				"Invalid token: Token_calc!(SymbolType."~
				goldSymbolTypeToString(staticSymbolType)~", '"~staticName~"')");
	}

	private template Token_calc(string staticName, int staticRuleId)
	{
		static if(staticRuleId == 0 && staticName == "<Add Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 1 && staticName == "<Add Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 2 && staticName == "<Add Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 3 && staticName == "<Mult Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 4 && staticName == "<Mult Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 5 && staticName == "<Mult Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 6 && staticName == "<Negate Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 7 && staticName == "<Negate Exp>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 8 && staticName == "<Value>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else static if(staticRuleId == 9 && staticName == "<Value>")
			alias _Token_calc!(SymbolType.NonTerminal, staticName, staticRuleId) Token_calc;
		else
			static assert(false,
				"Invalid token: Token_calc!('"~
				staticName~"', "~ctfe_i2a(staticRuleId)~")");
	}

	public template isCorrectToken_calc(string token, int type, string name)
	{
		static if(token == name)
			static if(Language_calc.staticIsSymbolNameAmbiguous(token))
				static assert(false, "Token name '"~staticName~
					"' is ambiguous, please specify SymbolType"~
					" (ex: Token_calc!(SymbolType.Terminal, \"+\"))\n"~
					"Possible types: ["~Language_calc.symbolTypesByName(name).goldSymbolTypesToString()~"]");
			else
				enum bool isCorrectToken_calc = true;
		else
			enum bool isCorrectToken_calc = false;
	}
	
	public template isCorrectToken_calc(token, int type, string name)
	{
		static if(is( token:_Token_calc!(cast(SymbolType)type, name) ))
			enum bool isCorrectToken_calc = true;
		else
			enum bool isCorrectToken_calc = false;
	}
	
	public template Token_calc(string staticName, subTokenTypes...)
		if(subTokenTypes.length != 1 || !isIntegral!(typeof(subTokenTypes[0])))
	{
		alias _Token_calc!(SymbolType.NonTerminal, staticName, ruleIdOf_calc!(staticName, subTokenTypes)) Token_calc;
	}
	
	//TODO? Move this to goldie.lang
	public template ruleIdOf_calc(string staticName, subTokenTypes...)
	{
		static if(
			staticName == "<Add Exp>" && subTokenTypes.length == 3 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Add Exp>") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.Terminal, "+") &&
			isCorrectToken_calc!(subTokenTypes[2], SymbolType.NonTerminal, "<Mult Exp>")
		)
			enum int ruleIdOf_calc = 0;
		else static if(
			staticName == "<Add Exp>" && subTokenTypes.length == 3 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Add Exp>") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.Terminal, "-") &&
			isCorrectToken_calc!(subTokenTypes[2], SymbolType.NonTerminal, "<Mult Exp>")
		)
			enum int ruleIdOf_calc = 1;
		else static if(
			staticName == "<Add Exp>" && subTokenTypes.length == 1 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Mult Exp>")
		)
			enum int ruleIdOf_calc = 2;
		else static if(
			staticName == "<Mult Exp>" && subTokenTypes.length == 3 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Mult Exp>") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.Terminal, "*") &&
			isCorrectToken_calc!(subTokenTypes[2], SymbolType.NonTerminal, "<Negate Exp>")
		)
			enum int ruleIdOf_calc = 3;
		else static if(
			staticName == "<Mult Exp>" && subTokenTypes.length == 3 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Mult Exp>") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.Terminal, "/") &&
			isCorrectToken_calc!(subTokenTypes[2], SymbolType.NonTerminal, "<Negate Exp>")
		)
			enum int ruleIdOf_calc = 4;
		else static if(
			staticName == "<Mult Exp>" && subTokenTypes.length == 1 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Negate Exp>")
		)
			enum int ruleIdOf_calc = 5;
		else static if(
			staticName == "<Negate Exp>" && subTokenTypes.length == 2 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.Terminal, "-") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.NonTerminal, "<Value>")
		)
			enum int ruleIdOf_calc = 6;
		else static if(
			staticName == "<Negate Exp>" && subTokenTypes.length == 1 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.NonTerminal, "<Value>")
		)
			enum int ruleIdOf_calc = 7;
		else static if(
			staticName == "<Value>" && subTokenTypes.length == 1 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.Terminal, "Number")
		)
			enum int ruleIdOf_calc = 8;
		else static if(
			staticName == "<Value>" && subTokenTypes.length == 3 &&
			isCorrectToken_calc!(subTokenTypes[0], SymbolType.Terminal, "(") &&
			isCorrectToken_calc!(subTokenTypes[1], SymbolType.NonTerminal, "<Add Exp>") &&
			isCorrectToken_calc!(subTokenTypes[2], SymbolType.Terminal, ")")
		)
			enum int ruleIdOf_calc = 9;
		else
			static assert(false,
				"Invalid rule: ruleIdOf_calc!('"~staticName~"', ...)"); //TODO: expand that "..."
	}
	
	public template SubTokenType_calc(int ruleId, int index)
	{
		static if(ruleId == 0 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Add Exp>") SubTokenType_calc;
		else static if(ruleId == 0 && index == 1)
			alias Token_calc!(SymbolType.Terminal, "+") SubTokenType_calc;
		else static if(ruleId == 0 && index == 2)
			alias Token_calc!(SymbolType.NonTerminal, "<Mult Exp>") SubTokenType_calc;
		else static if(ruleId == 1 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Add Exp>") SubTokenType_calc;
		else static if(ruleId == 1 && index == 1)
			alias Token_calc!(SymbolType.Terminal, "-") SubTokenType_calc;
		else static if(ruleId == 1 && index == 2)
			alias Token_calc!(SymbolType.NonTerminal, "<Mult Exp>") SubTokenType_calc;
		else static if(ruleId == 2 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Mult Exp>") SubTokenType_calc;
		else static if(ruleId == 3 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Mult Exp>") SubTokenType_calc;
		else static if(ruleId == 3 && index == 1)
			alias Token_calc!(SymbolType.Terminal, "*") SubTokenType_calc;
		else static if(ruleId == 3 && index == 2)
			alias Token_calc!(SymbolType.NonTerminal, "<Negate Exp>") SubTokenType_calc;
		else static if(ruleId == 4 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Mult Exp>") SubTokenType_calc;
		else static if(ruleId == 4 && index == 1)
			alias Token_calc!(SymbolType.Terminal, "/") SubTokenType_calc;
		else static if(ruleId == 4 && index == 2)
			alias Token_calc!(SymbolType.NonTerminal, "<Negate Exp>") SubTokenType_calc;
		else static if(ruleId == 5 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Negate Exp>") SubTokenType_calc;
		else static if(ruleId == 6 && index == 0)
			alias Token_calc!(SymbolType.Terminal, "-") SubTokenType_calc;
		else static if(ruleId == 6 && index == 1)
			alias Token_calc!(SymbolType.NonTerminal, "<Value>") SubTokenType_calc;
		else static if(ruleId == 7 && index == 0)
			alias Token_calc!(SymbolType.NonTerminal, "<Value>") SubTokenType_calc;
		else static if(ruleId == 8 && index == 0)
			alias Token_calc!(SymbolType.Terminal, "Number") SubTokenType_calc;
		else static if(ruleId == 9 && index == 0)
			alias Token_calc!(SymbolType.Terminal, "(") SubTokenType_calc;
		else static if(ruleId == 9 && index == 1)
			alias Token_calc!(SymbolType.NonTerminal, "<Add Exp>") SubTokenType_calc;
		else static if(ruleId == 9 && index == 2)
			alias Token_calc!(SymbolType.Terminal, ")") SubTokenType_calc;
		else
			static assert(false,
				"Invalid subtoken: SubTokenType_calc!("~ctfe_i2a(ruleId)~", "~ctfe_i2a(index)~")");
	}
	
	private class _Token_calc(SymbolType staticSymbolType, string staticName, int staticRuleId) : _Token_calc!(staticSymbolType, staticName)
	{
		// StringOf is a workaround for DMD Bug #1748
		//TODO: expand that "..."
		static enum string StringOf = "Token_calc!("~fullSymbolTypeToString(staticSymbolType)~", "~staticName.stringof~", ...)";

		//TODO: This should take Token_{langaugeName}[], not Token[]
		public this(Token[] sub, Language lang)
		{
			super(sub, lang, staticRuleId);
		}

		public @property SubTokenType_calc!(staticRuleId, index) sub(int index)()
		{
			return cast(SubTokenType_calc!(staticRuleId, index))subX[index];
		}
	}

	private class Base_Token_calc : Token
	{
		static enum string StringOf = "Token_calc";

		public this(Symbol symbol, Language lang, string content,
					string file="{unknown}", int line=0,
					int srcIndexStart=0, int srcIndexEnd=0,
					CommentType commentMode=CommentType.None,
					string debugInfo="")
		{
			super(
				symbol, lang, content,
				file, line,
				srcIndexStart, srcIndexEnd,
				commentMode,
				debugInfo
			);
		}
		
		public this(Symbol symbol, Token[] sub, Language lang, int ruleId)
		{
			super(symbol, sub, lang, ruleId);
		}
	}
}

//TODO: Add way to get token's rule in string form (like what's shown in dumpcgt)
//TODO? Make wrong ctor private in Token_calc!{symbol}? Make all ctors private in Token_calc?
private class _Token_calc(SymbolType staticSymbolType, string staticName) : Base_Token_calc
{
	// StringOf is a workaround for DMD Bug #1748
	version(GoldieStaticLang)
		static enum string StringOf = "Token_calc!("~fullSymbolTypeToString(staticSymbolType)~", "~staticName.stringof~")";

	
	
	static if(staticSymbolType != SymbolType.NonTerminal) {

	public this(Language lang, string content,
	            string file="{unknown}", int line=0,
				int srcIndexStart=0, int srcIndexEnd=0,
				CommentType commentMode=CommentType.None,
				string debugInfo="")
	{
		
		
		version(GoldieStaticLang)
		{
			static if(staticSymbolType == SymbolType.EOF && staticName == "EOF")
				int staticId = 0;
			else static if(staticSymbolType == SymbolType.Error && staticName == "Error")
				int staticId = 1;
			else static if(staticSymbolType == SymbolType.Whitespace && staticName == "Whitespace")
				int staticId = 2;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "-")
				int staticId = 3;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "(")
				int staticId = 4;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == ")")
				int staticId = 5;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "*")
				int staticId = 6;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "/")
				int staticId = 7;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "+")
				int staticId = 8;
			else static if(staticSymbolType == SymbolType.Terminal && staticName == "Number")
				int staticId = 9;
			else
				static assert(false,
					"Invalid token: Token_calc!(SymbolType."~
					goldSymbolTypeToString(staticSymbolType)~", '"~staticName~"')");
			super(
				language_calc.symbolTable[staticId],
				lang, content,
				file, line,
				srcIndexStart, srcIndexEnd,
				commentMode,
				debugInfo
			);
		}
	}
	
	} else {
	
	public this(Token[] sub, Language lang, int ruleId)
	{
		

		version(GoldieStaticLang)
		{
			static if(staticName == "<Add Exp>")
				int staticId = 10;
			else static if(staticName == "<Mult Exp>")
				int staticId = 11;
			else static if(staticName == "<Negate Exp>")
				int staticId = 12;
			else static if(staticName == "<Value>")
				int staticId = 13;
			else
				static assert(false,
					"Invalid token: Token_calc!(SymbolType."~
					goldSymbolTypeToString(staticSymbolType)~", '"~staticName~"')");
			super(language_calc.symbolTable[staticId], sub, lang, ruleId);
		}
	}
	}
	
}
