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

parsley.internal.deepembedding.singletons.token.SymbolEmbedding.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020 Parsley Contributors 
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package parsley.internal.deepembedding.singletons.token

import parsley.token.errors.LabelWithExplainConfig
import parsley.token.predicate.CharPredicate

import parsley.internal.collection.immutable.Trie
import parsley.internal.deepembedding.backend.StrictParsley.InstrBuffer
import parsley.internal.deepembedding.frontend.LazyParsleyIVisitor
import parsley.internal.deepembedding.singletons.Singleton
import parsley.internal.machine.instructions

private [parsley] final class SoftKeyword(private [SoftKeyword] val specific: String, letter: CharPredicate, val caseSensitive: Boolean,
                                          val expected: LabelWithExplainConfig, expectedEnd: String) extends Singleton[Unit] {
    // $COVERAGE-OFF$
    override def pretty: String = s"softKeyword($specific)"
    // $COVERAGE-ON$
    override def genInstrs(producesResults: Boolean)(implicit instrs: InstrBuffer): Unit = {
        instrs += new instructions.token.SoftKeyword(specific, letter, caseSensitive, expected, expectedEnd)
        if (producesResults) instrs += instructions.Push.Unit
    }

    // $COVERAGE-OFF$
    override def visit[T, U[+_]](visitor: LazyParsleyIVisitor[T, U], context: T): U[Unit] = {
        visitor.visit(this, context)(specific, letter, caseSensitive, expected, expectedEnd)
    }

    override private[parsley] def prettyName: String = "symbol.softKeyword"
    // $COVERAGE-ON$
}

private [parsley] final class SoftOperator(private [SoftOperator] val specific: String, letter: CharPredicate, ops: Trie[Unit],
                                           val expected: LabelWithExplainConfig, expectedEnd: String) extends Singleton[Unit] {
    // $COVERAGE-OFF$
    override def pretty: String = s"softOperator($specific)"
    // $COVERAGE-ON$
    override def genInstrs(producesResults: Boolean)(implicit instrs: InstrBuffer): Unit = {
        instrs += new instructions.token.SoftOperator(specific, letter, ops, expected, expectedEnd)
        if (producesResults) instrs += instructions.Push.Unit
    }

    // $COVERAGE-OFF$
    override def visit[T, U[+_]](visitor: LazyParsleyIVisitor[T, U], context: T): U[Unit] = {
        visitor.visit(this, context)(specific, letter, ops, expected, expectedEnd)
    }

    override private[parsley] def prettyName: String = "symbol.softOperator"
    // $COVERAGE-ON$
}

// $COVERAGE-OFF$
private [deepembedding] object SoftKeyword {
    def unapply(self: SoftKeyword): Some[String] = Some(self.specific)
}
private [deepembedding] object SoftOperator {
    def unapply(self: SoftOperator): Some[String] = Some(self.specific)
}
// $COVERAGE-ON$




© 2015 - 2024 Weber Informatics LLC | Privacy Policy