Esempio n. 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));
        }
Esempio n. 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));
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        static CSVParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.CSVContent);
            _csvLexer = new RCLexer(types);
        }
Esempio n. 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);
        }
Esempio n. 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, '"'));
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
     }
 }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 13
0
 public virtual RCTimeScalar ParseTime(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "time"));
 }
Esempio n. 14
0
 public virtual RCIncrScalar ParseIncr(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "incr"));
 }
Esempio n. 15
0
 public virtual byte ParseByte(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "byte"));
 }
Esempio n. 16
0
 public override RCTimeScalar ParseTime(RCLexer lexer, RCToken token)
 {
     return(ParseTime(token.Text));
 }
Esempio n. 17
0
 public override long ParseLong(RCLexer lexer, RCToken token)
 {
     return(long.Parse(ExtractNumber(token)));
 }
Esempio n. 18
0
 public abstract void AcceptScalar(object state, RCToken token, RCLexer lexer);
Esempio n. 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;
            }
        }
Esempio n. 20
0
 public virtual float ParseFloat(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "double"));
 }
Esempio n. 21
0
 public virtual decimal ParseDecimal(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "decimal"));
 }
Esempio n. 22
0
 public virtual long ParseLong(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "long"));
 }
Esempio n. 23
0
 public virtual object Parse(RCLexer lexer, RCToken token)
 {
     throw new Exception("cannot use " + Name + " as a symbol or within a cube");
 }
Esempio n. 24
0
 public override bool ParseBoolean(RCLexer lexer, RCToken token)
 {
     return(bool.Parse(token.Text));
 }
Esempio n. 25
0
 public virtual bool ParseBoolean(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "bool"));
 }
Esempio n. 26
0
 public virtual RCSymbolScalar ParseSymbol(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "symbol"));
 }
Esempio n. 27
0
 public override object Parse(RCLexer lexer, RCToken token)
 {
     return(ParseTime(lexer, token));
 }
Esempio n. 28
0
 public virtual RCBlock ParseLink(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "link"));
 }
Esempio n. 29
0
 public virtual int ParseInt(RCLexer lexer, RCToken token)
 {
     throw new Exception(Message(token.Type.ToString(), token.Text, "int"));
 }
Esempio n. 30
0
 public override int ParseInt(RCLexer lexer, RCToken token)
 {
     return(int.Parse(ExtractNumber(token)));
 }