Пример #1
0
        public override byte ParseByte(RCLexer lexer, RCToken token)
        {
            int major = HexCharToByte(token.Text[2]);
            int minor = HexCharToByte(token.Text[3]);

            return((byte)((major << 4) | minor));
        }
Пример #2
0
        public override object Parse(RCLexer lexer, RCToken token)
        {
            char last = token.Text[token.Text.Length - 1];

            switch (last)
            {
            case 'N': return(double.NaN);

            case 'd': return(ParseDouble(lexer, token));

            case 'l': return(ParseLong(lexer, token));

            case 'm': return(ParseDecimal(lexer, token));

            case 'i': return(ParseInt(lexer, token));

            case 'f': return(ParseFloat(lexer, token));
                // default: throw new Exception (
                //  "Cannot parse " + token.Text + ": If a number is used as a symbol or in a cube
                // the type
                // must be specified on every row");
            }
            if (token.Text.IndexOf('.') > -1)
            {
                return(ParseDouble(lexer, token));
            }
            else
            {
                return(ParseLong(lexer, token));
            }
        }
Пример #3
0
        public override RCSymbolScalar ParseSymbol(RCLexer lexer, RCToken token)
        {
            if (token.Text == "#")
            {
                return(RCSymbolScalar.Empty);
            }
            string[] parts = token.Text.Split(',');
            string   first = parts[0];

            // When "casting" strings into symbols, the initial # may be omitted
            // so that "a" becomes #a.
            if (first[0] == '#')
            {
                first = first.Substring(1);
            }
            RCToken        child  = lexer.LexSingle(first);
            object         part   = child.Parse(lexer);
            RCSymbolScalar result = new RCSymbolScalar(null, part);

            for (int i = 1; i < parts.Length; ++i)
            {
                child  = lexer.LexSingle(parts[i]);
                result = new RCSymbolScalar(result, child.Parse(lexer));
            }
            return(result);
        }
Пример #4
0
        static CSVParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.CSVContent);
            _csvLexer = new RCLexer(types);
        }
Пример #5
0
        static LogParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.LogEntryHeader);
            types.Write(RCTokenType.EndOfLine);
            types.Write(RCTokenType.LogEntryBody);
            types.Write(RCTokenType.LogEntryRawLine);
            _logLexer = new RCLexer(types);
        }
Пример #6
0
 public override string ParseString(RCLexer lexer, RCToken token)
 {
     if (token.Text[0] != '"')
     {
         return(token.Text);
     }
     else
     {
         string undelim = token.Text.Substring(1, token.Text.Length - 2);
         return(UnescapeControlChars(undelim, '"'));
     }
 }
Пример #7
0
        static XMLParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.XmlDeclaration);
            types.Write(RCTokenType.XmlContent);
            types.Write(RCTokenType.WhiteSpace);
            // We need a "XmlString" to support single quoted strings.
            // Also escape chars in xml.
            types.Write(RCTokenType.XmlString);
            types.Write(RCTokenType.XmlBracket);
            types.Write(RCTokenType.XmlName);
            _xmlLexer = new RCLexer(types);
        }
Пример #8
0
        static JSONParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.WhiteSpace);
            types.Write(RCTokenType.String);
            types.Write(RCTokenType.Number);
            types.Write(RCTokenType.Boolean);
            types.Write(RCTokenType.Block);
            types.Write(RCTokenType.Cube);
            types.Write(RCTokenType.Null);
            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.Evaluator);
            _jsonLexer = new RCLexer(types);
        }
Пример #9
0
        static MarkdownParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.EndOfLine);
            types.Write(RCTokenType.MarkdownLinkToken);
            types.Write(RCTokenType.MarkdownLiteralLinkToken);
            types.Write(RCTokenType.MarkdownHeaderToken);
            types.Write(RCTokenType.MarkdownBlockquoteToken);
            types.Write(RCTokenType.MarkdownBeginBoldToken);
            types.Write(RCTokenType.MarkdownEndBoldToken);
            types.Write(RCTokenType.MarkdownBeginItalicToken);
            types.Write(RCTokenType.MarkdownEndItalicToken);
            types.Write(RCTokenType.MarkdownULItemToken);
            types.Write(RCTokenType.MarkdownOLItemToken);
            types.Write(RCTokenType.MarkdownLIIndentToken);
            types.Write(RCTokenType.MarkdownContentToken);
            _markdownLexer = new RCLexer(types);
        }
Пример #10
0
 public override RCIncrScalar ParseIncr(RCLexer lexer, RCToken token)
 {
     // Assume it is always ++ because we don't do -- yet.
     if (token.Text == "++")
     {
         return(RCIncrScalar.Increment);
     }
     else if (token.Text == "+-")
     {
         return(RCIncrScalar.Decrement);
     }
     else if (token.Text == "+~")
     {
         return(RCIncrScalar.Delete);
     }
     else
     {
         throw new Exception("Unrecognized incr token: " + token.Text);
     }
 }
Пример #11
0
        public static RCSymbolScalar From(RCLexer lexer, string part)
        {
            RCToken token = lexer.LexSingle(part);

            if (token.Text.Length > 0 && token.Type == RCTokenType.Junk)
            {
                return(new RCSymbolScalar(RCSymbolScalar.Empty,
                                          string.Format("'{0}'", token.Text)));
            }
            else
            {
                object         val    = token.Parse(lexer);
                RCSymbolScalar result = val as RCSymbolScalar;
                if (result == null)
                {
                    return(new RCSymbolScalar(RCSymbolScalar.Empty, val));
                }
                else
                {
                    return(result);
                }
            }
        }
Пример #12
0
        static RCLParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.Content);
            types.Write(RCTokenType.WhiteSpace);
            types.Write(RCTokenType.EmptyVector);
            types.Write(RCTokenType.String);
            types.Write(RCTokenType.Time);
            types.Write(RCTokenType.Number);
            types.Write(RCTokenType.Boolean);
            types.Write(RCTokenType.Symbol);
            types.Write(RCTokenType.Incr);
            types.Write(RCTokenType.Literal);
            types.Write(RCTokenType.Paren);
            types.Write(RCTokenType.Block);
            types.Write(RCTokenType.Cube);
            types.Write(RCTokenType.Reference);
            types.Write(RCTokenType.Evaluator);
            types.Write(RCTokenType.Spacer);
            types.Write(RCTokenType.Name);
            types.Write(RCTokenType.Junk);
            _o2Lexer = new RCLexer(types);
        }
Пример #13
0
 public virtual RCTimeScalar ParseTime(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "time"));
 }
Пример #14
0
 public virtual RCIncrScalar ParseIncr(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "incr"));
 }
Пример #15
0
 public virtual byte ParseByte(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "byte"));
 }
Пример #16
0
 public override RCTimeScalar ParseTime(RCLexer lexer, RCToken token)
 {
     return(ParseTime(token.Text));
 }
Пример #17
0
 public override long ParseLong(RCLexer lexer, RCToken token)
 {
     return(long.Parse(ExtractNumber(token)));
 }
Пример #18
0
 public abstract void AcceptScalar(object state, RCToken token, RCLexer lexer);
Пример #19
0
        public override void AcceptScalar(object state, RCToken token, RCLexer lexer)
        {
            State s = (State)state;

            // Move the column number forward.
            s._tcolumn = (s._tcolumn + 1) % s._tnames.Count;
            // Create the cube if necessary.
            if (s._cube == null)
            {
                s._cube = new RCCube(s._tlcolnames);
            }
            if (s._tcolumn < s._tlcolnames.Count)
            {
                string colname = s._tnames[s._tcolumn];
                char   letter  = colname[0];
                switch (letter)
                {
                case 'G':
                    s._global = token.ParseLong(lexer);
                    break;

                case 'E':
                    s._event = token.ParseLong(lexer);
                    break;

                case 'T':
                    s._time = token.ParseTime(lexer);
                    break;

                case 'S':
                    s._symbol = token.ParseSymbol(lexer);
                    break;

                default: throw new Exception(
                              "Unknown timeline column with letter: " + letter);
                }
            }
            else
            {
                object val = token.Parse(lexer);
                if (val != null)
                {
                    ColumnBase column = s._cube.GetColumn(s._tnames[s._tcolumn]);
                    if (s._canonical && column != null && column is RCCube.ColumnOfNothing)
                    {
                        s._cube.UnreserveColumn(s._tnames[s._tcolumn]);
                    }
                    s._cube.WriteCell(s._tnames[s._tcolumn], s._symbol, val, -1, true, true);
                }
                else
                {
                    s._cube.ReserveColumn(s._tnames[s._tcolumn], canonical: s._canonical);
                }
            }
            // if (s._forceAxisWrite || s._tcolumn == s._tnames.Count - 1)
            if (s._tcolumn == s._tnames.Count - 1)
            {
                // If there is no time column in the source text then create a
                // series of ascending integers.
                if (!s._hasT)
                {
                    ++s._event;
                }
                s._cube.Axis.Write(s._global, s._event, s._time, s._symbol);
                // s._forceAxisWrite = false;
            }
        }
Пример #20
0
 public virtual float ParseFloat(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "double"));
 }
Пример #21
0
 public virtual decimal ParseDecimal(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "decimal"));
 }
Пример #22
0
 public virtual long ParseLong(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "long"));
 }
Пример #23
0
 public virtual object Parse(RCLexer lexer, RCToken token)
 {
     throw new Exception("cannot use " + Name + " as a symbol or within a cube");
 }
Пример #24
0
 public override bool ParseBoolean(RCLexer lexer, RCToken token)
 {
     return(bool.Parse(token.Text));
 }
Пример #25
0
 public virtual bool ParseBoolean(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "bool"));
 }
Пример #26
0
 public virtual RCSymbolScalar ParseSymbol(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "symbol"));
 }
Пример #27
0
 public override object Parse(RCLexer lexer, RCToken token)
 {
     return(ParseTime(lexer, token));
 }
Пример #28
0
 public virtual RCBlock ParseLink(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "link"));
 }
Пример #29
0
 public virtual int ParseInt(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "int"));
 }
Пример #30
0
 public override int ParseInt(RCLexer lexer, RCToken token)
 {
     return(int.Parse(ExtractNumber(token)));
 }