Пример #1
0
 public void doEnd(Token t)
 {
     StackElem pred = Pop();
     if (pred.predFlag)
     {
         if (Count > 0)
         {
             accumulator.Add(new Triple(NS(pred.id.TokenText), Peek().guid, pred.guid, true));
         }
         else
         {
             throw new Exception("Problem parsing: expecting overriding resource for: " + t.TokenText);
         }
     }
 }
 public void doEnd(Token t) { }
 public void doBegin(Token t) { }
        public void doValueProperty(Token t, Token iprop) 
        {
            if (mComponentToken == null)
                return;

            switch (mComponentToken.TokenText)
            {
                case "Vevent":

                    if (mAccountEvent == null || mIdToken == null || mSchedule == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", t.TokenText));

                    switch (mIdToken.TokenText)
                    {
                        case "dtstart":
                            mSchedule.StartDateTime = mAccountEvent.StartDateTime = DateTime.Parse(
                                Token.ParseDateTime(t.TokenText)).Add(-UtcOffset);
                            mSchedule.EndDateTime = mAccountEvent.EndDateTime = mAccountEvent.StartDateTime.AddHours(1);
                            break;
                        case "dtend":
                            mSchedule.EndDateTime = mAccountEvent.EndDateTime = DateTime.Parse(
                                Token.ParseDateTime(t.TokenText)).Add(-UtcOffset);
                            break;
                    }

                    break;            
            }
        
            // Console.WriteLine(mIdToken.TokenText  + ": "  + t.TokenText);
        }
        public void doRest(Token t, Token id) 
        {
            if (mComponentToken == null)
                return;

            switch (mComponentToken.TokenText)
            {
                case "Vevent":
                    
                    if (mAccountEvent == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", id.TokenText));

                    switch (id.TokenText)
                    {
                        case "summary":
                            mAccountEvent.Name = t.TokenText;
                            break;
                        case "description":
                            mAccountEvent.Description = t.TokenText;
                            break;
                        case "url":
                            mAccountEvent.Website = t.TokenText;
                            break;
                    }

                    break;

                case "Vvenue":

                    if (mAccountEvent == null || mPlace == null)
                        throw new Exception(string.Format(
                            "Unexpected {0}", id.TokenText));

                    switch (id.TokenText)
                    {
                        case "name":
                            mPlace.Name = mAccountEvent.PlaceName = t.TokenText;
                            break;
                        case "address":
                            mPlace.Street = t.TokenText;
                            break;
                        case "city":
                            mPlace.City = mAccountEvent.PlaceCity = t.TokenText;
                            break;
                        case "region":
                            mPlace.State = mAccountEvent.PlaceState = t.TokenText;
                            break;
                        case "country":
                            mPlace.Country = mAccountEvent.PlaceCountry = t.TokenText;
                            break;
                        case "postalcode":
                            mPlace.Zip = t.TokenText;
                            break;
                    }

                    break;
            }

            // Console.WriteLine("\t" + id.TokenText + "=>" + t.TokenText);
        } 
 public void doSymbolic(Token t) { }
 public void doURIResource(Token t) { }
Пример #8
0
 public void doURIResource(Token t)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(t.TokenText), true));
 }
Пример #9
0
 public void doMailto(Token t)
 {
     StackElem elem = Pop();
     elem.guid = NewGuid();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, elem.guid, true));
     accumulator.Add(new Triple(NS("calAddress"), elem.guid, NS(t.TokenText), true));
     Push(elem);
 }
Пример #10
0
 public void doID(Token t)
 {
     StackElem elem = new StackElem(t, null, false);  // the rest of the methods will fill in this properly
     Push(elem);
 }
Пример #11
0
 public void doSymbolic(Token t)
 {
     //TODO: url encoding
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(Token.CamelCase(t.TokenText.ToLower())), true));
 }
Пример #12
0
 public void doBegin(Token t)
 {
     // this indicates the beginning of a property describing the resource on the top of the stack
     Push(new StackElem(t, null, true));
 }
Пример #13
0
        public void doComponentBegin(Token t)
        {
            // beginning of a rdfType for this stmt - ie. it's a new resource
            string guid = NewGuid();
            StackElem elem = new StackElem(t, guid, false);

            if (Count > 0 && Peek().predFlag)
            {
                StackElem top = Peek();
                top.guid = guid;
            }
            Push(elem);

            accumulator.Add(new Triple(RDF("type"), guid, NS(t.TokenText), true));
        }
Пример #14
0
 public void doResourceBegin(Token t)
 {
     Push(new StackElem(t, NewGuid(), true));
 }
 public void doEndComponent() 
 {
     // Console.WriteLine(mComponentToken.TokenText);
     mComponentToken = null;
 }
Пример #16
0
        public void doValueProperty(Token t, Token iprop)
        {
            StackElem elem = Pop();
            elem.guid = NewGuid();
            accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, elem.guid, true));

            if (iprop != null)
            {
                string tag = NS(Token.CamelCase(iprop.TokenText.ToLower()));
                string lprop = Token.CamelCase(iprop.TokenText.ToLower());
                string lobj;
                if (lprop == "date")
                {
                    lobj = Token.ParseDate(t.TokenText);
                }
                else
                {
                    lobj = Token.CamelCase(t.TokenText.ToLower());
                }
                accumulator.Add(new Triple(tag, elem.guid, lobj, false));
            }
            else
            {
                accumulator.Add(new Triple(NS("dateTime"), elem.guid, Token.ParseDateTime(t.TokenText), false));
            }
            Push(elem);
        }
 public void doID(Token t)
 {
     mIdToken = t;
 }
Пример #18
0
 public void doIprop(Token t, Token iprop)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(iprop.TokenText), true));
 }
 public void doResource(Token t) { } 
Пример #20
0
 public void doRest(Token t, Token id)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, t.TokenText, false));
 }
 public void doMailto(Token t) { }
Пример #22
0
 public void doAttribute(Token key, Token val)
 {
     string actual;
     if (key.TokenText == "until")
     {
         actual = Token.ParseDateTime(val.TokenText);
     }
     else
     {
         actual = val.TokenText;
     }
     accumulator.Add(new Triple(NS(key.TokenText), Peek().guid, actual, false));
 }
 public void doIprop(Token t, Token iprop) { }
Пример #24
0
 public StackElem(Token _id, string _guid, bool _predFlag)
 {
     id = _id;
     guid = _guid;
     predFlag = _predFlag;
 }
 public void doAttribute(Token key, Token val) { }
Пример #26
0
        /// <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();
            }
        }
 public void doResourceBegin(Token t) { }
Пример #28
0
        /// <summary>
        /// Parse the first field (ID) of the line.  Returns a boolean on weather or not the
        /// method sucesfully recognized an ID.  If not, the method insures that the scanner
        /// will start at the beginning of a new line.
        /// </summary>
        /// <returns></returns>
        protected virtual bool parseID()
        {
            Token t;  // re-usable token variable
            id = scanner.GetNextToken(ScannerState.ParseID);
            if (id == null || id.TokenVal == TokenValue.Error)
            {
                // some kind of error - skip rest of line and continue
                reportError(scanner, "expecting ID - found nothing.");
                return false;
            }

            switch (id.TokenVal)
            {
                case TokenValue.Tbegin:
                    t = scanner.GetNextToken(ScannerState.ParseSimple);
                    if (t == null || t.isError() || t.TokenVal != TokenValue.Colon)
                    {
                        if (t == null)
                            reportError(scanner, " expecting : - found nothing.");
                        else
                            reportError(scanner, " expecting : - found " + t.TokenText);
                        return false;
                    }

                    t = scanner.GetNextToken(ScannerState.ParseID);
                    if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty()))
                    {
                        if (t == null)
                            reportError(scanner, " expecting a valid beginend value - found nothing.");
                        else
                            reportError(scanner, " expecting a valid beginend value - found " + t.TokenText);
                        return false;
                    }

                    // check for the different types of begin tags
                    if (t.isResourceProperty())
                    {
                        emitter.doResourceBegin(t);
                    }
                    else if (t.isComponent())
                    {
                        emitter.doComponent();
                        emitter.doComponentBegin(t);
                    }
                    else if (t.TokenVal == TokenValue.Tvcalendar)
                    {
                        emitter.doComponentBegin(t);
                    }
                    else
                    {
                        emitter.doBegin(t);
                    }
                    stack.Push(t);  // to match up to the corresponding end value
                    //scanner.ConsumeToEOL();
                    return false;

                case TokenValue.Tend:
                    t = scanner.GetNextToken(ScannerState.ParseSimple);
                    if (t == null || t.isError() || t.TokenVal != TokenValue.Colon)
                    {
                        if (t == null)
                            reportError(scanner, " expecting : - found nothing.");
                        else
                            reportError(scanner, " expecting : - found " + t.TokenText);
                        return false;
                    }

                    t = scanner.GetNextToken(ScannerState.ParseID);
                    if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty()))
                    {
                        if (t == null)
                            reportError(scanner, " expecting a valid beginend value - found nothing.");
                        else
                            reportError(scanner, " expecting a valid beginend value - found " + t.TokenText);
                        return false;
                    }

                    // the end is easier - ignore the last one...  
                    if (stack.Count != 0)
                    {
                        emitter.doEnd(t);
                        if (t.isComponent())
                        {
                            emitter.doEndComponent();
                        }
                        stack.Pop();
                    }
                    else
                    {
                        reportError(scanner, "stack stuff is weird - probably illformed .ics file - parsing " + id.TokenText);
                    }
                    //scanner.ConsumeToEOL();
                    return false;

                case TokenValue.Trrule:
                    emitter.doResourceBegin(id);
                    break;

                default:
                    emitter.doID(id);
                    break;
            }
            return true;
        }
 public void doComponentBegin(Token t)
 {
     mComponentToken = t;
     // Console.WriteLine(t.TokenText);
 }
Пример #30
0
 public bool MoveNext()
 {
     current = scanner.GetNextToken();
     return current != null;
 }