Created
March 21, 2016 21:56
-
-
Save RangerMauve/ddcbc5346d8cf8505dfe to your computer and use it in GitHub Desktop.
MQTT-Regex parser in PEG.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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