Exemplo n.º 1
0
        /// <summary>
        /// Traduit le jeton en "code" lisible.
        /// </summary>
        /// <returns></returns>
        public string ToDebugCode()
        {
            Func <string, string> getChildrenCode = delegate(string separator)
            {
                StringBuilder b = new StringBuilder();
                for (int i = 0; i < SubTokens.Count; i++)
                {
                    b.Append(SubTokens[i].ToDebugCode());
                    if (i != SubTokens.Count - 1)
                    {
                        b.Append(separator);
                    }
                }
                return(b.ToString());
            };

            switch (TkType)
            {
            case ExpressionTokenType.BracketList:
                return("l[" + getChildrenCode(",") + "]");

            case ExpressionTokenType.FunctionCall:
                return(FunctionCallIdentifier.ToDebugCode() + ".call(" + FunctionCallArgs.ToDebugCode() + ")");

            case ExpressionTokenType.GenericType:
                return(GenericTypeIdentifier.ToDebugCode() + ".gen<" + GenericTypeArgs.ToDebugCode() + ">");

            case ExpressionTokenType.ArrayType:
                return(ArrayTypeIdentifier.ToDebugCode() + ".arr[" + ArrayTypeArgs.ToDebugCode() + "]");

            case ExpressionTokenType.List:
                return("l:(" + getChildrenCode(" _ ") + ")");

            case ExpressionTokenType.ArgList:
                return("args:(" + getChildrenCode(",") + ")");

            case ExpressionTokenType.GenericParametersList:
                return("l<" + getChildrenCode(",") + ">");

            case ExpressionTokenType.Name:
                return(this.Content);

            case ExpressionTokenType.CodeBlock:
                return("{ " + getChildrenCode(",") + "}");

            case ExpressionTokenType.FunctionDeclaration:
                return("decl:" + SubTokens[0].ToDebugCode() + "{\n" + Tools.StringUtils.Indent(SubTokens[1].ToDebugCode(), 1) + "\n}");

            case ExpressionTokenType.EndOfInstruction:
                return("/" + this.Content);

            case ExpressionTokenType.InstructionList:
                return("\ninstruction_list:(\n" + getChildrenCode("?;\n") + ")\n");

            case ExpressionTokenType.ExpressionGroup:
                if (Operator.IsBinaryOperator)
                {
                    return("(" + Operands1.ToDebugCode() + Operator.ToDebugCode() + Operands2.ToDebugCode() + ")");
                }
                else
                {
                    return(Operator.ToDebugCode() + Operands1.ToDebugCode());
                }

            case ExpressionTokenType.NamedCodeBlock:
                return("block:" + SubTokens[0].ToDebugCode() + "{\n" + Tools.StringUtils.Indent(SubTokens[1].ToDebugCode(), 1) + "}\n");

            case ExpressionTokenType.NamedGenericCodeBlock:
                return("gen_block:" + NamedGenericCodeBlockIdentifier.ToDebugCode() +
                       "{\n" + Tools.StringUtils.Indent(NamedGenericCodeBlockInstructions.ToDebugCode(), 1) + "}\n");

            case ExpressionTokenType.NumberLiteral:
                return(this.Content);

            case ExpressionTokenType.Operator:
                return(this.Content);

            case ExpressionTokenType.Separator:
                return("/" + this.Content);

            case ExpressionTokenType.StringLiteral:
                return("\"" + this.Content + "\"");

            case ExpressionTokenType.Modifier:
                return(this.Content);

            case ExpressionTokenType.ConditionalStatement:
                return(this.Content);

            default:
                return("??");
            }
        }