parsley.token.descriptions.SymbolDesc.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2020 Parsley Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.token.descriptions
import parsley.internal.collection.immutable.Trie
/** This class describes how symbols (textual literals in a BNF) should be
* processed lexically.
*
* @param hardKeywords what keywords are ''always'' treated as keywords within the language.
* @param hardOperators what operators are ''always'' treated as reserved operators within the language.
* @param caseSensitive are the keywords case sensitive: when `false`, `IF == if`.
* @since 4.0.0
*/
final case class SymbolDesc (hardKeywords: Set[String],
hardOperators: Set[String],
caseSensitive: Boolean) {
require((hardKeywords & hardOperators).isEmpty, "there cannot be an intersection between keywords and operators")
private [parsley] val hardOperatorsTrie: Trie[Unit] = Trie(hardOperators)
private [parsley] def isReservedName(name: String): Boolean =
theReservedNames.contains(if (caseSensitive) name else name.toLowerCase)
private lazy val theReservedNames = if (caseSensitive) hardKeywords else hardKeywords.map(_.toLowerCase)
private [parsley] def isReservedOp(op: String): Boolean = hardOperators.contains(op)
}
/** This object contains any preconfigured symbol descriptions.
* @since 4.0.0
*/
object SymbolDesc {
/** Plain definition of symbols: case sensitive with no hard keywords or operators.
*
* {{{
* hardKeywords = Set.empty
* hardOperators = Set.empty
* caseSensitive = true
* }}}
*
* @since 4.0.0
*/
val plain = SymbolDesc(hardKeywords = Set.empty, hardOperators = Set.empty, caseSensitive = true)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy