示例#1
0
        private Token ScanBracketsExpression(System.IO.TextReader reader)
        {
            StringBuilder builder = new StringBuilder();
            char          c;

            reader.Read();
            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (c != ']')
                {
                    reader.Read();
                    builder.Append(c);
                }
                else
                {
                    reader.Read();
                    break;
                }
            }

            if (IsUserDefinedResultString(builder))
            {
                return(CreateStringTokenForUdr(builder));
            }

            Token  token;
            string input = builder.ToString();

            if (!complexTokens.TryGetValue(input, out token))
            {
                token = new VariableToken(input);
            }
            return(token);
        }
示例#2
0
 void EatWhitespace()
 {
     while (char.IsWhiteSpace((char)reader.Peek()))
     {
         reader.Read();
     }
 }
示例#3
0
        private Token ScanConstStringToken(System.IO.TextReader reader)
        {
            StringBuilder builder = new StringBuilder();
            char          c;

            reader.Read();
            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (c != '\'')
                {
                    reader.Read();
                    builder.Append(c);
                }
                else
                {
                    reader.Read();
                    break;
                }
            }
            Token  token;
            string input = builder.ToString();

            token = new StringToken(input);
            if (input != string.Empty)
            {
                DateTime dt = DateTime.MinValue;
                if (ConvertStringToDateTime(input, ref dt))
                {
                    token = new DateTimeToken(dt);
                }
            }
            return(token);
        }
示例#4
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads and ignores whitespace characters from a
        /// System.IO.TextReader.
        /// </summary>
        public static void SkipWhitespace(System.IO.TextReader reader)
        {
            int i = reader.Peek();

            while (i != -1 && char.IsWhiteSpace((char)i))
            {
                reader.Read();
                i = reader.Peek();
            }
        }
示例#5
0
        public RTFTokenType PeekTokenType()
        {
            int c = myReader.Peek();

            while (c == '\r' ||
                   c == '\n' ||
                   c == '\t' ||
                   c == '\0')
            {
                c = myReader.Read();
                c = myReader.Peek();
            }
            if (c == EOF)
            {
                return(RTFTokenType.Eof);
            }
            else
            {
                switch (c)
                {
                case '{':
                    return(RTFTokenType.GroupStart);

                case '}':
                    return(RTFTokenType.GroupEnd);

                case '\\':
                    return(RTFTokenType.Control);

                default:
                    return(RTFTokenType.Text);
                }
            }
        }
示例#6
0
        private Token ScanGramarToken(System.IO.TextReader reader)
        {
            StringBuilder builder = new StringBuilder();
            char          c;
            Token         tk;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (char.IsWhiteSpace(c))
                {
                    break;
                }
                else
                {
                    string str = builder.ToString();
                    if (simpleTokens.TryGetValue(c, out tk))
                    {
                        break;
                    }
                    if (complexTokens.TryGetValue(str, out tk))
                    {
                        if (complexTokens.TryGetValue(str + c, out tk))
                        {
                            reader.Read();
                            builder.Append(c);
                        }
                        break;
                    }

                    if (gramar.Contains(c) && str != string.Empty)
                    {
                        if (complexTokens.TryGetValue(str + c, out tk))
                        {
                            reader.Read();
                            builder.Append(c);
                        }
                        break;
                    }
                    reader.Read();
                    builder.Append(c);
                }
            }
            Token  token;
            string input = builder.ToString();

            /*
             *  All unknown letter-only strings default to varaibles.
             */
            if (!complexTokens.TryGetValue(input, out token))
            {
                token = new VariableToken(input);
            }
            return(token);
        }
示例#7
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads a word from a System.IO.TextReader.  A word is one or more
        /// adjacent non-whitespace characters.
        /// </summary>
        public static string ReadWord(System.IO.TextReader reader)
        {
            StringBuilder word = new StringBuilder();
            int           i    = reader.Peek();

            while (i != -1 && !char.IsWhiteSpace((char)i))
            {
                word.Append((char)reader.Read());
                i = reader.Peek();
            }
            return(word.ToString());
        }
示例#8
0
        public IEnumerator <string> ScanTokenString(System.IO.TextReader reader)
        {
            char  c;
            Token token;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (char.IsWhiteSpace(c))
                {
                    reader.Read();
                }
                else if (simpleTokens.TryGetValue(c, out token))
                {
                    yield return(c.ToString());

                    reader.Read();
                }
                else if (char.IsDigit(c))
                {
                    yield return(ScanDoubleAsString(reader));
                }
                else if (c == '[')
                {
                    token = ScanBracketsExpression(reader);
                    if (token is VariableToken)
                    {
                        yield return("[" + ((VariableToken)token).Name + "]");
                    }
                    else if (token is StringToken)
                    {
                        yield return("[#" + ((StringToken)token).Value + "#]");
                    }
                }
                else if (c == '\'')
                {
                    yield return("'" + ScanConstStringToken(reader).ToString() + "'");
                }
                else if (gramar.Contains(c) || char.IsLetter(c))
                {
                    yield return(ScanGramarTokenString(reader));
                }
                else
                {
                    ParseError();
                }
            }
            yield return("");
        }
示例#9
0
        private void TImportar_Tick(object sender, EventArgs e)
        {
            if (rt.Peek() > 0)
            {
                int rxs      = 1000 / TImportar.Interval;
                int segundos = (cBarraProgreso1.ValorMaximo - cBarraProgreso1.Progreso) / rxs;
                int minutos  = segundos / 60;
                segundos = segundos - (minutos * 60);
                cBarraProgreso1.Texto = cBarraProgreso1.Progreso.ToString() + "/" + cBarraProgreso1.ValorMaximo.ToString() + " Lineas leidas del archivo Tiempo estimado=" + minutos.ToString() + " minutos y " + segundos.ToString() + " Segundos  ";
                cBarraProgreso1.Progreso++;
                string s = rt.ReadLine();
                AgregaLiea(s);
            }
            else
            {
                rt.Close();
                TImportar.Enabled = false;
                //ahora reviso el numero de registros
                if (CreaTabla() == false)
                {
                    return;
                }
//                InsertaDatos();
                cBarraProgreso1.Texto       = "Subiendo registros";
                cBarraProgreso1.Progreso    = 0;
                cBarraProgreso1.ValorMaximo = Datos.Count;
                TimeSubirRegistros.Enabled  = true;
            }
        }
示例#10
0
        private void readString(System.IO.TextReader reader)
        {
            val  = "";
            type = Type.Literal;
            int  c   = reader.Read();          // read "
            bool esc = false;

            do
            {
                c = reader.Read();
                if (c == '\\' && !esc)
                {
                    esc = true;
                }
                else
                {
                    val += (char)c;
                    esc  = false;
                }
                c = reader.Peek();
            } while (c != -1 && (c != '"' || esc == true));
            if (c == '"')
            {
                reader.Read();                 // read "
            }
        }
示例#11
0
        /// <summary>
        /// read and ignore data , until just the end of current group,preserve the end.
        /// </summary>
        public void ReadToEndGround( )
        {
            int level = 0;

            while (true)
            {
                int c = myReader.Peek();
                if (c == -1)
                {
                    break;
                }
                else if (c == '{')
                {
                    level++;
                }
                else if (c == '}')
                {
                    level--;
                    if (level < 0)
                    {
                        break;
                    }
                }
                c = myReader.Read();
            }
        }
示例#12
0
        /// <summary>
        ///   move on to next token.
        ///   This method does the actual work of cutting up the input sequence.
        /// </summary>
        /// <returns><c>false</c> if positioned beyond tokens</returns>
        /// <exception><c>IOException</c> on input error</exception>
        public bool Advance()
        {
            int ch;

            if (AtEof)
            {
                return(false);
            }
            for (;;)
            {
                switch (ch = In.Read())
                {
                case -1:
                    AtEof = true; return(false);

                case ' ':
                case '\t':
                    continue;

                default:
                    if (System.Char.IsDigit((char)ch)) // support decimal integer values as double
                    {
                        value = ch - '0';
                        while (System.Char.IsDigit((char)In.Peek()))
                        {
                            value *= 10;
                            value += In.Read() - '0';
                        }
                        token = Arith.Number; return(true);
                    }
                    value = token = ch; return(true);
                }
            }
        }
        private static System.IO.TextReader GetDecodedInterviewAnswers(System.IO.TextReader input, ref string originalAnswers)
        {
            int firstc = input.Peek();

            if (firstc != -1)
            {
                char first = (char)firstc;
                if (first == '[')                 // looks like answers from stateless interview (HDANS format)
                {
                    // answers probably start with "[HDANS(" etc.
                    string ansPkg = input.ReadToEnd();
                    if (ansPkg.StartsWith("[HDSANS(", StringComparison.OrdinalIgnoreCase))
                    {
                        int end = ansPkg.IndexOf(")]", 8);
                        if (end > 0)
                        {
                            var lens = ansPkg.Substring(8, end - 8).Split(',');
                            if (lens.Length == 2)
                            {
                                int ansLen = int.Parse(lens[0]);
                                int orgLen = int.Parse(lens[1]);
                                if (ansPkg[end + 2 + ansLen] == '|')
                                {
                                    if (orgLen > 0 && originalAnswers != null)
                                    {
                                        originalAnswers = ansPkg.Substring(end + ansLen + 3, orgLen);
                                    }

                                    // decode & then return XML
                                    ansPkg = Encoding.UTF8.GetString(Convert.FromBase64String(ansPkg.Substring(end + 2, ansLen)));
                                    if (ansPkg[0] == 0xFEFF)
                                    {
                                        ansPkg = ansPkg.Substring(1);
                                    }
                                    return(new System.IO.StringReader(ansPkg));
                                }
                            }
                        }
                    }
                    // else
                    throw new ArgumentException("Error parsing interview answers.");
                }
                else if (first == '<')                 // looks like bare XML answers
                {
                    // answers probably start with "<?xml "
                    return(input);
                }
                else                 // otherwise should be base64 encoded UTF16 XML
                {
                    byte[] buffer  = Convert.FromBase64String(input.ReadToEnd());
                    string decoded = Encoding.Unicode.GetString(buffer);                    //This was "Unicode" (not "UTF8").
                    if (decoded.Length > 0 && decoded[0] == '\xfeff')
                    {
                        decoded = decoded.Substring(1);
                    }
                    return(new System.IO.StringReader(decoded));
                }
            }
            return(new System.IO.StringReader(""));
        }
示例#14
0
        public void Interpret(System.IO.TextReader input)
        {
            while (input.Peek() != -1)
            {
                string line = input.ReadLine();              //TODO add newline seperator to grammar
                if (line.Length > 0)
                {
                    Stream.TextReader reader = new Stream.TextReader(new System.IO.StringReader(line));

                    try
                    {
                        while (reader.Peek() != -1)
                        {
                            Stream.Node node   = this._parser.Parse(reader);
                            object      result = Evaluate(node);
                            if (result != null)
                            {
                                throw new System.Exception("Result is not expected.");
                            }
                        }
                    }
                    catch (System.Exception exception)
                    {
                        this.Output.WriteLine("ERROR: " + exception.Message + "\n" + exception.StackTrace);
                        this.Output.WriteLine();
                    }
                }
            }
        }
示例#15
0
 protected void ProcessLines(System.IO.TextReader sr, LineProcessor processor)
 {
     while (sr.Peek() != -1)
     {
         var line = sr.ReadLine();
         this.ProcessLine(line, processor);
     }
 }
示例#16
0
        /// <summary>
        /// Lexes and parses a JSON value as a System.Object in the specified text reader.
        /// </summary>
        /// <param name="reader">The text reader to lex and parse an object from.</param>
        /// <param name="context">The parser context.</param>
        /// <returns>A System.Object value, if found; otherwise, a ParseException is thrown.</returns>
        /// <remarks>
        /// This method does not consume whitespace; the character at the specified start index in the string is expected to be the start of a valid JSON value.
        /// </remarks>
        internal static object ParseAny(System.IO.TextReader reader, ParserContext context)
        {
            var c = reader.Peek();

            if (c < 0)
            {
                throw new ParseException("Unexpected end of stream when parsing a JSON value.", -1, ParseError.PrematureEndOfInput);
            }

            switch (c)
            {
            case 'n':
                if (!TryParseNullSkipN(reader, context))
                {
                    throw new ParseException("Expected null literal after lexing 'n' character.", -1, ParseError.UnexpectedToken);
                }
                return(null);

            case 't':
            case 'f':
                return(ParseBoolean(reader, context));

            case '-':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':

                //
                // CONSIDER: This could be made configurable to return a float, double, or decimal. There could even be a mode that
                //           looks ahead to detect the absence of '.' (and possibly '-') and allow an (unsigned) integer value to be
                //           returned. We skip adding these modes for now and pick a meaningful default, which also makes the resulting
                //           object easier to consume because only a few type checks need to be made.
                //

                return(ParseDouble(reader, context));

            case '\"':
                return(ParseString(reader, context));

            case '[':
                return(ParseAnyArray(reader, context));

            case '{':
                return(ParseAnyObject(reader, context, ParseAny));

            default:
                throw new ParseException(string.Format(CultureInfo.InvariantCulture, "Unexpected character '{0}' when deserializing a JSON value.", (char)c), -1, ParseError.UnexpectedToken);
            }
        }
示例#17
0
        public static EastAsianWidthDictionary Create(System.IO.TextReader sr)
        {
            EastAsianWidthDictionary dic = new EastAsianWidthDictionary();

            System.Text.RegularExpressions.Regex reg
                = new System.Text.RegularExpressions.Regex(@"^(?<CODE1>[0-9A-F]+)(\.\.(?<CODE2>[0-9A-F]+))?;(?<WIDTH>(Na|N|W|F|H|A))\s");

            EastAsianWidthDictionary dictionary = new EastAsianWidthDictionary();

            string line;

            while (sr.Peek() != -1)
            {
                line = sr.ReadLine();
                if (line.StartsWith("#"))
                {
                    continue;
                }

                var match = reg.Match(line);
                if (match.Success)
                {
                    string          sw = match.Groups["WIDTH"].Value;
                    EastAsianWidths w  = EastAsianWidths.Unknown;
                    switch (sw[0])
                    {
                    case 'N': w = sw.Length == 1 ? EastAsianWidths.Neutral : EastAsianWidths.Narrow; break;

                    case 'W': w = EastAsianWidths.Wide; break;

                    case 'F': w = EastAsianWidths.FullWidth; break;

                    case 'H': w = EastAsianWidths.HalfWidth; break;

                    case 'A': w = EastAsianWidths.Ambiguous; break;

                    default: w = EastAsianWidths.Unknown; break;
                    }

                    int code1 = int.Parse(match.Groups["CODE1"].Value, System.Globalization.NumberStyles.HexNumber);
                    int code2 = code1;
                    if (match.Groups["CODE2"].Success)
                    {
                        code2 = int.Parse(match.Groups["CODE2"].Value, System.Globalization.NumberStyles.HexNumber);
                    }

                    Range r = new Range(w, code1, code2);

                    dic.List.Add(r);
                }
                else
                {
                }
            }
            return(dic);
        }
示例#18
0
        private string ScanDoubleAsString(System.IO.TextReader reader)
        {
            string result = string.Empty;
            char   c;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (System.Char.IsDigit(c) || c == '.')
                {
                    result += c;
                    reader.Read();
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
示例#19
0
        private static void LoadSolution(System.IO.TextReader reader, Models.Solution solution)
        {
            if (reader.Peek() == -1)
            {
                reader.Read();
            }
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();

                if (line.StartsWith("Project"))
                {
                    LoadProject(line, solution);
                }
                else if (line.StartsWith("	GlobalSection(SolutionConfiguration)"))
                {
                    LoadConfigurations(reader, solution);
                }
            }
        }
示例#20
0
        public static System.Collections.IList Parse(System.IO.TextReader reader)
        {
            if (reader.Peek() == -1)
            {
                return(null);
            }

            System.Collections.ArrayList table = new System.Collections.ArrayList();

            while (reader.Peek() != -1)
            {
                System.Collections.IList row = ParseRow(reader);
                if (row != null && row.Count > 0)
                {
                    table.Add(row);
                }
            }

            return(table);
        }
示例#21
0
        public IEnumerator <Token> Scan(System.IO.TextReader reader)
        {
            char  c;
            Token token;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (char.IsWhiteSpace(c))
                {
                    reader.Read();
                }
                else if (simpleTokens.TryGetValue(c, out token))
                {
                    yield return(token);

                    reader.Read();
                }
                else if (char.IsDigit(c))
                {
                    yield return(ScanDouble(reader));
                }
                else if (c == '[')
                {
                    yield return(ScanBracketsExpression(reader));
                }
                else if (c == '\'')
                {
                    yield return(ScanConstStringToken(reader));
                }
                else if (gramar.Contains(c) || char.IsLetter(c))
                {
                    yield return(ScanGramarToken(reader));
                }
                else
                {
                    ParseError();
                }
            }
            yield return(new BareToken(TokenKind.End));
        }
示例#22
0
        internal static void SkipWhiteSpace(System.IO.TextReader reader)
        {
            //
            // NB: TextReader.Peek is well-defined to return -1 (and not any negative value) when no input is available.
            //     The char representation of -1 is \uffff which is not a whitespace character, so the test below is easy.
            //

            while (char.IsWhiteSpace((char)reader.Peek()))
            {
                reader.Read();
            }
        }
示例#23
0
 private static string GetSegment(System.IO.TextReader reader)
 {
     System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
     while (reader.Peek() != -1)
     {
         char ch = (char)reader.Peek();
         if (ch == '[')
         {
             break;
         }
         else if (ch == '.')
         {
             break;
         }
         else
         {
             stringBuilder.Append(ch);
             reader.Read();
         }
     }
     return(stringBuilder.ToString());
 }
示例#24
0
        private void readLiteral(System.IO.TextReader reader)
        {
            val  = "";
            type = Type.Literal;
            int c = -1;

            do
            {
                c    = reader.Read();
                val += (char)c;
                c    = reader.Peek();
            } while (IsIDChar((char)c) && c != -1);
        }
示例#25
0
        // return true if it is a comment
        private bool readKeyWord(System.IO.TextReader reader)
        {
            int  i = reader.Read();
            char c = (char)i;

            type = Type.Keyword;
            // some are 2 chars
            char c2 = (char)reader.Peek();

            if (c == '>' && c2 == '=')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '<' && c2 == '=')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '=' && c2 == '=')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '!' && c2 == '=')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '&' && c2 == '&')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '|' && c2 == '|')
            {
                reader.Read();
                val = "" + c + c2;
            }
            else if (c == '/' && c2 == '/')
            {
                reader.ReadLine();
                return(true);
            }
            else
            {
                val = "" + c;
            }
            return(false);
        }
示例#26
0
        private static string ParseQuotedString(System.IO.TextReader reader)
        {
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

            while (reader.Peek() != -1)
            {
                char ch = (char)reader.Read();

                switch (ch)
                {
                case '\"':
                {
                    if (reader.Peek() == (int)'\"')
                    {
                        stringBuilder.Append(EscapeQuotedString(reader));
                    }
                    else
                    {
                        if (reader.Peek() == (int)',')
                        {
                            reader.Read();
                        }
                        return(stringBuilder.ToString());
                    }
                    break;
                }

                default:
                {
                    stringBuilder.Append(ch);
                    break;
                }
                }
            }

            throw new System.Exception("Quoted string did not terminate.");
        }
示例#27
0
        private void ReadNextWord()
        {
            if (currentWord != null)
            {
                return;
            }
            System.Text.StringBuilder sb = new StringBuilder();
            char nextChar;
            int  next;

            do
            {
                next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                nextChar = (char)next;
                if (char.IsWhiteSpace(nextChar))
                {
                    break;
                }
                sb.Append(nextChar);
            } while (true);
            while ((reader.Peek() >= 0) && (char.IsWhiteSpace((char)reader.Peek())))
            {
                reader.Read();
            }
            if (sb.Length > 0)
            {
                currentWord = sb.ToString();
            }
            else
            {
                currentWord = null;
            }
        }
示例#28
0
        private DoubleToken ScanDouble(System.IO.TextReader reader)
        {
            double result = 0.0d;
            double factor = 0.1d;
            char   c;
            bool   dotNotRead = true;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (System.Char.IsDigit(c))
                {
                    double dv = c - 48;
                    if (dotNotRead)
                    {
                        result *= 10;
                        result += dv;
                    }
                    else
                    {
                        result += factor * dv;
                        factor /= 10;
                    }
                    reader.Read();
                }
                else if (dotNotRead && c == '.')
                {
                    dotNotRead = false;
                    reader.Read();
                }
                else
                {
                    break;
                }
            }
            return(new DoubleToken(result));
        }
示例#29
0
        private static void TrimWhitespace(System.IO.TextReader reader)
        {
            int n;

            while ((n = reader.Peek()) != -1)
            {
                char ch = (char)n;

                if (!IsWhitespace(ch))
                {
                    return;
                }
                reader.Read();
            }
        }
示例#30
0
        private static void LoadConfigurations(System.IO.TextReader reader, Models.Solution solution)
        {
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();

                if (line.StartsWith("	EndGlobalSection"))
                {
                    return;
                }

                Models.Config config = new Models.Config();
                config.Name = line.Split("=".ToCharArray())[0].Trim();
                solution.Configs.Add(config);
            }
        }