src/main/java/br/com/starcode/parccser/Parser.java
protected AttributeSelector attribute() throws ParserException {

    	int initialPos = pos;
        StringBuilder sb = new StringBuilder();
        ignoreWhitespaces();
        String name = !end() ? identifier() : null;
        if (name == null || name.isEmpty()) {
            throw new ParserException("Expected attribute name at position " + pos);
        }
        sb.append(name);
        ignoreWhitespaces();
        if (end()) {
            throw new ParserException("Unexpected end of selector selector at position " + pos);
        }
        AttributeOperator operator = null;
        if (current == '=') {
            operator = AttributeOperator.EQUALS;
            next();
        } else if (current != ']') {
            if (current == '~') operator = AttributeOperator.INCLUDES;
            else if (current == '|') operator = AttributeOperator.DASH_MATCH;
            else if (current == '^') operator = AttributeOperator.PREFIX_MATCH;
            else if (current == '$') operator = AttributeOperator.SUFFIX_MATCH;
            else if (current == '*') operator = AttributeOperator.SUBSTRING_MATCH;
            else throw new ParserException("Invalid operator ('" + current + "') at position " + pos);
            next();
            if (end() || current != '=') {
                throw new ParserException("Expected '=' sign at position " + pos);
            }
            next();
        }

        ignoreWhitespaces();
        if (end()) {
            throw new ParserException("Unexpected end of attribute selector at position " + pos);
        }

        //value
        StringValue value = null;
        if (operator != null) {
            sb.append(operator.getSign());
            if (current == '\'' || current == '"') {
                char quote = current;
                value = string();
                sb.append(quote);
                sb.append(value.getContext().toString());
                sb.append(quote);
            } else {
            	int identPos = pos;
                String ident = identifier();
                value = new StringValue(new Context(content, ident, identPos, pos), ident);
                sb.append(value);
            }
        }

        ignoreWhitespaces();

        //end of attribute
        if (end() || current != ']') {
            throw new ParserException("Token ']' expected at position " + pos);
        }
        int endPos = pos;
        next();

        return new AttributeSelector(name, operator, value, new Context(content, sb.toString(), initialPos, endPos));

    }
protected AttributeSelector attribute() throws ParserException {

    	int initialPos = pos;
        StringBuilder sb = new StringBuilder();
        ignoreWhitespaces();
        String name = !end() ? identifier() : null;
        if (name == null || name.isEmpty()) {
            throw new ParserException("Expected attribute name at position " + pos);
        }
        sb.append(name);
        ignoreWhitespaces();
        if (end()) {
            throw new ParserException("Unexpected end of selector selector at position " + pos);
        }
        AttributeOperator operator = null;
        if (current == '=') {
            operator = AttributeOperator.EQUALS;
            next();
        } else if (current != ']') {
            if (current == '~') operator = AttributeOperator.INCLUDES;
            else if (current == '|') operator = AttributeOperator.DASH_MATCH;
            else if (current == '^') operator = AttributeOperator.PREFIX_MATCH;
            else if (current == '$') operator = AttributeOperator.SUFFIX_MATCH;
            else if (current == '*') operator = AttributeOperator.SUBSTRING_MATCH;
            else throw new ParserException("Invalid operator ('" + current + "') at position " + pos);
            next();
            if (end() || current != '=') {
                throw new ParserException("Expected '=' sign at position " + pos);
            }
            next();
        }

        ignoreWhitespaces();
        if (end()) {
            throw new ParserException("Unexpected end of attribute selector at position " + pos);
        }

        //value
        StringValue value = null;
        if (operator != null) {
            sb.append(operator.getSign());
            if (current == '\'' || current == '"') {
                char quote = current;
                value = string();
                sb.append(quote);
                sb.append(value.getContext().toString());
                sb.append(quote);
            } else {
            	int identPos = pos;
                String ident = identifier();
                value = new StringValue(new Context(content, ident, identPos, pos), ident);
                sb.append(value);
            }
        }

        ignoreWhitespaces();

        //end of attribute
        if (end() || current != ']') {
            throw new ParserException("Token ']' expected at position " + pos);
        }
        int endPos = pos;
        next();

        return new AttributeSelector(name, operator, value, new Context(content, sb.toString(), initialPos, endPos));

    }
protected AttributeSelector attribute ( ) throws ParserException { int initialPos = pos ; StringBuilder sb = new StringBuilder ( ) ; ignoreWhitespaces ( ) ; String name = ! end ( ) ? identifier ( ) : null ; if ( name == null || name . isEmpty ( ) ) { throw new ParserException ( "Expected attribute name at position " + pos ) ; } sb . append ( name ) ; ignoreWhitespaces ( ) ; if ( end ( ) ) { throw new ParserException ( "Unexpected end of selector selector at position " + pos ) ; } AttributeOperator operator = null ; if ( current == ' ' ) { operator = AttributeOperator . EQUALS ; next ( ) ; } else if ( current != ' ' ) { if ( current == ' ' ) operator = AttributeOperator . INCLUDES ; else if ( current == ' ' ) operator = AttributeOperator . DASH_MATCH ; else if ( current == ' ' ) operator = AttributeOperator . PREFIX_MATCH ; else if ( current == ' ' ) operator = AttributeOperator . SUFFIX_MATCH ; else if ( current == ' ' ) operator = AttributeOperator . SUBSTRING_MATCH ; else throw new ParserException ( "Invalid operator ('" + current + "') at position " + pos ) ; next ( ) ; if ( end ( ) || current != ' ' ) { throw new ParserException ( "Expected '=' sign at position " + pos ) ; } next ( ) ; } ignoreWhitespaces ( ) ; if ( end ( ) ) { throw new ParserException ( "Unexpected end of attribute selector at position " + pos ) ; } //value
 StringValue value = null ; if ( operator != null ) { sb . append ( operator . getSign ( ) ) ; if ( current == ' ' || current == ' ' ) { char quote = current ; value = string ( ) ; sb . append ( quote ) ; sb . append ( value . getContext ( ) . toString ( ) ) ; sb . append ( quote ) ; } else { int identPos = pos ; String ident = identifier ( ) ; value = new StringValue ( new Context ( content , ident , identPos , pos ) , ident ) ; sb . append ( value ) ; } } ignoreWhitespaces ( ) ; //end of attribute
 if ( end ( ) || current != ' ' ) { throw new ParserException ( "Token ']' expected at position " + pos ) ; } int endPos = pos ; next ( ) ; return new AttributeSelector ( name , operator , value , new Context ( content , sb . toString ( ) , initialPos , endPos ) ) ; }
attrib
: '[' S* [ namespace_prefix ]? IDENT S*
[ [ PREFIXMATCH |
SUFFIXMATCH |
SUBSTRINGMATCH |
'=' |
INCLUDES |
DASHMATCH ] S* [ IDENT | STRING ] S*
]? ']'
attrib : [ S * [ namespace_prefix ] ? IDENT S * [ [ PREFIXMATCH | SUFFIXMATCH | SUBSTRINGMATCH | = | INCLUDES | DASHMATCH ] S * [ IDENT | STRING ] S * ] ? ]