Example #1
0
        private static void GetTagsDictionary()
        {
            var path = Settings.Default.SavePath + Settings.Default.KnownTagsFileName + ".txt";

            if (!File.Exists(path))
            {
                return;
            }

            var lines = File.ReadAllLines(path);

            foreach (var line in lines)
            {
                var x = line.Split(";");

                if (x.Length < 2)
                {
                    continue;
                }

                var key = x[0].Normalize(NormalizationForm.FormKC).ToUpper();

                if (KnownTags.ContainsKey(key))
                {
                    continue;
                }

                KnownTags.Add(key, x[1]);
            }
        }
Example #2
0
        public void RegisterMetadata(string key, Value value, Item context)
        {
            if (CheckingStyle == JournalCheckingStyleEnum.CHECK_WARNING || CheckingStyle == JournalCheckingStyleEnum.CHECK_ERROR)
            {
                if (!KnownTags.Contains(key))
                {
                    if (context == null)
                    {
                        if (ForceChecking)
                        {
                            FixedMetadata = true;
                        }
                        KnownTags.Add(key);
                    }
                    else if (!FixedMetadata && context != null && context.State != ItemStateEnum.Uncleared)
                    {
                        KnownTags.Add(key);
                    }
                    else if (CheckingStyle == JournalCheckingStyleEnum.CHECK_WARNING)
                    {
                        CurrentContext.Warning(String.Format("Unknown metadata tag '{0}'", key));
                    }
                    else if (CheckingStyle == JournalCheckingStyleEnum.CHECK_ERROR)
                    {
                        throw new ParseError(String.Format("Unknown metadata tag '{0}'", key));
                    }
                }
            }

            if (!Value.IsNullOrEmpty(value))
            {
                foreach (CheckExprPair pair in TagCheckExprsMap.GetValues(key))
                {
                    BindScope  boundScope = new BindScope(CurrentContext.Scope, context);
                    ValueScope valScope   = new ValueScope(boundScope, value);

                    if (!pair.Expr.Calc(valScope).AsBoolean)
                    {
                        if (pair.CheckExprKind == CheckExprKindEnum.EXPR_ASSERTION)
                        {
                            throw new ParseError(String.Format(ParseError.ParseError_MetadataAssertionFailedFor, key, value, pair.Expr));
                        }
                        else
                        {
                            CurrentContext.Warning(String.Format(ParseError.ParseError_MetadataCheckFailedFor, key, value, pair.Expr));
                        }
                    }
                }
            }
        }
        private void RemoveKeywords(Snippet snippet)
        {
            snippet.RemoveTags(Language.Types.Select(f => KnownTags.GenerateTypeTag(f.Name)));
            snippet.RemoveTags(Language.Modifiers.Select(f => KnownTags.GenerateModifierTag(f.Name)));

            snippet.RemoveTags(
                KnownTags.GenerateType,
                KnownTags.GenerateAccessModifier,
                KnownTags.GenerateInitializer,
                KnownTags.GenerateUnchanged,
                KnownTags.GenerateParameters,
                KnownTags.GenerateArguments,
                KnownTags.GenerateCollection,
                KnownTags.GenerateImmutableCollection,
                KnownTags.Array,
                KnownTags.Collection,
                KnownTags.Dictionary,
                KnownTags.TryParse,
                KnownTags.Initializer);
        }
 public LanguageSnippetGenerator(LanguageDefinition languageDefinition)
 {
     LanguageDefinition    = languageDefinition;
     _generateTypeTags     = LanguageDefinition.Types.Select(f => KnownTags.GenerateTypeTag(f.Name)).ToArray();
     _generateModifierTags = LanguageDefinition.Modifiers.Select(f => KnownTags.GenerateModifierTag(f.Name)).ToArray();
 }