Example #1
0
        /// <summary>
        /// Parse directives.
        /// </summary>
        private VersionDirective ProcessDirectives(TagDirectiveCollection tags)
        {
            VersionDirective version = null;

            while (true)
            {
                VersionDirective currentVersion;
                TagDirective     tag;

                if ((currentVersion = GetCurrentToken() as VersionDirective) != null)
                {
                    if (version != null)
                    {
                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found duplicate %YAML directive.");
                    }

                    if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)
                    {
                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found incompatible YAML document.");
                    }

                    version = currentVersion;
                }
                else if ((tag = GetCurrentToken() as TagDirective) != null)
                {
                    if (tagDirectives.Contains(tag.Handle))
                    {
                        throw new SemanticErrorException(tag.Start, tag.End, "Found duplicate %TAG directive.");
                    }
                    tagDirectives.Add(tag);
                    if (tags != null)
                    {
                        tags.Add(tag);
                    }
                }
                else
                {
                    break;
                }

                Skip();
            }

            if (tags != null)
            {
                AddDefaultTagDirectives(tags);
            }
            AddDefaultTagDirectives(tagDirectives);

            return(version);
        }
Example #2
0
 private static void AddDefaultTagDirectives(TagDirectiveCollection directives)
 {
     foreach (var directive in Constants.DefaultTagDirectives)
     {
         if (!directives.Contains(directive))
         {
             directives.Add(directive);
         }
     }
 }