File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
parser/src/main/scala/coulomb Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,19 @@ object standard:
3737object 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 =>
You can’t perform that action at this time.
0 commit comments