I've been working on a PEGjs grammar. Most of it works, but I'm having trouble with one last thing. My parser takes input that looks like this: First:[content];
and returns the type (First or Second) and each of the elements inside content ("c", "o"...). I also need it to be able to take ]
as input so it should be able to parse the following: First:[co]nt];
.
Does anyone have any ideas of how I can go about this? This is what I have so far:
prod = unit+
unit = u:(form / size)
form = key:(kind) ":" value:(clas) ";" {return {type:key, value:value} }
clas = "[" v:(charact+) "]" { return {type:"class",value:v} }
kind = "First" / "Second"
charact = letters / symbols
symbols = "(" / ")" / "!" / "?" / "%" / "{" / "}" / "[" // "]"
letters = [A-Za-z]`