コード例 #1
0
        private Message ParseIdentifier(Lexer lexer, Token.Identifier identifier)
        {
            var match = Regex.Match((string)identifier, @"^msg(id|id_plural|str|str\[(\d+)\]|ctxt)$");

            if (!match.Success)
            {
                throw new SyntaxException(lexer, "invalid identifier: " + (string)identifier);
            }

            int         plural_order;
            MessageType type;

            switch (match.Groups [1].Value)
            {
            case "id":
                type         = MessageType.SingularIdentifier;
                plural_order = -1;
                break;

            case "id_plural":
                type         = MessageType.PluralIdentifier;
                plural_order = -1;
                break;

            case "str":
                type         = MessageType.SingularString;
                plural_order = 0;
                break;

            case "ctxt":
                type         = MessageType.Context;
                plural_order = -1;
                break;

            default:
                if (match.Groups.Count == 3)
                {
                    type         = MessageType.PluralString;
                    plural_order = Int32.Parse(match.Groups [2].Value);
                }
                else
                {
                    throw new SyntaxException(lexer, "invalid identifier: " + (string)identifier);
                }
                break;
            }

            return(new Message(identifier, type, plural_order));
        }
コード例 #2
0
ファイル: ParseUtil.cs プロジェクト: ugurak/nemerle
        public static bool IsQuotationWithHeader(Token.QuoteGroup group, out Token.Identifier type, out Token.Operator colon, out Token body)
        {
            var content = group.Child as Token.LooseGroup;

            if (content != null)
            {
                var _type = content.Child as Token.Identifier;
                if (_type != null && _quotationTypes.Contains(_type.name))
                {
                    var _colon = _type.Next as Token.Operator;
                    if (_colon != null && string.Equals(_colon.name, ":", StringComparison.InvariantCulture))
                    {
                        type  = _type;
                        colon = _colon;
                        body  = _colon.Next;
                        return(true);
                    }
                }
            }
            type  = null;
            colon = null;
            body  = null;
            return(false);
        }