Created
November 10, 2012 19:29
-
-
Save ivoronin/4052222 to your computer and use it in GitHub Desktop.
strace lexer for pygments
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
__author__ = 'ivoronin' | |
from pygments.lexer import RegexLexer, bygroups, include | |
from pygments.token import * | |
class StraceLexer(RegexLexer): | |
name = "Strace" | |
aliases = ["strace", "truss"] | |
tokens = { | |
'generic': [ | |
(r'((?:0x)?[0-9a-f]+)', Number.Hex), | |
(r'(?:-)?\d+', Number), | |
(r'[A-Z_0-9]+', Keyword.Constant), | |
(r'\|', Punctuation), | |
(r'"[^"]*?"(?:\.\.\.)?', String), # read(3, "# The \"order\" line is only used "..., 4096) = 92 | |
(r'\*', Punctuation) | |
], | |
'namedargs': [ | |
(r'(\w+?)(=)', bygroups(Name.Variable, Punctuation)) | |
], | |
'root': [ | |
(r'^(\d+)( )', bygroups(Name.Attribute, Whitespace)), | |
(r'(\w+)(?=\()', Name.Function), | |
(r'(<... \w+ resumed>)( )', bygroups(Generic.Emph, Whitespace), 'arguments'), | |
(r'--- SIG.* ---$', Generic.Strong), | |
(r'(\()', Punctuation, 'arguments'), | |
(r'(\s+)(=)(\s)', bygroups(Whitespace, Punctuation, Whitespace), 'result') | |
], | |
'arguments': [ | |
(r'\)', Punctuation, '#pop'), # end of arguments | |
(r'(,)( )', bygroups(Punctuation, Whitespace)), # end of argument | |
# Data structures | |
(r' <unfinished \.\.\.>$', Generic.Emph), | |
(r'\[', Punctuation, 'array'), | |
(r'{', Punctuation, 'structure'), | |
include('namedargs'), | |
include('generic'), | |
], | |
'array': [ | |
(r'\]', Punctuation, '#pop'), | |
(r'(,)( )', bygroups(Punctuation, Whitespace)), # end of member | |
(r' ', Whitespace), # end of member | |
(r'/\*.+?\*/', Comment), | |
include('generic'), | |
], | |
'structure': [ | |
(r'}', Punctuation, '#pop'), # end of structure | |
(r'(,)( )', bygroups(Punctuation, Whitespace)), # end of member | |
(r'\[', Punctuation, 'array'), | |
include('namedargs'), | |
(r'\.\.\.', Punctuation), | |
include('generic'), | |
], | |
'result': [ | |
(r'$', Generic, '#pop'), | |
(r'(-1 E.+)$', Generic.Error), | |
(r'\?$', Punctuation), | |
include('generic') | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment