Пример #1
0
        public StringExpression(ASTNode parent, Scope scope, IList <LToken> tokens) : base(parent, scope, tokens)
        {
            if (this.Tokens.Count != 1)
            {
                throw new Exception("A StringExpression should only be composed of a single LToken of type String.");
            }
            LToken strtok = this.Tokens[0];

            if (strtok.ID == "literalstring")
            {
                this.UnescapedValue  = ( String )strtok.Value;
                this.EscapedValue    = this.UnescapedValue;
                this.StartDelimiter  = strtok.Raw.Substring(0, strtok.Raw.IndexOf('[', 1) + 1);
                this.EndDelimiter    = this.StartDelimiter.Replace('[', ']');
                this.IsLiteralString = true;
            }
            else
            {
                this.StartDelimiter = strtok.Raw[0].ToString( );
                this.EndDelimiter   = this.StartDelimiter;
                this.UnescapedValue = ( String )strtok.Value;

                var unescaped = new StringBuilder( );
                foreach (var c in ( String )strtok.Value)
                {
                    if (c == this.StartDelimiter[0] || c == '\n')
                    {
                        unescaped
                        .Append('\\')
                        .Append(c);
                    }
                    else if (!LJUtils.IsGraph(c) && !LJUtils.IsSpace(c))
                    {
                        unescaped.AppendFormat("\\x{0:X2}", ( Int32 )c);
                    }
                    else
                    {
                        unescaped.Append(c);
                    }
                }
                this.EscapedValue = unescaped.ToString( );
            }
        }
Пример #2
0
 public Error(ErrorType Type, LToken Token, String Message)
 {
     this.Type     = Type;
     this.Location = Token.Range.Start;
     this.Message  = Message;
 }
Пример #3
0
 private void AssertTokenEquals(LToken expected, string actual)
 {
     Assert.Equal(expected, LToken.Parse(actual), LTokenEqualityComparer.Instance);
 }
Пример #4
0
 private void AssertTokenEquals(LToken expected, LToken actual)
 {
     Assert.Equal(expected, actual, LTokenEqualityComparer.Instance);
 }
Пример #5
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;
                }