public bool MoveNext() { current = scanner.GetNextToken(); return(current != null); }
/// <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); }
/// <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; }
/// <summary> /// Alternate entry point for starting the parser. /// </summary> /// <param name="emitHandT">Indicates if the emitter should be told to emit headers /// and trailers before and after emitting the iCalendar body</param> public void Parse(bool emitHandT) { buff = new StringBuilder(); stack = new Stack(); linenumber = 0; attributes = new Stack(); // a stack of key-value pairs (implemented as a stack of DitionaryEntry) if (emitHandT) { emitter.doIntro(); } // each time through the loop will get a single (maybe folded) line while (true) { // check for termination condition if (scanner.isEOF()) { // end of file - do cleanup and go break; } // empty the attribute stack and the iprop value... attributes.Clear(); iprop = null; id = null; //FIXME: linenumber doesn't really keep track of actual line numbers because // it is not aware of folded lines... linenumber++; //DEBUG: emit line number //emitter.emit( linenumber + ". " ); if (!parseID()) { continue; } // we now have to parse a set of attributes (semi-colon separated) or // a value (delimited by a colon) Token sep = scanner.GetNextToken(ScannerState.ParseSimple); if (sep == null || sep.TokenVal == TokenValue.Error) { // some kind of error - skip rest of line and continue reportError(scanner, " expecting : or ; after id - found nothing."); continue; } else if (sep.TokenVal == TokenValue.SemiColon) { if (!parseAttributes(scanner)) { continue; } // now we have to parse the value sep = scanner.GetNextToken(ScannerState.ParseSimple); if (!parseValue()) { continue; } } else if (sep.TokenVal == TokenValue.Colon) { if (!parseValue()) { continue; } } else { reportError(scanner, "expecting : or ; after id - found: " + sep.TokenText); continue; } // now sploosh out the attributes (if any) and finish the ID tag while (attributes.Count > 0) { DictionaryEntry entry = (DictionaryEntry)attributes.Pop(); Token key = (Token)entry.Key; Token val = (Token)entry.Value; emitter.doAttribute(key, val); } emitter.doEnd(id); } if (emitHandT) { emitter.doOutro(); } }