コード例 #1
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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);
         }
     }
 }
コード例 #2
0
 public void doEnd(Token t) { }
コード例 #3
0
 public void doBegin(Token t) { }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        } 
コード例 #6
0
 public void doSymbolic(Token t) { }
コード例 #7
0
 public void doURIResource(Token t) { }
コード例 #8
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 public void doURIResource(Token t)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(t.TokenText), true));
 }
コード例 #9
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
        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
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 public void doResourceBegin(Token t)
 {
     Push(new StackElem(t, NewGuid(), true));
 }
コード例 #15
0
 public void doEndComponent() 
 {
     // Console.WriteLine(mComponentToken.TokenText);
     mComponentToken = null;
 }
コード例 #16
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
        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);
        }
コード例 #17
0
 public void doID(Token t)
 {
     mIdToken = t;
 }
コード例 #18
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 public void doIprop(Token t, Token iprop)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, NS(iprop.TokenText), true));
 }
コード例 #19
0
 public void doResource(Token t) { } 
コード例 #20
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 public void doRest(Token t, Token id)
 {
     StackElem elem = Pop();
     accumulator.Add(new Triple(NS(elem.id.TokenText), Peek().guid, t.TokenText, false));
 }
コード例 #21
0
 public void doMailto(Token t) { }
コード例 #22
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 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));
 }
コード例 #23
0
 public void doIprop(Token t, Token iprop) { }
コード例 #24
0
ファイル: TripleEmitter.cs プロジェクト: dblock/sncore
 public StackElem(Token _id, string _guid, bool _predFlag)
 {
     id = _id;
     guid = _guid;
     predFlag = _predFlag;
 }
コード例 #25
0
 public void doAttribute(Token key, Token val) { }
コード例 #26
0
ファイル: Parser.cs プロジェクト: dblock/sncore
        /// <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();
            }
        }
コード例 #27
0
 public void doResourceBegin(Token t) { }
コード例 #28
0
ファイル: Parser.cs プロジェクト: dblock/sncore
        /// <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;
        }
コード例 #29
0
 public void doComponentBegin(Token t)
 {
     mComponentToken = t;
     // Console.WriteLine(t.TokenText);
 }
コード例 #30
0
ファイル: Scanner.cs プロジェクト: dblock/sncore
 public bool MoveNext()
 {
     current = scanner.GetNextToken();
     return current != null;
 }