コード例 #1
0
        public override void AddField(TextSpan field)
        {
            if (!field.StartsWith("PRE"))
            {
                if (field.TryRemovePrefix("TYPE=", out var type) ||
                    field.TryRemovePrefix("!TYPE=", out type))
                {
                    var types    = type.Value.Split('.');
                    var selector = string.Join(" or ", types.Select(t => $"language.IsType(\"{t}\")"));
                    if (field.StartsWith("!"))
                    {
                        selector = $"not ({selector})";
                    }
                    Selectors.Add(selector);
                }
                else if (field.Value == "ALL")
                {
                    Selectors.Add("true");
                }
                else
                {
                    Selectors.Add($"stringMatch(language.Name, \"{field.Value}\")");
                }

                return;
            }
            base.AddField(field);
        }
コード例 #2
0
        public override void AddField(TextSpan field)
        {
            if (Category == null)
            {
                Category = field.Value;
                return;
            }

            if (Nature == null)
            {
                Nature = field.Value;
                return;
            }

            if (!field.StartsWith("PRE") && !field.StartsWith("!PRE"))
            {
                if (field.TryRemovePrefix("TYPE=", out field))
                {
                    Types.Add(field.Value);
                    return;
                }

                Names.Add(field.Value);
                return;
            }
            base.AddField(field);
        }
コード例 #3
0
        public virtual void AddField(TextSpan field)
        {
            foreach (var def in GetPropertyDefinitions())
            {
                if (def(field, _properties, _clear))
                {
                    return;
                }
            }

            if (field.StartsWith("TEMPVALUE:") || field.StartsWith("MODIFY:FACE"))
            {
                // TODO: These are undocumented
                return;
            }

            UnknownField(field);
        }
コード例 #4
0
        public static bool TryParse(TextSpan field, [NotNullWhen(true)] out AutomaticLanguage?result)
        {
            if (!field.StartsWith("AUTO:LANG|"))
            {
                result = null;
                return(false);
            }

            var value = field.Substring("AUTO:LANG|".Length);
            var parts = value.Split('|').ToArray();

            Helpers.CheckForMODorCOPYorCLEAR(parts[0]);

            var    firstPart = parts[0];
            string?name      = null;
            string?type      = null;
            bool   invert    = false;
            bool   all       = false;

            if (firstPart.StartsWith("TYPE="))
            {
                type = firstPart.Substring("TYPE=".Length).Value;
            }
            else if (firstPart.StartsWith("!TYPE="))
            {
                type   = firstPart.Substring("!TYPE=".Length).Value;
                invert = true;
            }
            else if (firstPart.Value == "ALL")
            {
                all = true;
            }
            else
            {
                name = firstPart.Value;
            }

            var conditions = new List <Condition>();

            foreach (var part in parts.Skip(1))
            {
                if (!Condition.TryParse(part, out Condition? condition))
                {
                    throw new ParseFailedException(part, "Unable to parse Condition.");
                }
                conditions.Add(condition);
            }

            result = new AutomaticLanguage(conditions, name, type, invert, all);
            return(true);
        }