def build_valid_keywords_grammar(keywords=None):
    """Update parser grammar to add a list of allowed keywords."""
    from invenio_query_parser.parser import KeywordQuery, KeywordRule, \
        NotKeywordValue, SimpleQuery, ValueQuery

    if keywords:
        KeywordRule.grammar = attr('value', re.compile(
            r"(\d\d\d\w{{0,3}}|{0})\b".format("|".join(keywords), re.I)))

        NotKeywordValue.grammar = attr('value', re.compile(
            r'\b(?!\d\d\d\w{{0,3}}|{0}:)\S+\b:'.format(
                ":|".join(keywords))))

        SimpleQuery.grammar = attr(
            'op', [NotKeywordValue, KeywordQuery, ValueQuery])
    else:
        KeywordRule.grammar = attr('value', re.compile(r"[\w\d]+(\.[\w\d]+)*"))
        SimpleQuery.grammar = attr('op', [KeywordQuery, ValueQuery])
Update parser grammar to add a list of allowed keywords.