Esempio n. 1
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.Entity"/> class.
			/// </summary>
			public Entity(L20nObject index, bool is_private, L20nObject value, L20nObject attributes)
			{
				m_Index = index;
				m_Value = value;
				m_Attributes = attributes;
				m_IsPrivate = is_private;
			}
Esempio n. 2
0
			/// <summary>
			/// A common evaluation method that defines the actual logic to cast
			/// both parameters to the same and accepted type (bool, literal or string).
			/// Returns null in case no legal match was found.
			/// </summary>
			private L20nObject CommonEval(L20nObject first, L20nObject second)
			{
				// Are they literals?
				var l1 = first as Literal;
				var l2 = second as Literal;

				if (l1 != null && l2 != null)
				{
					m_Output.Value = Operation(l1.Value, l2.Value);
					return m_Output;
				}
				
				// Are they booleans?
				var b1 = first as BooleanValue;
				var b2 = second as BooleanValue;
				
				if (b1 != null && b2 != null)
				{
					m_Output.Value = Operation(b1.Value, b2.Value);
					return m_Output;
				}
				
				// Are they strings!
				var s1 = first as StringOutput;
				var s2 = second as StringOutput;
				
				if (s1 != null && s2 != null)
				{
					m_Output.Value = Operation(s1.Value, s2.Value);
					return m_Output;
				}

				return null;
			}
Esempio n. 3
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.Macro"/> class.
			/// </summary>
			public Macro(
				string identifier, L20nObject expression, string[] parameters)
			{
				m_Parameters = parameters;
				m_Expression = expression;
				m_Identifier = identifier;
			}
Esempio n. 4
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.StringValue"/> class
			/// with the format string (<c>value</c>) and the <c>expressions</c>
			/// given by the callee of this constructor.
			/// </summary>
			public StringValue(string value, L20nObject[] expressions)
			{
				m_Value = value;
				m_Expressions = expressions;

				m_EvaluatedExpressions = new string[expressions.Length];
				m_Output = new StringOutput();
			}
Esempio n. 5
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.IfElseExpression"/> class.
			/// </summary>
			public IfElseExpression(
				L20nObject condition,
				L20nObject if_true, L20nObject if_false)
			{
				m_Condition = condition;
				m_IfTrue = if_true;
				m_IfFalse = if_false;
			}
Esempio n. 6
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.PropertyExpression"/> class.
			/// An exception gets thrown in case less than 2 identifiers is given,
			/// as that should never happen.
			/// </summary>
			/// <param name="identifiers">Identifiers.</param>
			public PropertyExpression(string[] identifiers)
			{
				if (identifiers.Length < 2)
				{
					throw new EvaluateException("a property needs at least 2 identifiers");
				}

				// create an Identifier for each given identifier string.
				m_Identifiers = new L20nObject[identifiers.Length];
				for (int i = 0; i < identifiers.Length; ++i)
				{
					m_Identifiers [i] = new Identifier(identifiers [i]);
				}
			}
Esempio n. 7
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.PropertyExpression"/> class.
			/// An exception gets thrown in case less than 2 identifiers is given,
			/// as that should never happen.
			/// </summary>
			public PropertyExpression(L20nObject[] identifiers)
			{
				m_Identifiers = identifiers;
			}
Esempio n. 8
0
			public NegativeExpression(L20nObject e) : base(e)
			{
			}
Esempio n. 9
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.UnaryNumericExpression"/> class.
			/// </summary>
			public UnaryNumericExpression(L20nObject expression)
			{
				m_Expression = expression;
				m_Output = new Literal();
			}
Esempio n. 10
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.Index"/> class.
			/// </summary>
			public Index(L20nObject[] indeces)
			{
				m_Indeces = indeces;
				m_EvaluatedIndeces = new L20nObject[indeces.Length];
			}
Esempio n. 11
0
			public SubstractExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
				m_Output = new Literal();
			}
Esempio n. 12
0
			/// <summary>
			/// Will return <c>null</c> in case this is a root entity and this instance is private,
			/// or in case something else went wrong.
			/// Otherwise it will evaluate the value, optionally using the first given <c>argv</c> parameter,
			/// which will always result in a <see cref="L20nCore.Objects.StringOutput"/> value in case of success.
			/// </summary>
			public override L20nObject Eval(LocaleContext ctx, params L20nObject[] argv)
			{
				// if the first given parameter is of L20n type dummy, we'll check if we're not private.
				// if not we can continue and will simply re-call this method with the
				// dummy object removed from the given parameters.
				if (argv.Length != 0 && (argv [0] as Dummy) != null)
				{
					if (m_IsPrivate)
					{
						Logger.Warning("entity is marked as private and cannot be accessed from C#");
						return null;
					}

					if (argv.Length > 1)
					{
						var arguments = new L20nObject[argv.Length - 1];
						for (int i = 0; i < arguments.Length; ++i)
							arguments [i] = argv [i + 1];
						return this.Eval(ctx, arguments);
					} else
					{
						return this.Eval(ctx);
					}
				}
	
				// if index is given and no extern parameters have been given,
				// we'll evaluate the index and will use that to evaluate the final output value.
				// this also assumes that in case the index is given,
				// that the value is a HashValue rather than a StringValue,
				// which is something the parser of this type enforces anyhow.
				if (m_Index != null && argv.Length == 0)
				{
					var index = m_Index.Eval(ctx);
					if (index == null)
					{
						Logger.Warning("Entity: index couldn't be evaluated");
						return index;
					}

					// could be one simple identifier, in which case we can evaluate
					// the HashValue of this instance given the identifier as a parameter
					var identifier = index as Identifier;
					if (identifier != null)
					{
						var result = m_Value.Eval(ctx, identifier);
						if (result == null)
						{
							Logger.Warning("<Entity>: <Identifier>-index got evaluated to null");
							return null;
						}

						return result.Eval(ctx);
					}

					// otherwise it should be a PropertyExpression,
					// in which case we evaluate that expression given this instance as the first parameter.
					var property = index as PropertyExpression;
					if (property != null)
					{
						var result = property.Eval(ctx, this);
						if (result == null)
						{
							Logger.Warning("<Entity>: <PropertyExpression>-index got evaluated to null");
							return null;
						}

						return result.Eval(ctx);
					}

					Logger.Warning("couldn't evaluate entity as index was expexted to be a <property_expression>");
					return null;
				}

				// in all other cases we simply evaluate the wrapped value,
				// passing on the given external parameters (e.g. an index)
				return m_Value.Eval(ctx, argv);
			}
Esempio n. 13
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.HashValue"/> class.
			/// </summary>
			public KeyValuePair(L20nObject value, L20nObject index)
			{
				m_Value = value;
				m_Index = index;
			}
Esempio n. 14
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.BinaryExpression"/> class.
			/// </summary>
			public BinaryExpression(L20nObject first, L20nObject second)
			{
				m_First = first;
				m_Second = second;
				m_Output = new BooleanValue();
			}
Esempio n. 15
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.IsNotEqualExpression"/> class.
			/// </summary>
			public IsNotEqualExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
			}
Esempio n. 16
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.BinaryNumericExpression"/> class.
			/// </summary>
			public BinaryNumericExpression(L20nObject first, L20nObject second)
			{
				m_First = first;
				m_Second = second;
			}
Esempio n. 17
0
			public GreaterThanOrEqualExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
				m_Output = new BooleanValue();
			}
Esempio n. 18
0
			/// <summary>
			/// Pushes <c>value</c> on the stack with
			/// the value of <c>key</c> as its name.
			/// </summary>
			public void PushVariable(string key, L20nObject value)
			{
				m_Variables.Push(key, value);
			}
Esempio n. 19
0
			public AddExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
				m_Output = new Literal();
			}
Esempio n. 20
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.LogicalExpression"/> class.
			/// </summary>
			public LogicalExpression(L20nObject first, L20nObject second)
			{
				m_First = first;
				m_Second = second;
			}
Esempio n. 21
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.Identifier"/> class,
			/// with the given <c>value</c> used to look up the L20nObject instance.
			/// </summary>
			public AttributeExpression(L20nObject root, L20nObject identifier, L20nObject propertyExpression)
			{
				m_Root = root;
				m_Identifier = identifier;
				m_PropertyExpression = propertyExpression;
			}
Esempio n. 22
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.AndExpression"/> class.
			/// </summary>
			public AndExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
			}
Esempio n. 23
0
			/// <summary>
			/// Initializes a new instance of the <see cref="L20nCore.Objects.NegateExpression"/> class.
			/// </summary>
			public NegateExpression(L20nObject expression)
			{
				m_Expression = expression;
				m_Output = new BooleanValue();
			}
Esempio n. 24
0
			public CallExpression(string identifier, L20nObject[] variables)
			{
				m_Identifier = identifier;
				m_Variables = variables;
			}
Esempio n. 25
0
			private void AddObject(string name, L20nObject value)
			{
				if (m_Info.ContainsKey(name))
				{
					Internal.Logger.WarningFormat(
						"information with the name {0} will be overriden", name);
				}

				m_Info.Add(name, value);
			}
Esempio n. 26
0
 /// <summary>
 /// This function should be called after the L20n Initialization, but before any translation, if possible.
 /// Even though it's safe to call it at any time during runtime, it is not recommended.
 /// Globals are available to all locales and are accessible within the L20n Language via the @-syntax.
 /// This function stores the given <c>value</c> as a global value with the given <c>id</c> as its name.
 /// </summary>
 public static void AddGlobal(string id, L20nObject value)
 {
     GetCore().AddGlobal(id, value);
 }
Esempio n. 27
0
			public PositiveExpression(L20nObject e) : base(e)
			{
			}
Esempio n. 28
0
			public LessThanExpression(L20nObject a, L20nObject b)
			: base(a, b)
			{
				m_Output = new BooleanValue();
			}
Esempio n. 29
0
	/// <summary>
	/// This function should be called after the L20n Initialization, but before any translation, if possible.
	/// Even though it's safe to call it at any time during runtime, it is not recommended.
	/// Globals are available to all locales and are accessible within the L20n Language via the @-syntax.
	/// This function stores the given <c>value</c> as a global value with the given <c>id</c> as its name. 
	/// </summary>
	public static void AddGlobal (string id, L20nObject value)
	{
		GetCore ().AddGlobal (id, value);
	}
Esempio n. 30
0
			/// <summary>
			/// A help function to get the root entity based on the first variable.
			/// The given identifier is either an Identifier, Variable or Global,
			/// which will define the action to be taken in order to get and return the Root Entity.
			/// </summary>
			private Entity GetEntity(LocaleContext ctx, L20nObject key)
			{
				// is it an identifier?
				var identifier = key as Identifier;
				if (identifier != null)
					return ctx.GetEntity(identifier.Value);

				// is it a variable?
				var variable = key as Variable;
				if (variable != null)
				{
					var obj = ctx.GetVariable(variable.Identifier);
					
					// a variable can also be a string-reference to an entity
					var reference = obj as StringOutput;
					if (reference != null)
					{
						return ctx.GetEntity(reference.Value);
					}

					// otherwise it's simply an entity (or at least it should be)
					return obj as Entity;
				}

				// is it a global?
				var global = key as Global;
				if (global != null)
					return ctx.GetGlobal(global.Identifier) as Entity;

				// is it a string?
				var str = key as StringOutput;
				if (str != null)
					return ctx.GetEntity(str.Value);

				return null;
			}