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

parsley.internal.deepembedding.frontend.debugger.Named.scala Maven / Gradle / Ivy

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

import parsley.XAssert

import parsley.internal.deepembedding.backend.StrictParsley
import parsley.internal.deepembedding.frontend.{LazyParsley, LazyParsleyIVisitor, Unary}

// $COVERAGE-OFF$
// Wrapper parser class indicating explicitly named parsers.
private [parsley] final class Named[A](_p: LazyParsley[A], val name: String) extends Unary[A, A](_p) {
    XAssert.assert(!p.isInstanceOf[Named[_]], "Named parsers should not be nested within each other directly.")
    def make(p: StrictParsley[A]): StrictParsley[A] = p
    override def visit[T, U[+_]](visitor: LazyParsleyIVisitor[T, U], context: T): U[A] = visitor.visitUnknown(this, context)
    private [parsley] var debugName = name
}

private [parsley] object Named {
    def apply[A](par: LazyParsley[A], name: String): Named[A] = new Named(par, name)

    def unapply[A](p: LazyParsley[A]): Option[(LazyParsley[A], String)] = p match {
        case n: Named[A @unchecked] => Some((n.p, n.name))
        case _                      => None
    }
}
// $COVERAGE-ON$




© 2015 - 2025 Weber Informatics LLC | Privacy Policy