Skip to content

Instantly share code, notes, and snippets.

@peteoleary
Created September 9, 2014 04:17
Show Gist options
  • Save peteoleary/e0d69b6cd6d8fc191e61 to your computer and use it in GitHub Desktop.
Save peteoleary/e0d69b6cd6d8fc191e61 to your computer and use it in GitHub Desktop.
ANTLR grammar for Logstash conf file format
grammar logstash_conf;
filler: (comment | WS)*;
comment: (WS? '#' .*? '\r'? '\n')+;
config: filler plugin_section (filler plugin_section)* ;
plugin_section: plugin_type filler '{'
filler (branch_or_plugin filler)*
'}';
plugin_type: ('input' | 'filter' | 'output');
branch_or_plugin: branch | plugin;
branch: r_if (filler else_if)* (filler r_else)?;
plugin:
name filler '{'
filler
attributes
filler
'}';
attributes:( attribute (WS filler attribute)*)?;
attribute: name filler '=>' filler value;
r_if: 'if' filler condition filler '{' filler (branch_or_plugin filler)* '}';
else_if: 'else' filler 'if' filler condition filler '{' filler ( branch_or_plugin filler)* '}';
r_else: 'else' filler '{' filler (branch_or_plugin filler)* '}';
name: ID | string;
string: double_quoted_string | single_quoted_string;
double_quoted_string : '"' ( '\\"' | . )*? '"' ;
single_quoted_string : '\'' ( . )*? '\'' ;
value: plugin | ID | string | number | array | hash;
number:
'-'? DIGIT+ ('.' DIGIT*)?;
condition: expression (filler boolean_operator filler expression)*;
expression:
(
('(' filler condition filler ')')
| negative_expression
| in_expression
| not_in_expression
| compare_expression
| regexp_expression
| rvalue
);
array:
'['
filler
(
value (filler ',' filler value)*
)?
filler
']';
hash:
'{'
filler
hashentries?
filler
'}'
;
hashentries:
hashentry (WS hashentry)*
;
hashentry:
name filler '=>' filler value;
boolean_operator:
('and' | 'or' | 'xor' | 'nand');
negative_expression:
(
('!' filler '(' filler condition filler ')')
| ('!' filler selector)
);
in_expression:
rvalue filler in_operator filler rvalue;
not_in_expression:
rvalue filler not_in_operator filler rvalue;
rvalue:
string | number | selector | array | method_call | regexp;
selector: selector_element+;
compare_expression:
rvalue filler compare_operator filler rvalue;
regexp_expression:
rvalue filler regexp_operator filler (string | regexp);
// TODO: figure out selector_elements
selector_element: '[' .+? ']';
in_operator: 'in';
not_in_operator: 'not' filler 'in';
method_call:
ID filler '(' filler
(
rvalue ( filler ',' filler rvalue )*
)?
filler ')';
// TODO: figure out regexp
regexp: '/' ( . )*? '/';
compare_operator :
('==' | '!=' | '<=' | '>=' | '<' / '>') ;
regexp_operator: ('=~' / '!~');
ID: [a-zA-Z_$] [a-zA-Z_$0-9]* ;
DIGIT: [0-9];
WS : (' '|'\r'|'\n')+;
NEWLINE : [\r\n]+ ;
INT : [0-9]+ ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment