Skip to content

Instantly share code, notes, and snippets.

@josch
Created August 6, 2013 11:57
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 josch/6163871 to your computer and use it in GitHub Desktop.
Save josch/6163871 to your computer and use it in GitHub Desktop.
pygments lexer for nfql
class NFQLLexer(RegexLexer):
name = 'NFQL'
aliases = ['nfql']
filenames = ['*.flw']
tokens = {
'whitespace': [
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text),
(r'#(\n|.*?\n)', Comment.Single),
],
'root' : [
include('whitespace'),
(r'(branch)(\s+[a-zA-Z]+)?(\s*{)', bygroups(Keyword, String, Punctuation), 'branch'),
(r'(merger)(\s+[a-zA-Z]+)?(\s*{)', bygroups(Keyword, String, Punctuation), 'merger'),
(r'(ungrouper)(\s+[a-zA-Z]+)?(\s*{)', bygroups(Keyword, String, Punctuation), 'ungrouper'),
],
'branch': [
include('whitespace'),
(r'(filter|groupfilter)(\s+[a-zA-Z]+)?(\s*{)', bygroups(Keyword, String, Punctuation), 'filter'),
(r'(grouper)(\s+[a-zA-Z]+)?(\s*{)', bygroups(Keyword, String, Punctuation), 'grouper'),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'dnf': [
(r'\d+', Number.Integer),
(r'(OR|delta|TCP)\b', Keyword.Reserved),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'(!=|>=|<=|[<>=])', Operator),
],
'mergerdnf': [
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String, Punctuation, Name)),
include('dnf'),
],
'aggregation': [
include('whitespace'),
(r'(static|union|sum|min|max)(\()([a-zA-Z_][a-zA-Z0-9_]*)(\))', bygroups(Keyword, Punctuation, Name, Punctuation)),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'ungrouper' : [
include('whitespace'),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'merger' : [
include('whitespace'),
include('mergerdnf'),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'filter' : [
include('whitespace'),
include('dnf'),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'grouper' : [
include('whitespace'),
(r'(aggregation)(\s*{)', bygroups(Keyword, Punctuation), 'aggregation'),
include('dnf'),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment