Token id, iprop; // id is the current ID for the current line /// <summary> /// Create a new iCalendar parser. /// </summary> /// <param name="reader">The reader that contains the stream of text iCalendar</param> /// <param name="_emitter">The emitter that will transform the iCalendar elements</param> public Parser(TextReader reader, IEmitter _emitter) { scanner = new Scanner(reader); emitter = _emitter; emitter.VParser = this; errors = new ArrayList(); }
/// <summary> /// Parse the list of attributes - separated by ';'s. Attributes always are in the /// form 'id=value' and indicate key/value pairs in the iCalendar attribute format. /// </summary> /// <returns></returns> protected virtual bool parseAttributes(Scanner scan) { Token key = scan.GetNextToken(ScannerState.ParseKey); if (key == null || key.TokenVal == TokenValue.Error) { // some kind of error - skip rest of line and continue if (key == null) reportError(scanner, " expecting ID - found nothing."); else reportError(scanner, " expecting ID - found " + key.TokenText); return false; } Token sep = scan.GetNextToken(ScannerState.ParseSimple); if (sep == null || sep.TokenVal == TokenValue.Error || sep.TokenVal != TokenValue.Equals) { // some kind of error - skip rest of line and continue if (sep == null) reportError(scanner, " expecting = - found nothing."); else reportError(scanner, " expecting = - found " + sep.TokenText); return false; } Token val = scan.GetNextToken(ScannerState.ParseParms); if (val == null || val.TokenVal == TokenValue.Error) { // some kind of error - skip rest of line and continue if (val == null) reportError(scanner, " expecting parameter - found nothing."); else reportError(scanner, " expecting parameter - found " + val.TokenText); return false; } if (key.TokenVal == TokenValue.Tvalue && scanner == scan) { // it's an IPROP - don't ask... iprop = val; } else { attributes.Push(new DictionaryEntry(key, val)); } // do a recursive case to identify all of the attributes sep = scan.GetNextToken(ScannerState.ParseSimple); if (sep == null || sep.TokenVal == TokenValue.Error) { // if we are parsing an rrule - this is the line termination if (scanner != scan) { return true; } // some kind of error - skip rest of line and continue if (sep == null) reportError(scanner, " expecting : or ; - found nothing."); else reportError(scanner, " expecting : or ; - found " + sep.TokenText); return false; } if (sep.TokenVal == TokenValue.Colon) { // termination case return true; } else if (sep.TokenVal == TokenValue.SemiColon) { // recursive case return parseAttributes(scan); } return true; }
protected void reportFatalError(Scanner s, string msg) { s.ConsumeToEOL(); //Console.Error.WriteLine( "Found a fatal error on line " + linenumber + " : " + msg ); errors.Add(new ParserError(linenumber, msg)); }
internal Enumerator(Scanner _scanner) { scanner = _scanner; current = null; }