Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RangerMauve
Created March 21, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RangerMauve/ddcbc5346d8cf8505dfe to your computer and use it in GitHub Desktop.
Save RangerMauve/ddcbc5346d8cf8505dfe to your computer and use it in GitHub Desktop.
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