Initial project's source code check-in.
This commit is contained in:
commit
b03b0b373f
4573 changed files with 981205 additions and 0 deletions
|
@ -0,0 +1,165 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class BinaryExpression : Expression
|
||||
{
|
||||
Expression lhs;
|
||||
Expression rhs;
|
||||
TokenType op;
|
||||
|
||||
public BinaryExpression(int line, int column, Expression lhs, TokenType op, Expression rhs)
|
||||
: base(line, column)
|
||||
{
|
||||
this.lhs = lhs;
|
||||
this.op = op;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
public TokenType Operator
|
||||
{
|
||||
get { return op; }
|
||||
}
|
||||
|
||||
Expression LeftExpression
|
||||
{
|
||||
get { return lhs; }
|
||||
set { lhs = value; }
|
||||
}
|
||||
|
||||
Expression RightExpression
|
||||
{
|
||||
get { return rhs; }
|
||||
set { rhs = value; }
|
||||
}
|
||||
|
||||
public override object Eval(TemplateContext context)
|
||||
{
|
||||
// evaluate both parts
|
||||
object lv = LeftExpression.Eval(context);
|
||||
object rv = RightExpression.Eval(context);
|
||||
|
||||
// equality/not-equality
|
||||
if (op == TokenType.Equal)
|
||||
{
|
||||
if (lv == null && rv == null)
|
||||
return true;
|
||||
else if (lv != null)
|
||||
return lv.Equals(rv);
|
||||
}
|
||||
else if (op == TokenType.NotEqual)
|
||||
{
|
||||
if (lv == null && rv == null)
|
||||
return false;
|
||||
else if (lv != null)
|
||||
return !lv.Equals(rv);
|
||||
}
|
||||
|
||||
// arithmetic operation
|
||||
else if (op == TokenType.Mult
|
||||
|| op == TokenType.Div
|
||||
|| op == TokenType.Mod
|
||||
|| op == TokenType.Plus
|
||||
|| op == TokenType.Minus
|
||||
|| op == TokenType.Less
|
||||
|| op == TokenType.LessOrEqual
|
||||
|| op == TokenType.Greater
|
||||
|| op == TokenType.GreaterOrEqual)
|
||||
{
|
||||
if(!((lv is Decimal || lv is Int32) && (rv is Decimal || rv is Int32)))
|
||||
throw new ParserException("Arithmetic and logical operations can be applied to operands or integer and decimal types only.",
|
||||
Line, Column);
|
||||
|
||||
|
||||
bool dec = lv is Decimal || rv is Decimal;
|
||||
object val = null;
|
||||
if(op == TokenType.Mult)
|
||||
val = dec ? (Decimal)lv * (Decimal)rv : (Int32)lv * (Int32)rv;
|
||||
else if (op == TokenType.Div)
|
||||
val = dec ? (Decimal)lv / (Decimal)rv : (Int32)lv / (Int32)rv;
|
||||
else if (op == TokenType.Mod)
|
||||
val = dec ? (Decimal)lv % (Decimal)rv : (Int32)lv % (Int32)rv;
|
||||
else if (op == TokenType.Plus)
|
||||
val = dec ? (Decimal)lv + (Decimal)rv : (Int32)lv + (Int32)rv;
|
||||
else if (op == TokenType.Minus)
|
||||
val = dec ? (Decimal)lv - (Decimal)rv : (Int32)lv - (Int32)rv;
|
||||
else if (op == TokenType.Less)
|
||||
val = dec ? (Decimal)lv < (Decimal)rv : (Int32)lv < (Int32)rv;
|
||||
else if (op == TokenType.LessOrEqual)
|
||||
val = dec ? (Decimal)lv <= (Decimal)rv : (Int32)lv <= (Int32)rv;
|
||||
else if (op == TokenType.Greater)
|
||||
val = dec ? (Decimal)lv > (Decimal)rv : (Int32)lv > (Int32)rv;
|
||||
else if (op == TokenType.GreaterOrEqual)
|
||||
val = dec ? (Decimal)lv >= (Decimal)rv : (Int32)lv >= (Int32)rv;
|
||||
|
||||
if (val is Boolean)
|
||||
{
|
||||
bool ret = Convert.ToBoolean(val);
|
||||
return ret;
|
||||
}
|
||||
else if (dec)
|
||||
{
|
||||
decimal ret = Convert.ToDecimal(val);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ret = Convert.ToInt32(val);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else if (op == TokenType.Or || op == TokenType.And)
|
||||
{
|
||||
if (!(lv is Boolean && rv is Boolean))
|
||||
throw new ParserException("Logical operation can be applied to operands of boolean type only", Line, Column);
|
||||
|
||||
if (op == TokenType.Or)
|
||||
return (Boolean)lv || (Boolean)rv;
|
||||
else if (op == TokenType.And)
|
||||
return (Boolean)lv && (Boolean)rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("(")
|
||||
.Append(LeftExpression.ToString()).Append(" ")
|
||||
.Append(Operator).Append(" ")
|
||||
.Append(RightExpression.ToString()).Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class CallTemplateStatement : Statement
|
||||
{
|
||||
public string templateName;
|
||||
public Dictionary<string, Expression> parameters = new Dictionary<string, Expression>();
|
||||
List<Statement> statements = new List<Statement>();
|
||||
|
||||
public CallTemplateStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public string TemplateName
|
||||
{
|
||||
get { return templateName; }
|
||||
set { templateName = value; }
|
||||
}
|
||||
|
||||
public Dictionary<string, Expression> Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public List<Statement> Statements
|
||||
{
|
||||
get { return statements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
// locate template
|
||||
if (!context.Templates.ContainsKey(templateName))
|
||||
throw new ParserException(String.Format("Custom template \"{0}\" is not defined", templateName), Line, Column);
|
||||
|
||||
TemplateStatement tmp = context.Templates[templateName];
|
||||
|
||||
// create template-specific context
|
||||
TemplateContext tmpContext = new TemplateContext();
|
||||
tmpContext.ParentContext = context;
|
||||
tmpContext.Templates = context.Templates;
|
||||
|
||||
// evaluate inner statements
|
||||
StringWriter innerWriter = new StringWriter();
|
||||
foreach (Statement stm in Statements)
|
||||
stm.Eval(context, innerWriter);
|
||||
tmpContext.Variables["innerText"] = innerWriter.ToString();
|
||||
|
||||
// set context variables
|
||||
foreach (string name in parameters.Keys)
|
||||
tmpContext.Variables[name] = parameters[name].Eval(context);
|
||||
|
||||
// evaluate template statements
|
||||
foreach (Statement stm in tmp.Statements)
|
||||
stm.Eval(tmpContext, writer);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{").Append(templateName);
|
||||
|
||||
foreach (string name in parameters.Keys)
|
||||
sb.Append(" ").Append(name).Append("=\"").Append(parameters[name].ToString()).Append("\"");
|
||||
|
||||
sb.Append(" /}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class ElseIfStatement : Statement
|
||||
{
|
||||
Expression condition;
|
||||
List<Statement> trueStatements = new List<Statement>();
|
||||
|
||||
public ElseIfStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public Expression Condition
|
||||
{
|
||||
get { return condition; }
|
||||
set { condition = value; }
|
||||
}
|
||||
|
||||
public List<Statement> TrueStatements
|
||||
{
|
||||
get { return trueStatements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
foreach (Statement stm in TrueStatements)
|
||||
stm.Eval(context, writer);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{elseif ")
|
||||
.Append(Condition.ToString()).Append("}");
|
||||
foreach (Statement stm in TrueStatements)
|
||||
{
|
||||
sb.Append(stm);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal abstract class Expression
|
||||
{
|
||||
int line;
|
||||
int column;
|
||||
|
||||
public Expression(int line, int column)
|
||||
{
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public int Line
|
||||
{
|
||||
get { return line; }
|
||||
}
|
||||
|
||||
public int Column
|
||||
{
|
||||
get { return column; }
|
||||
}
|
||||
|
||||
public abstract object Eval(TemplateContext context);
|
||||
}
|
||||
}
|
118
WebsitePanel/Sources/WebsitePanel.Templates/AST/ForStatement.cs
Normal file
118
WebsitePanel/Sources/WebsitePanel.Templates/AST/ForStatement.cs
Normal file
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class ForStatement : Statement
|
||||
{
|
||||
string indexIdentifier;
|
||||
Expression startIndex;
|
||||
Expression endIndex;
|
||||
List<Statement> statements = new List<Statement>();
|
||||
|
||||
public ForStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public string IndexIdentifier
|
||||
{
|
||||
get { return indexIdentifier; }
|
||||
set { indexIdentifier = value; }
|
||||
}
|
||||
|
||||
public Expression StartIndex
|
||||
{
|
||||
get { return startIndex; }
|
||||
set { startIndex = value; }
|
||||
}
|
||||
|
||||
public Expression EndIndex
|
||||
{
|
||||
get { return endIndex; }
|
||||
set { endIndex = value; }
|
||||
}
|
||||
|
||||
public List<Statement> Statements
|
||||
{
|
||||
get { return statements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
// evaluate indicies
|
||||
object objStartIdx = StartIndex.Eval(context);
|
||||
object objEndIdx = EndIndex.Eval(context);
|
||||
|
||||
// check indicies
|
||||
if (!(objStartIdx is Int32))
|
||||
throw new ParserException("Start index expression should evaluate to integer.", StartIndex.Line, StartIndex.Column);
|
||||
if (!(objEndIdx is Int32))
|
||||
throw new ParserException("End index expression should evaluate to integer.", StartIndex.Line, StartIndex.Column);
|
||||
|
||||
int startIdx = Convert.ToInt32(objStartIdx);
|
||||
int endIdx = Convert.ToInt32(objEndIdx);
|
||||
int step = startIdx < endIdx ? 1 : -1;
|
||||
endIdx += step;
|
||||
|
||||
int i = startIdx;
|
||||
do
|
||||
{
|
||||
context.Variables[IndexIdentifier] = i;
|
||||
|
||||
// evaluate statements
|
||||
foreach (Statement stm in Statements)
|
||||
stm.Eval(context, writer);
|
||||
|
||||
i += step;
|
||||
}
|
||||
while (i != endIdx);
|
||||
|
||||
// cleanup vars
|
||||
context.Variables.Remove(IndexIdentifier);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{for ")
|
||||
.Append(IndexIdentifier).Append(" = ")
|
||||
.Append(StartIndex).Append(" to ").Append(EndIndex).Append("}");
|
||||
foreach (Statement stm in Statements)
|
||||
{
|
||||
sb.Append(stm);
|
||||
}
|
||||
sb.Append("{/for}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class ForeachStatement : Statement
|
||||
{
|
||||
string elementIdentifier;
|
||||
string indexIdentifier;
|
||||
Expression collection;
|
||||
List<Statement> statements = new List<Statement>();
|
||||
|
||||
public ForeachStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public string ElementIdentifier
|
||||
{
|
||||
get { return elementIdentifier; }
|
||||
set { elementIdentifier = value; }
|
||||
}
|
||||
|
||||
public string IndexIdentifier
|
||||
{
|
||||
get { return indexIdentifier; }
|
||||
set { indexIdentifier = value; }
|
||||
}
|
||||
|
||||
public Expression Collection
|
||||
{
|
||||
get { return collection; }
|
||||
set { collection = value; }
|
||||
}
|
||||
|
||||
public List<Statement> Statements
|
||||
{
|
||||
get { return statements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
// evaluate collection expression
|
||||
object coll = Collection.Eval(context);
|
||||
if(!(coll is IEnumerable))
|
||||
throw new ParserException("Collection expression should evaluate into the value implementing IEnumerable interface.",
|
||||
Collection.Line, Collection.Column);
|
||||
|
||||
int idx = 0;
|
||||
foreach(object obj in ((IEnumerable)coll))
|
||||
{
|
||||
context.Variables[ElementIdentifier] = obj;
|
||||
if(IndexIdentifier != null)
|
||||
context.Variables[IndexIdentifier] = idx;
|
||||
idx++;
|
||||
|
||||
// evaluate statements
|
||||
foreach(Statement stm in Statements)
|
||||
stm.Eval(context, writer);
|
||||
}
|
||||
|
||||
// cleanup context
|
||||
context.Variables.Remove(ElementIdentifier);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{foreach ")
|
||||
.Append(ElementIdentifier).Append(" in ").Append(Collection);
|
||||
if (IndexIdentifier != null)
|
||||
sb.Append(" index ").Append(IndexIdentifier);
|
||||
sb.Append("}");
|
||||
foreach (Statement stm in Statements)
|
||||
{
|
||||
sb.Append(stm);
|
||||
}
|
||||
sb.Append("{/foreach}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class IdentifierExpression : Expression
|
||||
{
|
||||
List<IdentifierPart> parts = new List<IdentifierPart>();
|
||||
|
||||
public IdentifierExpression(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public List<IdentifierPart> Parts
|
||||
{
|
||||
get { return parts; }
|
||||
}
|
||||
|
||||
public override object Eval(TemplateContext context)
|
||||
{
|
||||
object val = null;
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
// get variable from context
|
||||
if (i == 0 && !parts[i].IsMethod)
|
||||
{
|
||||
val = EvalContextVariable(parts[i], context);
|
||||
}
|
||||
// call built-in function
|
||||
else if (i == 0 && parts[i].IsMethod)
|
||||
{
|
||||
BuiltinFunctions target = new BuiltinFunctions();
|
||||
target.Context = context;
|
||||
target.Line = parts[i].Line;
|
||||
target.Column = parts[i].Column;
|
||||
val = EvalMethod(target, parts[i], context);
|
||||
}
|
||||
// call public property
|
||||
else if(i > 0 && !parts[i].IsMethod) // property
|
||||
{
|
||||
val = EvalProperty(val, parts[i], context);
|
||||
}
|
||||
// call public method
|
||||
else if (i > 0 && parts[i].IsMethod) // property
|
||||
{
|
||||
val = EvalMethod(val, parts[i], context);
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private object EvalContextVariable(IdentifierPart variable, TemplateContext context)
|
||||
{
|
||||
object val = null;
|
||||
TemplateContext lookupContext = context;
|
||||
|
||||
while (lookupContext != null)
|
||||
{
|
||||
if (lookupContext.Variables.ContainsKey(variable.Name))
|
||||
{
|
||||
val = lookupContext.Variables[variable.Name];
|
||||
break; // found local scope var - stop looking
|
||||
}
|
||||
|
||||
// look into parent scope
|
||||
lookupContext = lookupContext.ParentContext;
|
||||
}
|
||||
|
||||
// get from context
|
||||
if (val == null)
|
||||
return null;
|
||||
|
||||
// evaluate index expression if required
|
||||
val = EvalIndexer(val, variable, context);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private object EvalIndexer(object target, IdentifierPart indexer, TemplateContext context)
|
||||
{
|
||||
if (indexer.Index == null)
|
||||
return target;
|
||||
|
||||
object index = null;
|
||||
index = indexer.Index.Eval(context);
|
||||
|
||||
if (index == null)
|
||||
throw new ParserException("Indexer expression evaluated to NULL", Line, Column);
|
||||
|
||||
if (target == null)
|
||||
throw new ParserException("Cannot call indexer on NULL object", Line, Column);
|
||||
|
||||
// get from index if required
|
||||
if(target is IDictionary)
|
||||
{
|
||||
// dictionary
|
||||
return ((IDictionary)target)[index];
|
||||
}
|
||||
else if (target is Array)
|
||||
{
|
||||
// array
|
||||
if(index is Int32)
|
||||
return ((Array)target).GetValue((Int32)index);
|
||||
else
|
||||
throw new ParserException("Array index expression must evaluate to integer.", Line, Column);
|
||||
}
|
||||
else if (target is IList)
|
||||
{
|
||||
// list
|
||||
if(index is Int32)
|
||||
return ((IList)target)[(Int32)index];
|
||||
else
|
||||
throw new ParserException("IList index expression must evaluate to integer.", Line, Column);
|
||||
}
|
||||
else
|
||||
{
|
||||
// call "get_Item" method
|
||||
MethodInfo methodInfo = target.GetType().GetMethod("get_Item",
|
||||
BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
|
||||
if (methodInfo != null)
|
||||
return methodInfo.Invoke(target, new object[] { index });
|
||||
}
|
||||
throw new ParserException("Cannot call indexer", Line, Column);
|
||||
}
|
||||
|
||||
private object EvalProperty(object target, IdentifierPart property, TemplateContext context)
|
||||
{
|
||||
object val = target;
|
||||
|
||||
// check for null
|
||||
if (val == null)
|
||||
throw new ParserException("Cannot read property value of NULL object", Line, Column);
|
||||
|
||||
// get property
|
||||
string propName = property.Name;
|
||||
PropertyInfo prop = val.GetType().GetProperty(propName,
|
||||
BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
|
||||
|
||||
if (prop == null)
|
||||
{
|
||||
// build the list of available properties
|
||||
StringBuilder propsList = new StringBuilder();
|
||||
int vi = 0;
|
||||
PropertyInfo[] props = val.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
||||
foreach (PropertyInfo p in props)
|
||||
{
|
||||
if (vi++ > 0)
|
||||
propsList.Append(",");
|
||||
propsList.Append(p.Name);
|
||||
}
|
||||
throw new ParserException("Public property could not be found: " + propName + "."
|
||||
+ " Supported properties: " + propsList.ToString(), Line, Column);
|
||||
}
|
||||
|
||||
// read property
|
||||
try
|
||||
{
|
||||
val = prop.GetValue(val, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ParserException("Cannot read property value: " + ex.Message, Line, Column);
|
||||
}
|
||||
|
||||
// evaluate index expression if required
|
||||
val = EvalIndexer(val, property, context);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private object EvalMethod(object target, IdentifierPart method, TemplateContext context)
|
||||
{
|
||||
object val = target;
|
||||
|
||||
// check for null
|
||||
if (val == null)
|
||||
throw new ParserException("Cannot perform method of NULL object", Line, Column);
|
||||
|
||||
// evaluate method parameters
|
||||
object[] prms = new object[method.MethodParameters.Count];
|
||||
Type[] prmTypes = new Type[method.MethodParameters.Count];
|
||||
|
||||
for (int i = 0; i < prms.Length; i++)
|
||||
{
|
||||
prms[i] = method.MethodParameters[i].Eval(context);
|
||||
if (prms[i] != null)
|
||||
prmTypes[i] = prms[i].GetType();
|
||||
else
|
||||
prmTypes[i] = typeof(object); // "null" parameter was specified
|
||||
}
|
||||
|
||||
// find method
|
||||
string methodName = method.Name;
|
||||
MethodInfo methodInfo = val.GetType().GetMethod(methodName,
|
||||
BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public,
|
||||
null, prmTypes, null);
|
||||
|
||||
if (methodInfo == null)
|
||||
{
|
||||
// failed to find exact signature
|
||||
// try to iterate
|
||||
methodInfo = val.GetType().GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
|
||||
}
|
||||
|
||||
if (methodInfo == null)
|
||||
{
|
||||
// build the list of available methods
|
||||
StringBuilder methodsList = new StringBuilder();
|
||||
int vi = 0;
|
||||
MethodInfo[] methods = val.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public);
|
||||
foreach (MethodInfo mi in methods)
|
||||
{
|
||||
if (vi++ > 0)
|
||||
methodsList.Append(",");
|
||||
methodsList.Append(mi.Name);
|
||||
}
|
||||
throw new ParserException("Public method could not be found: " + methodName + "."
|
||||
+ " Available methods: " + methodsList.ToString(), Line, Column);
|
||||
}
|
||||
|
||||
// call method
|
||||
try
|
||||
{
|
||||
val = methodInfo.Invoke(val, prms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ParserException("Cannot call method: " + ex.Message, Line, Column);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < Parts.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.Append(".");
|
||||
sb.Append(Parts[i]);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class IdentifierPart
|
||||
{
|
||||
string name;
|
||||
Expression index;
|
||||
bool isMethod;
|
||||
List<Expression> methodParameters = new List<Expression>();
|
||||
int line;
|
||||
int column;
|
||||
|
||||
public IdentifierPart(string name, int line, int column)
|
||||
{
|
||||
this.name = name;
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public Expression Index
|
||||
{
|
||||
get { return index; }
|
||||
set { index = value; }
|
||||
}
|
||||
|
||||
public bool IsMethod
|
||||
{
|
||||
get { return isMethod; }
|
||||
set { isMethod = value; }
|
||||
}
|
||||
|
||||
public List<Expression> MethodParameters
|
||||
{
|
||||
get { return methodParameters; }
|
||||
}
|
||||
|
||||
public int Line
|
||||
{
|
||||
get { return line; }
|
||||
}
|
||||
|
||||
public int Column
|
||||
{
|
||||
get { return column; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(name);
|
||||
if (Index != null)
|
||||
sb.Append("[").Append(Index).Append("]");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
138
WebsitePanel/Sources/WebsitePanel.Templates/AST/IfStatement.cs
Normal file
138
WebsitePanel/Sources/WebsitePanel.Templates/AST/IfStatement.cs
Normal file
|
@ -0,0 +1,138 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class IfStatement : Statement
|
||||
{
|
||||
Expression condition;
|
||||
List<ElseIfStatement> elseIfStatements = new List<ElseIfStatement>();
|
||||
List<Statement> trueStatements = new List<Statement>();
|
||||
List<Statement> falseStatements = new List<Statement>();
|
||||
|
||||
public IfStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public Expression Condition
|
||||
{
|
||||
get { return condition; }
|
||||
set { condition = value; }
|
||||
}
|
||||
|
||||
public List<ElseIfStatement> ElseIfStatements
|
||||
{
|
||||
get { return elseIfStatements; }
|
||||
}
|
||||
|
||||
public List<Statement> TrueStatements
|
||||
{
|
||||
get { return trueStatements; }
|
||||
}
|
||||
|
||||
public List<Statement> FalseStatements
|
||||
{
|
||||
get { return falseStatements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
// evaluate test condition
|
||||
bool result = EvalCondition(Condition, context);
|
||||
|
||||
if (result)
|
||||
{
|
||||
foreach (Statement stm in TrueStatements)
|
||||
stm.Eval(context, writer);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// process else if statements
|
||||
foreach (ElseIfStatement stm in ElseIfStatements)
|
||||
{
|
||||
if (EvalCondition(stm.Condition, context))
|
||||
{
|
||||
stm.Eval(context, writer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// process else
|
||||
foreach (Statement stm in FalseStatements)
|
||||
stm.Eval(context, writer);
|
||||
}
|
||||
}
|
||||
|
||||
private bool EvalCondition(Expression expr, TemplateContext context)
|
||||
{
|
||||
object val = expr.Eval(context);
|
||||
if (val is Boolean)
|
||||
return (Boolean)val;
|
||||
else if (val is Int32)
|
||||
return ((Int32)val) != 0;
|
||||
else if (val is Decimal)
|
||||
return ((Decimal)val) != 0;
|
||||
else if (val != null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{if ")
|
||||
.Append(Condition.ToString()).Append("}");
|
||||
|
||||
// true statements
|
||||
foreach (Statement stm in TrueStatements)
|
||||
sb.Append(stm);
|
||||
|
||||
// elseif statements
|
||||
foreach (Statement stm in ElseIfStatements)
|
||||
sb.Append(stm);
|
||||
|
||||
// false statements
|
||||
if(FalseStatements.Count > 0)
|
||||
{
|
||||
sb.Append("{else}");
|
||||
foreach (Statement stm in FalseStatements)
|
||||
sb.Append(stm);
|
||||
}
|
||||
|
||||
sb.Append("{/if}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class LiteralExpression : Expression
|
||||
{
|
||||
object val;
|
||||
|
||||
public LiteralExpression(int line, int column, object val)
|
||||
: base(line, column)
|
||||
{
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return val; }
|
||||
set { val = value; }
|
||||
}
|
||||
|
||||
public override object Eval(TemplateContext context)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return val != null ? val.ToString() : "null";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class PrintStatement : Statement
|
||||
{
|
||||
Expression printExpression;
|
||||
string formatter;
|
||||
|
||||
public PrintStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public Expression PrintExpression
|
||||
{
|
||||
get { return printExpression; }
|
||||
set { printExpression = value; }
|
||||
}
|
||||
|
||||
public string Formatter
|
||||
{
|
||||
get { return formatter; }
|
||||
set { formatter = value; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
writer.Write(PrintExpression.Eval(context));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return printExpression.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class SetStatement : Statement
|
||||
{
|
||||
Expression valueExpression;
|
||||
string name;
|
||||
|
||||
public SetStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public Expression ValueExpression
|
||||
{
|
||||
get { return valueExpression; }
|
||||
set { valueExpression = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
context.Variables[Name] = ValueExpression.Eval(context);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{set name=\"")
|
||||
.Append(Name).Append("\" value=\"")
|
||||
.Append(ValueExpression.ToString())
|
||||
.Append("\"/}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
59
WebsitePanel/Sources/WebsitePanel.Templates/AST/Statement.cs
Normal file
59
WebsitePanel/Sources/WebsitePanel.Templates/AST/Statement.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal abstract class Statement
|
||||
{
|
||||
int line;
|
||||
int column;
|
||||
|
||||
public Statement(int line, int column)
|
||||
{
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public int Line
|
||||
{
|
||||
get { return line; }
|
||||
}
|
||||
|
||||
public int Column
|
||||
{
|
||||
get { return column; }
|
||||
}
|
||||
|
||||
public abstract void Eval(TemplateContext context, StringWriter writer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class TemplateStatement : Statement
|
||||
{
|
||||
public string name;
|
||||
List<Statement> statements = new List<Statement>();
|
||||
|
||||
public TemplateStatement(int line, int column)
|
||||
: base(line, column)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public List<Statement> Statements
|
||||
{
|
||||
get { return statements; }
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("{template ")
|
||||
.Append("name=\"").Append(Name).Append("\"}");
|
||||
foreach (Statement stm in Statements)
|
||||
{
|
||||
sb.Append(stm);
|
||||
}
|
||||
sb.Append("{/template}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class TextStatement : Statement
|
||||
{
|
||||
string text;
|
||||
|
||||
public TextStatement(string text, int line, int column) : base(line, column)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public override void Eval(TemplateContext context, System.IO.StringWriter writer)
|
||||
{
|
||||
writer.Write(text);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Templates.AST
|
||||
{
|
||||
internal class UnaryExpression : Expression
|
||||
{
|
||||
Expression rhs;
|
||||
TokenType op;
|
||||
|
||||
public UnaryExpression(int line, int column, TokenType op, Expression rhs)
|
||||
: base(line, column)
|
||||
{
|
||||
this.op = op;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
public TokenType Operator
|
||||
{
|
||||
get { return op; }
|
||||
}
|
||||
|
||||
Expression RightExpression
|
||||
{
|
||||
get { return rhs; }
|
||||
set { rhs = value; }
|
||||
}
|
||||
|
||||
public override object Eval(TemplateContext context)
|
||||
{
|
||||
// evaluate right side
|
||||
object val = rhs.Eval(context);
|
||||
|
||||
if (op == TokenType.Minus && val is Decimal)
|
||||
return -(Decimal)val;
|
||||
else if (op == TokenType.Minus && val is Int32)
|
||||
return -(Int32)val;
|
||||
else if (op == TokenType.Not && val is Boolean)
|
||||
return !(Boolean)val;
|
||||
|
||||
throw new ParserException("Unary operator can be applied to integer, decimal and boolean expressions.", Line, Column);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(Operator).Append("(").Append(RightExpression).Append(")");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue