示例#1
0
 public ZScriptToken(ZScriptToken other)
 {
     Type           = other.Type;
     Value          = other.Value;
     ValueInt       = other.ValueInt;
     ValueDouble    = other.ValueDouble;
     IsValid        = other.IsValid;
     WarningMessage = other.WarningMessage;
     Position       = other.Position;
 }
示例#2
0
 public void SkipWhitespace() // note that this skips both whitespace, newlines AND comments
 {
     while (true)
     {
         ZScriptToken tok = ExpectToken(ZScriptTokenType.Newline, ZScriptTokenType.BlockComment, ZScriptTokenType.LineComment, ZScriptTokenType.Whitespace);
         if (tok == null || !tok.IsValid)
         {
             break;
         }
     }
 }
示例#3
0
        private ZScriptToken TryReadIdentifier()
        {
            long cpos = LastPosition = reader.BaseStream.Position;
            char c    = reader.ReadChar();

            // check identifier
            if ((c >= 'a' && c <= 'z') ||
                (c >= 'A' && c <= 'Z') ||
                (c == '_'))
            {
                SB.Length = 0;
                SB.Append(c);
                while (true)
                {
                    char cnext = reader.ReadChar();
                    if ((cnext >= 'a' && cnext <= 'z') ||
                        (cnext >= 'A' && cnext <= 'Z') ||
                        (cnext == '_') ||
                        (cnext >= '0' && cnext <= '9'))
                    {
                        SB.Append(cnext);
                        continue;
                    }

                    reader.BaseStream.Position--;
                    break;
                }

                ZScriptToken tok = new ZScriptToken();
                tok.Position = cpos;
                tok.Type     = ZScriptTokenType.Identifier;
                tok.Value    = SB.ToString();
                return(tok);
            }

            reader.BaseStream.Position = cpos;
            return(null);
        }
示例#4
0
        private ZScriptToken TryReadWhitespace()
        {
            long cpos = LastPosition = reader.BaseStream.Position;
            char c    = reader.ReadChar();

            //
            string whitespace = " \r\t\u00A0";

            // check whitespace
            if (whitespace.Contains(c))
            {
                //string ws_content = "";
                SB.Length = 0;
                SB.Append(c);
                while (true)
                {
                    char cnext = reader.ReadChar();
                    if (whitespace.Contains(cnext))
                    {
                        SB.Append(cnext);
                        continue;
                    }

                    reader.BaseStream.Position--;
                    break;
                }

                ZScriptToken tok = new ZScriptToken();
                tok.Position = cpos;
                tok.Type     = ZScriptTokenType.Whitespace;
                tok.Value    = SB.ToString();
                return(tok);
            }

            reader.BaseStream.Position = cpos;
            return(null);
        }