Cases for Parser using Scala Parser Combinators

I have a query with regards to a parser.

The parser accepts
'[' ~ action_op ~ '(' (subject | var)~ comp_expr ~ ')' ']'

How could I possibly produce a different case one for when a subject is inserted, and one when a variable is inserted please ?

Thanks a lot and good day

Split the parser?

sealed trait NecTarget

object NecTarget {
  case class Sub(value: Int) extends NecTarget
  case class Var(name: String) extends NecTarget

def subP: Parser[Sub] = ???
def varP: Parser[Var] = ???
def targetP: Parser[NecTarget] = subP | varP
1 Like

Thanks a lot and good day :slight_smile: