public static string Format_Literal_Expression(LiteralExpression literal)
        {
            switch (literal.LiteralType)
            {
                case LiteralType.True:
                    return "true";
                case LiteralType.False:
                    return "false";
                case LiteralType.Null:
                    return "null";
                /*
            case LiteralType.DecimalInteger:
                break;
            case LiteralType.HexadecimalInteger:
                break;
            case LiteralType.OctalInteger:
                break;
            case LiteralType.Real:
                break;
            case LiteralType.Character:
                break;
            case LiteralType.String:
                break;
            case LiteralType.VerbatimString:
                break;
                 */
            }

            return literal.LiteralValue;
        }
        protected void Verify(string source, object value)
        {
            if (!(value is Expression))
                value = new LiteralExpression(value);

            base.Verify(source, (Expression)value);
        }
        /// <summary>
        /// Initializes a new instance of the LabelStatement class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the statement.
        /// </param>
        /// <param name="identifier">
        /// The label identifier.
        /// </param>
        internal LabelStatement(CsTokenList tokens, LiteralExpression identifier)
            : base(StatementType.Label, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(identifier, "identifier");

            this.identifier = identifier;
            this.AddExpression(identifier);
        }
        /// <summary>
        /// Initializes a new instance of the EventDeclaratorExpression class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the statement.
        /// </param>
        /// <param name="identifier">
        /// The identifier name of the event.
        /// </param>
        /// <param name="initializer">
        /// The initialization expression for the event.
        /// </param>
        internal EventDeclaratorExpression(CsTokenList tokens, LiteralExpression identifier, Expression initializer)
            : base(ExpressionType.EventDeclarator, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(identifier, "identifier");
            Param.Ignore(initializer);

            this.identifier = identifier;
            this.initializer = initializer;

            this.AddExpression(identifier);

            if (initializer != null)
            {
                this.AddExpression(initializer);
            }
        }
        private static Expression CoerceLiteralExpression(LiteralExpression literal)
        {
            // Force 0 and 1 literals to boolean.

            if (literal.Value is int)
            {
                switch ((int)literal.Value)
                {
                    case 0:
                        return new LiteralExpression(false, LiteralType.Boolean);

                    case 1:
                        return new LiteralExpression(true, LiteralType.Boolean);
                }
            }

            throw new ODataException(ErrorMessages.Parser_ExpectedBooleanExpression);
        }
        /// <summary>
        /// Initializes a new instance of the AttributeExpression class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the expression.
        /// </param>
        /// <param name="target">
        /// The attribute target, if any.
        /// </param>
        /// <param name="initialization">
        /// The attribute initialization call.
        /// </param>
        internal AttributeExpression(CsTokenList tokens, LiteralExpression target, Expression initialization)
            : base(ExpressionType.Attribute, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.Ignore(target);
            Param.AssertNotNull(initialization, "initialization");

            // Add the target expression.
            this.target = target;
            if (target != null)
            {
                this.AddExpression(target);
            }

            // Add the initialization expression.
            this.initialization = initialization;
            this.AddExpression(initialization);
        }
 /// <summary>
 /// Initializes a new instance of the QualifiedAliasExpression class.
 /// </summary>
 /// <param name="proxy">Proxy object for the expression.</param>
 /// <param name="leftHandSide">The left side of the operation.</param>
 /// <param name="rightHandSide">The member being accessed.</param>
 internal QualifiedAliasExpression(CodeUnitProxy proxy, Expression leftHandSide, LiteralExpression rightHandSide)
     : base(proxy, ExpressionType.QualifiedAlias, leftHandSide, rightHandSide)
 {
     Param.Ignore(proxy, leftHandSide, rightHandSide);
 }
		protected virtual void VisitLiteral(LiteralExpression literal)
		{
		}
Example #9
0
        /// <summary>
        /// Initializes a new instance of the CatchStatement class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the statement.
        /// </param>
        /// <param name="tryStatement">
        /// The try-statement that this catch-statement is attached to.
        /// </param>
        /// <param name="classExpression">
        /// The inner expression.
        /// </param>
        /// <param name="embeddedStatement">
        /// The statement embedded within the catch-statement.
        /// </param>
        internal CatchStatement(CsTokenList tokens, TryStatement tryStatement, Expression classExpression, BlockStatement embeddedStatement)
            : base(StatementType.Catch, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(classExpression);
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");

            this.tryStatement = tryStatement;
            this.catchExpression = classExpression;
            this.embeddedStatement = embeddedStatement;

            if (classExpression != null)
            {
                this.AddExpression(classExpression);

                if (classExpression != null)
                {
                    if (classExpression.ExpressionType == ExpressionType.Literal)
                    {
                        this.classType = ((LiteralExpression)classExpression).Token as TypeToken;
                    }
                    else if (classExpression.ExpressionType == ExpressionType.VariableDeclaration)
                    {
                        VariableDeclarationExpression variableDeclaration = (VariableDeclarationExpression)classExpression;

                        this.classType = variableDeclaration.Type;

                        foreach (VariableDeclaratorExpression declarator in variableDeclaration.Declarators)
                        {
                            this.identifier = declarator.Identifier;
                            break;
                        }
                    }
                }
            }

            this.AddStatement(embeddedStatement);
        }
Example #10
0
 public void VisitLiteralExpression(LiteralExpression literal)
 {
     throw new NotImplementedException();
 }
 public string GetExpression(LiteralExpression expression, ref List<OleDbParameter> parameters)
 {
     string name = "p" + parameters.Count.ToString();
     OleDbParameter parameter = new OleDbParameter(name, expression.Value);
     parameters.Add(parameter);
     return " ? ";
 }
        private Expression GetNextExpression(
            ExpressionPrecedence previousPrecedence, bool unsafeCode, bool allowVariableDeclaration, bool typeExpression)
        {
            Param.Ignore(previousPrecedence);
            Param.Ignore(unsafeCode);
            Param.Ignore(allowVariableDeclaration);
            Param.Ignore(typeExpression);

            // Saves the next expression.
            Expression expression = null;

            // Get the next symbol.
            Symbol symbol = this.GetNextSymbol();

            if (symbol != null)
            {
                switch (symbol.SymbolType)
                {
                    case SymbolType.Other:
                        if (this.IsLambdaExpression())
                        {
                            expression = this.GetLambdaExpression(unsafeCode);
                        }
                        else if (this.IsQueryExpression(unsafeCode))
                        {
                            expression = this.GetQueryExpression(unsafeCode);
                        }

                        // If the expression is still null now, this is just a regular 'other' expression.
                        if (expression == null)
                        {
                            expression = this.GetOtherExpression(allowVariableDeclaration, unsafeCode);
                        }

                        break;

                    case SymbolType.Checked:
                        expression = this.GetCheckedExpression(unsafeCode);
                        break;

                    case SymbolType.Unchecked:
                        expression = this.GetUncheckedExpression(unsafeCode);
                        break;

                    case SymbolType.New:
                        expression = this.GetNewAllocationExpression(unsafeCode);
                        break;

                    case SymbolType.Stackalloc:
                        expression = this.GetStackallocExpression(unsafeCode);
                        break;

                    case SymbolType.Sizeof:
                        expression = this.GetSizeofExpression(unsafeCode);
                        break;

                    case SymbolType.Typeof:
                        expression = this.GetTypeofExpression(unsafeCode);
                        break;

                    case SymbolType.Default:
                        expression = this.GetDefaultValueExpression(unsafeCode);
                        break;

                    case SymbolType.Delegate:
                        expression = this.GetAnonymousMethodExpression(unsafeCode);
                        break;

                    case SymbolType.Increment:
                        if (this.IsUnaryExpression())
                        {
                            expression = this.GetUnaryIncrementExpression(unsafeCode);
                        }

                        break;

                    case SymbolType.Decrement:
                        if (this.IsUnaryExpression())
                        {
                            expression = this.GetUnaryDecrementExpression(unsafeCode);
                        }

                        break;

                    case SymbolType.Plus:
                    case SymbolType.Minus:
                        if (this.IsUnaryExpression())
                        {
                            expression = this.GetUnaryExpression(unsafeCode);
                        }

                        break;

                    case SymbolType.Not:
                    case SymbolType.Tilde:
                        expression = this.GetUnaryExpression(unsafeCode);
                        break;

                    case SymbolType.OpenParenthesis:
                        if (this.IsLambdaExpression())
                        {
                            expression = this.GetLambdaExpression(unsafeCode);
                        }
                        else
                        {
                            expression = this.GetOpenParenthesisExpression(unsafeCode);
                        }

                        break;
                            
                    case SymbolType.Number:
                        Node<CsToken> tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Number, SymbolType.Number));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.String:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.String, SymbolType.String));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.True:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.True, SymbolType.True));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.False:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.False, SymbolType.False));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.Null:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Null, SymbolType.Null));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.This:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.This, SymbolType.This));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.Base:
                        tokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Base, SymbolType.Base));
                        expression = new LiteralExpression(new CsTokenList(this.tokens, tokenNode, tokenNode), tokenNode);
                        break;

                    case SymbolType.Multiplication:
                        if (!unsafeCode)
                        {
                            goto default;
                        }

                        expression = this.GetUnsafeAccessExpression(unsafeCode);
                        break;

                    case SymbolType.LogicalAnd:
                        if (!unsafeCode)
                        {
                            goto default;
                        }

                        expression = this.GetUnsafeAccessExpression(unsafeCode);
                        break;

                    default:
                        throw new SyntaxException(this.document.SourceCode, symbol.LineNumber);
                }
            }

            // Gather up all extensions to this expression.
            while (expression != null)
            {
                // Check if there is an extension to this expression.
                Expression extension = this.GetExpressionExtension(expression, previousPrecedence, unsafeCode, typeExpression);
                if (extension != null)
                {
                    // The larger expression is what we want to return here.
                    expression = extension;
                }
                else
                {
                    // There are no more extensions.
                    break;
                }
            }

            // Return the expression.
            return expression;
        }
Example #13
0
	void LiteralExpression(ref ExpressionTreeBase expr) {
		if (la.kind == 35) {
			Get();
			expr = new RangeExpression(t.val); 
		} else if (la.kind == 3) {
			Get();
			expr = new LiteralExpression(t.val); 
		} else if (la.kind == 4) {
			Get();
			expr = new LiteralExpression(t.val.Substring(1, t.val.Length - 2), true); 
		} else if (la.kind == 5) {
			Get();
			expr = new ValueExpression(Int32.Parse(t.val.Substring(1))); 
		} else if (la.kind == 1) {
			Get();
			expr = new LiteralExpression(t.val); 
		} else SynErr(53);
	}
 public void VisitLiteralExpression(LiteralExpression literal)
 {
     //no op
 }
Example #15
0
        public static bool TryCoerceInt(LiteralExpression expression, out int result)
        {
            switch (expression.LiteralType)
            {
                case LiteralType.Int:
                    result = (int)expression.Value;
                    return true;

                case LiteralType.Long:
                    result = (int)(long)expression.Value;
                    return true;

                default:
                    result = 0;
                    return false;
            }
        }
Example #16
0
 public static string CoerceString(LiteralExpression literal)
 {
     if (literal.LiteralType == LiteralType.String)
         return (string)literal.Value;
     else
         return literal.Value.ToString();
 }
		protected override void VisitLiteral(LiteralExpression literal)
		{
			base.VisitLiteral(literal);
			AppendCodeBlock(String.Format(@"{0}.push({1});", 
				CodeBufferVariableName, _serializer.Serialize(literal.Literal)));
		}
Example #18
0
        public Window1()
        {
            BindKey(ApplicationCommands.Find, Key.F, ModifierKeys.Control);
            BindKey(EditingCommands.Backspace, Key.N, ModifierKeys.Alt);
            BindKey(EditingCommands.Delete, Key.M, ModifierKeys.Alt);
            BindKey(EditingCommands.DeleteNextWord, Key.M, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.DeletePreviousWord, Key.N, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveDownByLine, Key.K, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveDownByPage, Key.K, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveLeftByCharacter, Key.J, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveRightByCharacter, Key.Oem3, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveUpByLine, Key.L, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveLeftByWord, Key.J, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveRightByWord, Key.M, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveToDocumentEnd, Key.Oem1, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveToDocumentStart, Key.U, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.MoveToLineEnd, Key.Oem1, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveToLineStart, Key.U, ModifierKeys.Alt);
            BindKey(EditingCommands.MoveUpByPage, Key.L, ModifierKeys.Alt | ModifierKeys.Control);
            BindKey(EditingCommands.SelectDownByLine, Key.K, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectDownByPage, Key.K, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectLeftByCharacter, Key.J, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectLeftByWord, Key.J, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectRightByCharacter, Key.Oem3, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectRightByWord, Key.Oem1, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectToDocumentEnd, Key.Oem1, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectToDocumentStart, Key.U, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectToLineEnd, Key.Oem1, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectToLineStart, Key.U, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectUpByLine, Key.L, ModifierKeys.Alt | ModifierKeys.Shift);
            BindKey(EditingCommands.SelectUpByPage, Key.L, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift);
            InitializeComponent();
            textBox.FontSize = 16;
            intellisense.MaxHeight = 100;
            intellisense.Width = 200;
            intellisense.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);

            textBox.FontFamily = new FontFamily("Courier New");
            textBox.AcceptsTab = true;
            intellisense.MouseDoubleClick += delegate {
                Complete();
            };
            textBox.PreviewKeyDown += delegate(object sender, KeyEventArgs e) {
                if (Intellisense) {
                    e.Handled = true;
                    if (e.KeyboardDevice.Modifiers == ModifierKeys.Alt) {
                        if (e.Key == Key.L) {
                            IntellisenseUp();
                        }
                        else if (e.Key == Key.K) {
                            IntellisenseDown();
                        }
                        else {
                            e.Handled = false;
                        }
                    }
                    else if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
                        if (e.Key == Key.L) {
                            EditingCommands.MoveToLineStart.Execute(null, textBox);
                            EditingCommands.SelectToLineEnd.Execute(null, textBox);
                            EditingCommands.Delete.Execute(null, textBox);
                        }
                        else if (e.Key == Key.Space) {
                        }
                        else {
                            e.Handled = false;
                        }
                    }
                    else if (e.Key == Key.Return) {
                        Complete();
                    }
                    else if (e.Key == Key.Tab) {
                        Complete();
                    }
                    else if (e.Key == Key.Up) {
                        IntellisenseUp();
                    }
                    else if (e.Key == Key.Down) {
                        IntellisenseDown();
                    }
                    else {
                        e.Handled = false;
                    }
                }
            };;
            textBox.KeyDown += delegate(object obj, KeyEventArgs e) {
                if (e.Key == Key.Return) {
                    string line = textBox.GetLineText(textBox.GetLineIndexFromCharacterIndex(textBox.SelectionStart));
                    textBox.SelectedText = "\n".PadRight(1 + line.Length - line.TrimStart('\t').Length, '\t');
                    textBox.SelectionStart = textBox.SelectionStart + textBox.SelectionLength;
                    textBox.SelectionLength = 0;
                    textBox.Focus();
                }
                else if (e.Key == Key.Escape) {
                    if (Intellisense) {
                        intellisense.Visibility = Visibility.Hidden;
                    }
                }
                else if (e.Key == Key.OemPeriod) {
                    string text = textBox.Text.Substring(0, textBox.SelectionStart);
                    searchStart = textBox.SelectionStart;
                    Interpreter.profiling = false;
                    foreach (Parser.CachedRule rule in Parser.CachedRule.cachedRules) {
                        rule.cached.Clear();
                    }
                    Parser parser = new Parser(text, fileName);
                    Map map = null;
                    bool matched = Parser.File.Match(parser, ref map);
                    LiteralExpression gac = new LiteralExpression(Gac.gac, null);
                    LiteralExpression lib = new LiteralExpression(Gac.gac["library"], gac);
                    lib.Statement = new LiteralStatement(gac);
                    KeyStatement.intellisense = true;
                    map[CodeKeys.Function].GetExpression(lib).Statement = new LiteralStatement(lib);
                    map[CodeKeys.Function].Compile(lib);
                    Source key = new Source(
                        parser.State.Line,
                        parser.State.Column,
                        parser.FileName);
                    intellisense.Items.Clear();
                    if (Meta.Expression.sources.ContainsKey(key)) {
                        List<Meta.Expression> list = Meta.Expression.sources[key];
                        for (int i = 0; i < list.Count; i++) {
                            if (list[i] is Search || list[i] is Select) {
                                PositionIntellisense();
                                intellisense.Items.Clear();
                                Structure s = list[i].EvaluateStructure();
                                List<string> keys = new List<string>();
                                if (s != null) {
                                    foreach (Map m in ((LiteralStructure)s).Literal.Keys) {
                                        keys.Add(m.ToString());
                                    }
                                }
                                keys.Sort(delegate(string a, string b) {
                                    return a.CompareTo(b);
                                });
                                if (keys.Count != 0) {
                                    intellisense.Visibility = Visibility.Visible;
                                }
                                foreach (string k in keys) {
                                    intellisense.Items.Add(k);
                                }
                                if (intellisense.Items.Count != 0) {
                                    intellisense.SelectedIndex = 0;
                                }
                            }
                        }
                    }
                    else {
                        MessageBox.Show("no intellisense" + Meta.Expression.sources.Count);
                    }
                    Meta.Expression.sources.Clear();
                }
            };
            DockPanel dockPanel = new DockPanel();

            Menu menu = new Menu();
            DockPanel.SetDock(menu, Dock.Top);
            MenuItem file = new MenuItem();
            MenuItem save = new MenuItem();
            MenuItem run = new MenuItem();
            MenuItem open = new MenuItem();
            file.Header = "File";
            open.Header = "Open";
            save.Header = "Save";
            run.Header = "Run";
            open.Click += delegate {
                OpenFileDialog dialog = new OpenFileDialog();
                if (dialog.ShowDialog() == true) {
                    Open(dialog.FileName);
                }
            };
            run.Click += delegate {
                Save();
                Process.Start(System.IO.Path.Combine(@"D:\Meta\", @"bin\Debug\Meta.exe"), fileName);
            };
            save.Click += delegate {
                Save();
            };
            DockPanel.SetDock(status, Dock.Bottom);
            dockPanel.Children.Add(status);

            file.Items.Add(open);
            file.Items.Add(save);
            file.Items.Add(run);
            menu.Items.Add(file);
            dockPanel.Children.Add(menu);

            DockPanel.SetDock(textBox,Dock.Bottom);
            textBox.TextChanged += delegate {
                if (Intellisense) {
                    if (textBox.SelectionStart <= searchStart) {
                        intellisense.Visibility = Visibility.Hidden;
                    }
                    else {
                        int index = textBox.Text.Substring(0, textBox.SelectionStart).LastIndexOf('.');
                        if (index != -1) {
                            string text = textBox.Text.Substring(index + 1, textBox.SelectionStart - index - 1);
                            foreach (string item in intellisense.Items) {
                                if (item.StartsWith(text, StringComparison.OrdinalIgnoreCase)) {
                                    intellisense.SelectedItem = item;
                                    intellisense.ScrollIntoView(intellisense.SelectedItem);
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            textBox.SelectionChanged += delegate {
                status.Content = "Ln " +
                    (textBox.GetLineIndexFromCharacterIndex(textBox.SelectionStart) + 1);
            };
            Canvas canvas = new Canvas();
            canvas.Children.Add(textBox);
            canvas.Background = Brushes.Yellow;
            DockPanel.SetDock(canvas, Dock.Top);
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            scrollViewer.Content = canvas;
            dockPanel.Children.Add(scrollViewer);
            const int width = 0;
            const int height = 0;

            Canvas.SetLeft(textBox, width/2);
            Canvas.SetTop(textBox, height/2);
            textBox.SizeChanged += delegate {
                canvas.Width = textBox.ActualWidth + width;
                canvas.Height = textBox.ActualHeight + height;
            };
            intellisense.SelectionChanged += delegate(object sender, SelectionChangedEventArgs e) {
                if (intellisense.SelectedItem != null) {
                    intellisense.ScrollIntoView(intellisense.SelectedItem);
                }
            };
            intellisense.Visibility = Visibility.Hidden;
            Canvas.SetZIndex(intellisense, 100);
            canvas.Children.Add(intellisense);
            this.Content = dockPanel;
            this.Loaded += delegate {
                Open(@"D:\meta\game.meta");
                textBox.Focus();
                textBox.SelectionStart = 0;
            };
        }
    private static Expression ParseExpression(Match match)
    {
      string expressionText = match.Value.Trim();
      Expression expression;
      lock (_expressions)
      {
        if (_expressions.TryGetValue(expressionText, out expression))
        {
          return expression;
        }
        // temporarily add a dummy expression to prevent other threads from parsing the same expression again
        Log.Debug("Cacheing expression: {0}", expressionText);
        _expressions.Add(expressionText, new LiteralExpression(expressionText));
      }

      if (match.Groups["string"].Success)
      {
        expression = new LiteralExpression(match.Groups["string"].Value);
      }
      else if (match.Groups["int"].Success)
      {
        expression = new LiteralExpression(int.Parse(match.Groups["int"].Value));
      }
      else if (match.Groups["float"].Success)
      {
        expression = new LiteralExpression(float.Parse(match.Groups["float"].Value, CultureInfo.InvariantCulture));
      }
      else if (match.Groups["property"].Success)
      {
        expression = new PropertyExpression(match.Groups["property"].Value);
      }
      else if (match.Groups["function"].Success)
      {
        string functionName = match.Groups["function"].Value;
        FunctionDefinition function;
        if (!_registeredFunctions.TryGetValue(functionName, out function))
        {
          Log.Error("Undefined function '{0}' in expression '{1}'", functionName, match.Value);
          expression = new LiteralExpression(match.Value);
        }
        else
        {
          int paramCount = match.Groups["param"].Captures.Count;
          Expression[] parameters = new Expression[paramCount];

          for (int i = 0; i < paramCount; i++)
          {
            string paramText = match.Groups["param"].Captures[i].Value;
            Match paramMatch = _expressionRegEx.Match(paramText);
            parameters[i] = ParseExpression(paramMatch);
          }

          expression = new FunctionExpression(_registeredFunctions[functionName], parameters);
        }
      }
      lock (_expressions)
      {
        // now replace with the real expression
        _expressions[expressionText] = expression;
      }
      return expression;
    }
 public virtual void VisitLiteralExpression(LiteralExpression literalExpression)
 {
     VisitChildren (literalExpression);
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayoutKeyValue"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public LayoutKeyValue(Identifier name, object value)
 {
     Name = name;
     Value = new LiteralExpression(value);
 }
 /// <summary>
 /// Initializes a new instance of the PointerAccessExpression class.
 /// </summary>
 /// <param name="proxy">Proxy object for the expression.</param>
 /// <param name="leftHandSide">The left side of the operation.</param>
 /// <param name="rightHandSide">The member being accessed.</param>
 internal PointerAccessExpression(CodeUnitProxy proxy, Expression leftHandSide, LiteralExpression rightHandSide)
     : base(proxy, ExpressionType.PointerAccess, leftHandSide, rightHandSide)
 {
     Param.Ignore(proxy, leftHandSide, rightHandSide);
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayoutKeyValue"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public LayoutKeyValue(Identifier name, LiteralExpression value)
 {
     Name = name;
     Value = value;
 }
Example #24
0
 public override void Visit(LiteralExpression node)
 {
     base.Visit(node);
     _result = Expression.Constant(node.Value, typeof(object));
 }