protected virtual Object[] AnalyseTableConstructorExpression(TableConstructorExpression node, params Object[] args)
 {
     foreach (TableKeyValue field in node.Fields)
     {
         this.Analyse(field);
     }
     return(null);
 }
 public void SetArgument(TableConstructorExpression arg)
 {
     if (this.Argument != null)
     {
         this.RemoveChild(this.Argument);
     }
     this.AddChild(arg);
     this.Argument = arg;
 }
Example #3
0
        protected override Object[] AnalyseTableConstructorExpression(TableConstructorExpression node, params Object[] args)
        {
            var sequentialIndex = 1;

            foreach (TableKeyValue keyValue in node.Fields)
            {
                if (keyValue.IsSequential)
                {
                    keyValue.Key = GetNumberExpression(keyValue.Key, sequentialIndex++);
                }
            }

            return(null);
        }
Example #4
0
        public override void ConstructTableConstructorExpression(TableConstructorExpression node)
        {
            // First token is always {
            this.Write('{');

            if (node.Fields.Count > 1)
            {
                this.WriteLine( );
            }
            else if (node.Fields.Count == 1 && !node.Fields[0].IsSequential)
            {
                this.Write(' ');
            }

            this.Indent( );
            for (var i = 0; i < node.Fields.Count; i++)
            {
                TableKeyValue field = node.Fields[i];

                if (field.IsSequential)
                {// No key to write
                }
                else if (field.Key.Tokens[0].ID == "ident")
                {
                    this.WriteIndented((( StringExpression )field.Key).Value);
                    this.Write(" = ");
                }
                else
                {
                    this.WriteIndented('[');
                    this.ConstructInternal(field.Key);
                    this.Write("] = ");
                }

                this.ConstructInternal(field.Value);
                this.WriteLine(field.Separator);
            }
            this.Outdent( );

            this.WriteIndented('}');
        }
Example #5
0
 protected virtual ASTNode FoldTableConstructorExpression(TableConstructorExpression node, params Object[] args)
 {
     node.SetFields(this.FoldNodeList(node.Fields));
     return(node);
 }
Example #6
0
        protected TableConstructorExpression ParseTableConstructorExpression(ASTNode parent, Scope scope)
        {
            var fullTableTokens = new List <LToken> ( );
            var tableExpr       = new TableConstructorExpression(parent, scope, fullTableTokens);

            this.Expect("{", fullTableTokens);

            while (true)
            {
                TableKeyValue fieldExp;
                if (this.NextIs("["))
                {
                    ; // tbl = {
                    ; //     [expr] = expr(,|;)
                    ; // }
                    var fieldTokens = new List <LToken> ( );
                    this.Get(fieldTokens);

                    ASTNode keyExpr = this.ParseExpression(tableExpr, scope);

                    this.Expect("]", fieldTokens);
                    this.Expect("=", fieldTokens);

                    ASTNode valExpr = this.ParseExpression(tableExpr, scope);

                    fieldExp = tableExpr.AddExplicitKeyField(keyExpr, valExpr, "", fieldTokens);
                    fullTableTokens.AddRange(fieldTokens);
                }
                else if (this.NextIs("ident"))
                {
                    if (this.Peek(1).ID == "=")
                    {
                        ; // tbl = {
                        ; //     keyString = expr(,|;)
                        ; // }
                        var fieldTokens = new List <LToken> ( );

                        LToken  strTok = this.Get <LToken> ( );
                        ASTNode strExp = new StringExpression(tableExpr, scope, new List <LToken> (new[] { strTok }));

                        this.Expect("=", fieldTokens);

                        ASTNode valExp = this.ParseExpression(tableExpr, scope);

                        fieldExp = tableExpr.AddExplicitKeyField(strExp, valExp, "", fieldTokens);
                        fullTableTokens.AddRange(fieldTokens);
                    }
                    else
                    {
                        ; // tbl = {
                        ; //     identExpr,
                        ; // }

                        ASTNode identExpr = this.ParseExpression(tableExpr, scope);

                        fieldExp = tableExpr.AddSequentialField(identExpr, "", new List <LToken> ( ));
                    }
                }
                else if (this.Consume("}", out LToken _, fullTableTokens))
                {
                    // table end
                    break;
                }
 public abstract void ConstructTableConstructorExpression(TableConstructorExpression node);