Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active August 29, 2015 14:16
Show Gist options
  • Save icholy/d21bd7e2f5eb7e1936d7 to your computer and use it in GitHub Desktop.
Save icholy/d21bd7e2f5eb7e1936d7 to your computer and use it in GitHub Desktop.
PEG parser for Nagios Status.dat file.
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