コード例 #1
0
        // reads a STON address initial context
        private IStonInitialContext ReadInitialContext(StonTokenReader reader)
        {
            int addressOpen = reader.ExpectChartype(StonChartype.AddressBegin);

            // reference defining context
            if (addressOpen == '$')
            {
                reader.PeekSignificant();
                return(ElementFactory.CreateAncestorInitialContext(0));
            }
            else if (addressOpen == '^')
            {
                // document core
                if (reader.Peek() == '*')
                {
                    reader.ReadAndSkip();
                    return(ElementFactory.CreateGlobalEntityInitialContext(""));
                }
                // reference defining context ancestor
                else
                {
                    int ancestorOrder = 1;
                    reader.PeekSignificant();
                    while (reader.TryAndSkip(StonChartype.AncestorAccess))
                    {
                        ++ancestorOrder;
                    }
                    return(ElementFactory.CreateAncestorInitialContext(ancestorOrder));
                }
            }
            // globally identified entity
            else
            {
                reader.PeekSignificant();
                string globalIdentifier = reader.ReadCanun();
                return(ElementFactory.CreateGlobalEntityInitialContext(globalIdentifier));
            }
        }