<commit_before>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed 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.
 */

#include "TokenKind.h"

namespace ydsh {
namespace parser {

static const char *TOKEN_KIND_STRING[] = {
#define GEN_NAME(ENUM) "<" #ENUM ">",
        EACH_TOKEN(GEN_NAME)
#undef GEN_NAME
};

const char *toString(TokenKind kind) {
    return TOKEN_KIND_STRING[kind];
}

std::ostream &operator<<(std::ostream &stream, TokenKind kind) {
    stream << toString(kind);
    return stream;
}

unsigned int getPrecedence(TokenKind kind) {
    switch(kind) {
    case MUL:
    case DIV:
    case MOD:
        return 300;
    case PLUS:
    case MINUS:
        return 280;
    case LA:
    case RA:
    case LE:
    case GE:
        return 260;
    case IS:
    case AS:
        return 240;
    case EQ:
    case NE:
    case RE_MATCH:
    case RE_UNMATCH:
        return 220;
    case AND:
        return 200;
    case XOR:
        return 180;
    case OR:
        return 160;
    case COND_AND:
        return 140;<commit_msg>fix operator precedence, close #98<commit_after>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed 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.
 */

#include "TokenKind.h"

namespace ydsh {
namespace parser {

static const char *TOKEN_KIND_STRING[] = {
#define GEN_NAME(ENUM) "<" #ENUM ">",
        EACH_TOKEN(GEN_NAME)
#undef GEN_NAME
};

const char *toString(TokenKind kind) {
    return TOKEN_KIND_STRING[kind];
}

std::ostream &operator<<(std::ostream &stream, TokenKind kind) {
    stream << toString(kind);
    return stream;
}

unsigned int getPrecedence(TokenKind kind) {
    switch(kind) {
    case IS:
    case AS:
        return 300;
    case MUL:
    case DIV:
    case MOD:
        return 280;
    case PLUS:
    case MINUS:
        return 260;
    case AND:
        return 220;
    case XOR:
        return 200;
    case OR:
        return 180;
    case LA:
    case RA:
    case LE:
    case GE:
    case EQ:
    case NE:
    case RE_MATCH:
    case RE_UNMATCH:
        return 160;
    case COND_AND:
        return 140;
{'fraction_non_alphanumeric': 0.08953755329616267, 'fraction_numerical': 0.022630370613315843, 'mean_word_length': 2.7515375153751536, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '3186586', 'n_tokens_mistral': 991, 'n_tokens_neox': 922, 'n_words': 351}