242 lines
4.7 KiB
Plaintext
242 lines
4.7 KiB
Plaintext
|
require "treetop/runtime"
|
||
|
require "logstash/compiler/lscl.rb"
|
||
|
|
||
|
grammar LogStashCompilerLSCLGrammar
|
||
|
rule config
|
||
|
(cs plugin_section)* cs <LogStash::Compiler::LSCL::AST::Config>
|
||
|
end
|
||
|
|
||
|
rule comment
|
||
|
(whitespace? "#" [^\r\n]* "\r"? "\n")+ <LogStash::Compiler::LSCL::AST::Comment>
|
||
|
end
|
||
|
|
||
|
rule cs
|
||
|
(comment / whitespace)* <LogStash::Compiler::LSCL::AST::Whitespace>
|
||
|
end
|
||
|
|
||
|
rule whitespace
|
||
|
[ \t\r\n]+ <LogStash::Compiler::LSCL::AST::Whitespace>
|
||
|
end
|
||
|
|
||
|
rule plugin_section
|
||
|
plugin_type cs "{"
|
||
|
cs (branch_or_plugin cs)*
|
||
|
"}"
|
||
|
<LogStash::Compiler::LSCL::AST::PluginSection>
|
||
|
end
|
||
|
|
||
|
rule branch_or_plugin
|
||
|
branch / plugin
|
||
|
end
|
||
|
|
||
|
rule plugin_type
|
||
|
("input" / "filter" / "output")
|
||
|
end
|
||
|
|
||
|
rule plugins
|
||
|
(plugin (cs plugin)*)?
|
||
|
<LogStash::Compiler::LSCL::AST::Plugins>
|
||
|
end
|
||
|
|
||
|
rule plugin
|
||
|
name cs "{"
|
||
|
cs
|
||
|
attributes:( attribute (whitespace cs attribute)*)?
|
||
|
cs
|
||
|
"}"
|
||
|
<LogStash::Compiler::LSCL::AST::Plugin>
|
||
|
end
|
||
|
|
||
|
rule name
|
||
|
(
|
||
|
([A-Za-z0-9_-]+ <LogStash::Compiler::LSCL::AST::Name>)
|
||
|
/ string
|
||
|
)
|
||
|
end
|
||
|
|
||
|
rule attribute
|
||
|
name cs "=>" cs value
|
||
|
<LogStash::Compiler::LSCL::AST::Attribute>
|
||
|
end
|
||
|
|
||
|
rule value
|
||
|
plugin / bareword / string / number / array / hash
|
||
|
end
|
||
|
|
||
|
rule array_value
|
||
|
bareword / string / number / array / hash
|
||
|
end
|
||
|
|
||
|
rule bareword
|
||
|
[A-Za-z_] [A-Za-z0-9_]+
|
||
|
<LogStash::Compiler::LSCL::AST::Bareword>
|
||
|
end
|
||
|
|
||
|
rule double_quoted_string
|
||
|
( '"' ( '\"' / !'"' . )* '"' <LogStash::Compiler::LSCL::AST::String>)
|
||
|
end
|
||
|
|
||
|
rule single_quoted_string
|
||
|
( "'" ( "\\'" / !"'" . )* "'" <LogStash::Compiler::LSCL::AST::String>)
|
||
|
end
|
||
|
|
||
|
rule string
|
||
|
double_quoted_string / single_quoted_string
|
||
|
end
|
||
|
|
||
|
rule regexp
|
||
|
( '/' ( '\/' / !'/' . )* '/' <LogStash::Compiler::LSCL::AST::RegExp>)
|
||
|
end
|
||
|
|
||
|
rule number
|
||
|
"-"? [0-9]+ ("." [0-9]*)?
|
||
|
<LogStash::Compiler::LSCL::AST::Number>
|
||
|
end
|
||
|
|
||
|
rule array
|
||
|
"["
|
||
|
cs
|
||
|
(
|
||
|
value (cs "," cs value)*
|
||
|
)?
|
||
|
cs
|
||
|
"]"
|
||
|
<LogStash::Compiler::LSCL::AST::Array>
|
||
|
end
|
||
|
|
||
|
rule hash
|
||
|
"{"
|
||
|
cs
|
||
|
hashentries?
|
||
|
cs
|
||
|
"}"
|
||
|
<LogStash::Compiler::LSCL::AST::Hash>
|
||
|
end
|
||
|
|
||
|
rule hashentries
|
||
|
hashentry (whitespace hashentry)*
|
||
|
<LogStash::Compiler::LSCL::AST::HashEntries>
|
||
|
end
|
||
|
|
||
|
rule hashentry
|
||
|
name:(number / bareword / string) cs "=>" cs value
|
||
|
<LogStash::Compiler::LSCL::AST::HashEntry>
|
||
|
end
|
||
|
|
||
|
# Conditions
|
||
|
rule branch
|
||
|
if (cs else_if)* (cs else)?
|
||
|
<LogStash::Compiler::LSCL::AST::Branch>
|
||
|
end
|
||
|
|
||
|
rule if
|
||
|
"if" cs condition cs "{" cs (branch_or_plugin cs)* "}"
|
||
|
<LogStash::Compiler::LSCL::AST::If>
|
||
|
end
|
||
|
|
||
|
rule else_if
|
||
|
"else" cs "if" cs condition cs "{" cs ( branch_or_plugin cs)* "}"
|
||
|
<LogStash::Compiler::LSCL::AST::Elsif>
|
||
|
end
|
||
|
|
||
|
rule else
|
||
|
"else" cs "{" cs (branch_or_plugin cs)* "}"
|
||
|
<LogStash::Compiler::LSCL::AST::Else>
|
||
|
end
|
||
|
|
||
|
rule condition
|
||
|
expression (cs boolean_operator cs expression)*
|
||
|
<LogStash::Compiler::LSCL::AST::Condition>
|
||
|
end
|
||
|
|
||
|
rule expression
|
||
|
(
|
||
|
("(" cs condition cs ")")
|
||
|
/ negative_expression
|
||
|
/ in_expression
|
||
|
/ not_in_expression
|
||
|
/ compare_expression
|
||
|
/ regexp_expression
|
||
|
/ rvalue
|
||
|
) <LogStash::Compiler::LSCL::AST::Expression>
|
||
|
end
|
||
|
|
||
|
rule negative_expression
|
||
|
(
|
||
|
("!" cs "(" cs condition cs ")")
|
||
|
/ ("!" cs selector)
|
||
|
) <LogStash::Compiler::LSCL::AST::NegativeExpression>
|
||
|
end
|
||
|
|
||
|
rule in_expression
|
||
|
rvalue cs in_operator cs rvalue
|
||
|
<LogStash::Compiler::LSCL::AST::InExpression>
|
||
|
end
|
||
|
|
||
|
rule not_in_expression
|
||
|
rvalue cs not_in_operator cs rvalue
|
||
|
<LogStash::Compiler::LSCL::AST::NotInExpression>
|
||
|
end
|
||
|
|
||
|
rule in_operator
|
||
|
"in"
|
||
|
end
|
||
|
|
||
|
rule not_in_operator
|
||
|
"not " cs "in"
|
||
|
end
|
||
|
|
||
|
rule rvalue
|
||
|
string / number / selector / array / method_call / regexp
|
||
|
end
|
||
|
|
||
|
rule method_call
|
||
|
method cs "(" cs
|
||
|
(
|
||
|
rvalue ( cs "," cs rvalue )*
|
||
|
)?
|
||
|
cs ")"
|
||
|
<LogStash::Compiler::LSCL::AST::MethodCall>
|
||
|
end
|
||
|
|
||
|
rule method
|
||
|
bareword
|
||
|
end
|
||
|
|
||
|
rule compare_expression
|
||
|
rvalue cs compare_operator cs rvalue
|
||
|
<LogStash::Compiler::LSCL::AST::ComparisonExpression>
|
||
|
end
|
||
|
|
||
|
rule compare_operator
|
||
|
("==" / "!=" / "<=" / ">=" / "<" / ">")
|
||
|
<LogStash::Compiler::LSCL::AST::ComparisonOperator>
|
||
|
end
|
||
|
|
||
|
rule regexp_expression
|
||
|
rvalue cs regexp_operator cs (string / regexp)
|
||
|
<LogStash::Compiler::LSCL::AST::RegexpExpression>
|
||
|
end
|
||
|
|
||
|
rule regexp_operator
|
||
|
("=~" / "!~") <LogStash::Compiler::LSCL::AST::RegExpOperator>
|
||
|
end
|
||
|
|
||
|
|
||
|
rule boolean_operator
|
||
|
("and" / "or" / "xor" / "nand")
|
||
|
<LogStash::Compiler::LSCL::AST::BooleanOperator>
|
||
|
end
|
||
|
|
||
|
rule selector
|
||
|
selector_element+
|
||
|
<LogStash::Compiler::LSCL::AST::Selector>
|
||
|
end
|
||
|
|
||
|
rule selector_element
|
||
|
"[" [^\]\[,]+ "]"
|
||
|
<LogStash::Compiler::LSCL::AST::SelectorElement>
|
||
|
end
|
||
|
|
||
|
end
|