All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.antlr.v4.kotlinruntime.LexerInterpreter.kt Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD 3-clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

package org.antlr.v4.kotlinruntime

import org.antlr.v4.kotlinruntime.atn.ATN
import org.antlr.v4.kotlinruntime.atn.ATNType
import org.antlr.v4.kotlinruntime.atn.LexerATNSimulator
import org.antlr.v4.kotlinruntime.atn.PredictionContextCache
import org.antlr.v4.kotlinruntime.dfa.DFA

class LexerInterpreter(override val grammarFileName: String, override val vocabulary: Vocabulary, ruleNames: Collection, channelNames: Collection, modeNames: Collection, override val atn: ATN, input: CharStream) : Lexer(input) {


    @Deprecated("")
    @get:Deprecated("")
    override val tokenNames: Array?
    override val ruleNames: Array?
    override val channelNames: Array?
    override val modeNames: Array?

    protected val _decisionToDFA: Array
    protected val _sharedContextCache = PredictionContextCache()

    @Deprecated("")
    constructor(grammarFileName: String, tokenNames: Collection, ruleNames: Collection, modeNames: Collection, atn: ATN, input: CharStream) : this(grammarFileName, VocabularyImpl.fromTokenNames(tokenNames.toTypedArray()), ruleNames, ArrayList(), modeNames, atn, input) {
    }

    @Deprecated("")
    constructor(grammarFileName: String, vocabulary: Vocabulary, ruleNames: Collection, modeNames: Collection, atn: ATN, input: CharStream) : this(grammarFileName, vocabulary, ruleNames, ArrayList(), modeNames, atn, input) {
    }

    init {

        if (atn.grammarType !== ATNType.LEXER) {
            throw IllegalArgumentException("The ATN must be a lexer ATN.")
        }
        this.tokenNames = arrayOfNulls(atn.maxTokenType)
        for (i in tokenNames!!.indices) {
            tokenNames!![i] = vocabulary!!.getDisplayName(i)
        }

        this.ruleNames = ruleNames.toTypedArray()
        this.channelNames = channelNames.toTypedArray()
        this.modeNames = modeNames.toTypedArray()

        this._decisionToDFA = arrayOfNulls(atn.numberOfDecisions)
        for (i in _decisionToDFA.indices) {
            _decisionToDFA[i] = DFA(atn.getDecisionState(i)!!, i)
        }
        this.interpreter = LexerATNSimulator(this, atn, _decisionToDFA, _sharedContextCache)
    }

//    fun getVocabulary(): Vocabulary {
//        return vocabulary ?: super.vocabulary
//
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy