@top T { (A | B)+ }

A[@dynamicPrecedence=2] { "foo" "bar" ~ambig }

B[@dynamicPrecedence=1] { "foo" ("bar" | "baz" ~ambig | Inner) ~ambig }

Inner[@dynamicPrecedence=-1] { ("baz" | "quux") ~ambig }

# Prefers As

foobarfoobar

==> T(A, A)

# Can parse Bs

foobazfoobar

==> T(B, A)

# Will use penalized rules when necessary

fooquux

==> T(B(Inner))
