Ejemplo n.º 1
0
        private Property EventPropertyAtomic()
        {
            if (lookahead.token != TokenType.IDENT && lookahead.token != TokenType.IDENTESCAPED) {
                ExpectOrFail(TokenType.IDENT);
            }

            string ident;
            if (lookahead.token == TokenType.IDENT) {
                ident = ProcessIdent(lookahead.sequence);
            }
            else {
                ident = ProcessIdent(PropertyParser.UnescapeBacktickForProperty(lookahead.sequence));
            }

            NextToken();

            if (lookahead.token == TokenType.LBRACK) {
                NextToken();
                ExpectOrFail(TokenType.LBRACK, TokenType.NUMBER);

                var index = int.Parse(lookahead.sequence);
                NextToken();

                ExpectOrFail(TokenType.NUMBER, TokenType.RBRACK);
                NextToken();

                if (lookahead.token == TokenType.QUESTION) {
                    NextToken();
                    return new DynamicIndexedProperty(ident, index);
                }

                if (dynamic) {
                    return new DynamicIndexedProperty(ident, index);
                }

                return new IndexedProperty(ident, index);
            }

            if (lookahead.token == TokenType.LPAREN) {
                NextToken();

                if (lookahead.token == TokenType.DOUBLEQUOTEDLITERAL ||
                    lookahead.token == TokenType.SINGLEQUOTEDLITERAL) {
                    var type = lookahead.token;
                    var value = lookahead.sequence.Trim();
                    var key = value.Substring(1, value.Length - 2);
                    NextToken();

                    ExpectOrFail(type, TokenType.RPAREN);
                    NextToken();

                    if (lookahead.token == TokenType.QUESTION) {
                        NextToken();
                        return new DynamicMappedProperty(ident, key);
                    }

                    if (dynamic) {
                        return new DynamicMappedProperty(ident, key);
                    }

                    return new MappedProperty(ident, key);
                }

                ExpectOrFail(TokenType.LPAREN, TokenType.DOUBLEQUOTEDLITERAL);
            }

            if (lookahead.token == TokenType.QUESTION) {
                NextToken();
                dynamic = true;
                return new DynamicSimpleProperty(ident);
            }

            if (dynamic) {
                return new DynamicSimpleProperty(ident);
            }

            return new SimpleProperty(ident);
        }