I have the following template:
#foo(args)# // START CONTAINER1
#foo(foo <- foos)(args)# // BLOCK STARTS HERE (`args` can be on either side of `block`)
#bar(args)# // START CONTAINER2
#.bar# // END CONTAINER2
#.foo# // END BLOCK
#.foo# // END CONTAINER1
*notice how #.foo# closes each container/block
The trouble I see here is that there's no unique id of some sort to represent each block so I have to keep track of how many container openers/closers there are (#foo#/#.foo#) so that a block with an inside container's END CONTAINER hash won't confuse the parser as ending the block.
How would I use Scala's parsers to parse blocks in a language like this?
I started off with this:
def maybeBlockMaybeJustContainer:Content = {
(openingHash ~ identifier ~ opt(args) ~> opt(blockName) <~ opt(args) ~ closingHash) ~
opt(content) ~
openHash ~ dot ~ identifier ~ closingHash ^^ ...
}
I'm also thinking about preprocessing it but not sure where to start.
openingHashandclosingHashshould be the same. Why not justhash?