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)); }
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)); } }
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); }
static CSVParser() { RCArray <RCTokenType> types = new RCArray <RCTokenType> (); types.Write(RCTokenType.CSVSeparator); types.Write(RCTokenType.CSVContent); _csvLexer = new RCLexer(types); }
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); }
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, '"')); } }
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); }
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); }
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); }
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); } }
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); } } }
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); }
public virtual RCTimeScalar ParseTime(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "time")); }
public virtual RCIncrScalar ParseIncr(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "incr")); }
public virtual byte ParseByte(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "byte")); }
public override RCTimeScalar ParseTime(RCLexer lexer, RCToken token) { return(ParseTime(token.Text)); }
public override long ParseLong(RCLexer lexer, RCToken token) { return(long.Parse(ExtractNumber(token))); }
public abstract void AcceptScalar(object state, RCToken token, RCLexer lexer);
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; } }
public virtual float ParseFloat(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "double")); }
public virtual decimal ParseDecimal(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "decimal")); }
public virtual long ParseLong(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "long")); }
public virtual object Parse(RCLexer lexer, RCToken token) { throw new Exception("cannot use " + Name + " as a symbol or within a cube"); }
public override bool ParseBoolean(RCLexer lexer, RCToken token) { return(bool.Parse(token.Text)); }
public virtual bool ParseBoolean(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "bool")); }
public virtual RCSymbolScalar ParseSymbol(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "symbol")); }
public override object Parse(RCLexer lexer, RCToken token) { return(ParseTime(lexer, token)); }
public virtual RCBlock ParseLink(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "link")); }
public virtual int ParseInt(RCLexer lexer, RCToken token) { throw new Exception(Message(token.Type.ToString(), token.Text, "int")); }
public override int ParseInt(RCLexer lexer, RCToken token) { return(int.Parse(ExtractNumber(token))); }