Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MQTT-Regex parser in PEG.js
path = items:(pathStart pathEnd?) {return items[0].concat(items[1])}
pathStart = (items:(pathItem / singleParam / single)+)
pathEnd = item:(multiParam / multi / lastItem) {return item}
pathItem = text:pathName "/" {return {type: "text", content: text}}
lastItem = text:pathName "/"?
singleParam = "+" item:pathName "/" {return {type: "singleParam", name:item}}
multiParam = "#" item:pathName "/"? {return {type: "multiParam", name:item}}
single = "+" "/" {return {type: "single"}}
multi = "#" "/"? {return {type: "multi"}}
pathName = text:(pathText+) {return text.join("")}
pathText = [^/+#]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment