Last active
August 29, 2015 14:16
-
-
Save icholy/d21bd7e2f5eb7e1936d7 to your computer and use it in GitHub Desktop.
PEG parser for Nagios Status.dat file.
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
start = group* | |
identifier = [a-zA-Z_]+ | |
whitespace = [ \r\n\t] | |
comment = '#' [^\n]* '\n' | |
ignored = whitespace / comment | |
_ = ignored* | |
value = word:[^\n]+ '\n' { | |
return word; | |
} | |
property = _ name:identifier '=' value:value? _ { | |
return { | |
name: name.join(""), | |
value: (value || []).join("").trim() | |
}; | |
} | |
group = _ group_name:identifier _ '{' properties:property* '}' _ { | |
return { | |
name: group_name.join(""), | |
properties: properties.reduce(function (acc, p) { | |
acc[p.name] = p.value; | |
return acc; | |
}, {}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment