Skip to content

Commit b1fd7d2

Browse files
committed
mul not working
1 parent ffc6532 commit b1fd7d2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

parser/src/main/scala/coulomb/parser.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ object standard:
3737
object infra:
3838
import _root_.cats.parse.*
3939

40+
val ws: Parser[Unit] = Parser.charIn(" \t\r\n").void
41+
val ws0: Parser0[Unit] = ws.rep0.void
42+
43+
def unit(named: Parser[RuntimeUnit]): Parser[RuntimeUnit] =
44+
Parser.recursive[RuntimeUnit] { recurse =>
45+
val sub: Parser[RuntimeUnit] = recurse.between(Parser.char('(') <* ws0, ws0 *> Parser.char(')'))
46+
val mul: Parser[RuntimeUnit] =
47+
((recurse <* Parser.char('*').soft.surroundedBy(ws0)).soft ~ recurse).map { case (lhs, rhs) =>
48+
RuntimeUnit.Mul(lhs, rhs)
49+
}
50+
Parser.oneOf(named :: sub :: mul :: Nil)
51+
}
52+
4053
def named(unames: Map[String, String], pnames: Set[String]): Parser[RuntimeUnit] =
4154
// unames is never empty by construction
4255
val unit = strset(unames.keySet).map { name =>

0 commit comments

Comments
 (0)