<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ANTLR Grammar Definition for Cassandra Query Language (CQL)
//
// CQL is a query language tailored for Cassandra's multi-level (or 
// nested-table like) data model where values stored for each key 
// can be:
//
//  * a simple column map (a 1-level nested table). This is the case
//    for a simple column family.
//
//  or,
// 
//  * a supercolumn column map, which in turn contains a column map
//    per super column (i.e. a 2-level nested table). This is the case
//    for a super column family.
//
// For the common case of key-based data retrieval or storage, CQL
// provides array like get/set syntax, such as:
//
//        SET user.profile['99']['name'] = 'joe';
//        SET user.profile['99']['age'] = '27';
//        GET user.profile['99']['name'];
//        GET user.profile['99'];
//
// When additional constraints need to be applied to data being retrieved
// (such as imposing row limits, retrieving counts, retrieving data for
// a subset of super columns or columns and son on) CQL falls back to more
// traditional SQL-like syntax. 
//
// *Note*: The SQL syntax supported by CQL doesn't support the full
// relational algebra. For example, it doesn't have any support for
// joins. It also imposes restrictions on the types of filters and ORDER
// BY clauses it supports-- generally only those queries that can be
// efficiently answered based on data layout are supported. Suppose a column
// family has been configured to store columns in time sorted fashion,
// CQL will not support 'ORDER BY column_name' for such a column family. 
//


//
// NOTE: The grammar is in a very rudimentary/prototypish shape right now.
//       Will undergo fairly big restructuring in the next checkin.
//

grammar Cql;

options {
    output=AST;
    ASTLabelType=CommonTree;
    backtrack=true;
}

//
// AST Nodes. We use a A_ prefix convention for these AST node names.
//
tokens {

    // Top-level AST nodes
    // These typically correspond to various top-level CQL statements.
    A_DELETE;
    A_GET;
    A_SELECT;
    A_SET;
    A_EXPLAIN_PLAN;

    // Internal AST nodes
    A_COLUMN_ACCESS;
    A_COLUMN_MAP_ENTRY;
    A_COLUMN_MAP_VALUE;
    A_FROM;
    A_KEY_IN_LIST;
    A_KEY_EXACT_MATCH;
    A_LIMIT;
    A_OFFSET;
    A_ORDER_BY;
    A_SUPERCOLUMN_MAP_ENTRY;
    A_SUPERCOLUMN_MAP_VALUE;
    A_SELECT_CLAUSE;
    A_WHERE;
}

@parser::header {
            package com.facebook.infrastructure.cql.compiler.parse;
        }

@lexer::header {
            package com.facebook.infrastructure.cql.compiler.parse;
        }

//
// Parser Section
//

// the root node
root
    : stmt SEMICOLON? EOF -> stmt
    | K_EXPLAIN K_PLAN stmt SEMICOLON? EOF -> ^(A_EXPLAIN_PLAN stmt)
    ;<commit_msg>fix package name.  patch by <NAME> for #42<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ANTLR Grammar Definition for Cassandra Query Language (CQL)
//
// CQL is a query language tailored for Cassandra's multi-level (or 
// nested-table like) data model where values stored for each key 
// can be:
//
//  * a simple column map (a 1-level nested table). This is the case
//    for a simple column family.
//
//  or,
// 
//  * a supercolumn column map, which in turn contains a column map
//    per super column (i.e. a 2-level nested table). This is the case
//    for a super column family.
//
// For the common case of key-based data retrieval or storage, CQL
// provides array like get/set syntax, such as:
//
//        SET user.profile['99']['name'] = 'joe';
//        SET user.profile['99']['age'] = '27';
//        GET user.profile['99']['name'];
//        GET user.profile['99'];
//
// When additional constraints need to be applied to data being retrieved
// (such as imposing row limits, retrieving counts, retrieving data for
// a subset of super columns or columns and son on) CQL falls back to more
// traditional SQL-like syntax. 
//
// *Note*: The SQL syntax supported by CQL doesn't support the full
// relational algebra. For example, it doesn't have any support for
// joins. It also imposes restrictions on the types of filters and ORDER
// BY clauses it supports-- generally only those queries that can be
// efficiently answered based on data layout are supported. Suppose a column
// family has been configured to store columns in time sorted fashion,
// CQL will not support 'ORDER BY column_name' for such a column family. 
//


//
// NOTE: The grammar is in a very rudimentary/prototypish shape right now.
//       Will undergo fairly big restructuring in the next checkin.
//

grammar Cql;

options {
    output=AST;
    ASTLabelType=CommonTree;
    backtrack=true;
}

//
// AST Nodes. We use a A_ prefix convention for these AST node names.
//
tokens {

    // Top-level AST nodes
    // These typically correspond to various top-level CQL statements.
    A_DELETE;
    A_GET;
    A_SELECT;
    A_SET;
    A_EXPLAIN_PLAN;

    // Internal AST nodes
    A_COLUMN_ACCESS;
    A_COLUMN_MAP_ENTRY;
    A_COLUMN_MAP_VALUE;
    A_FROM;
    A_KEY_IN_LIST;
    A_KEY_EXACT_MATCH;
    A_LIMIT;
    A_OFFSET;
    A_ORDER_BY;
    A_SUPERCOLUMN_MAP_ENTRY;
    A_SUPERCOLUMN_MAP_VALUE;
    A_SELECT_CLAUSE;
    A_WHERE;
}

@parser::header {
            package org.apache.cassandra.cql.compiler.parse;
        }

@lexer::header {
            package org.apache.cassandra.cql.compiler.parse;
        }

//
// Parser Section
//

// the root node
root
    : stmt SEMICOLON? EOF -> stmt
    | K_EXPLAIN K_PLAN stmt SEMICOLON? EOF -> ^(A_EXPLAIN_PLAN stmt)
    ;
{'fraction_non_alphanumeric': 0.0895353763592713, 'fraction_numerical': 0.004801581697500353, 'mean_word_length': 2.891208791208791, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364109', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2055, 'n_words': 865}