Commits

Anonymous committed 96b6322

added mysql lexer and fixed bug in html formatter

  • Participants
  • Parent commits 8f180ff
  • Branches trunk

Comments (0)

Files changed (4)

 
 - The Lua lexer now recognizes multi-line comments.
 
+- Added a MySQL lexer.
+
 
 Version 0.8.1
 -------------

pygments/formatters/html.py

 CSSFILE_TEMPLATE = '''\
 td.linenos { background-color: #f0f0f0; padding-right: 10px; }
 span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
-pre { line-height: 125%; }
+pre { line-height: 125%%; }
 %(styledefs)s
 '''
 

pygments/lexers/_mapping.py

     'MiniDLexer': ('pygments.lexers.agile', 'MiniD', ('minid',), ('*.md',), ('text/x-minidsrc',)),
     'MoinWikiLexer': ('pygments.lexers.text', 'MoinMoin/Trac Wiki markup', ('trac-wiki', 'moin'), (), ('text/x-trac-wiki',)),
     'MuPADLexer': ('pygments.lexers.math', 'MuPAD', ('mupad',), ('*.mu',), ()),
+    'MySqlLexer': ('pygments.lexers.other', 'MySQL', ('mysql',), (), ('text/x-mysql',)),
     'MyghtyCssLexer': ('pygments.lexers.templates', 'CSS+Myghty', ('css+myghty',), (), ('text/css+myghty',)),
     'MyghtyHtmlLexer': ('pygments.lexers.templates', 'HTML+Myghty', ('html+myghty',), (), ('text/html+myghty',)),
     'MyghtyJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Myghty', ('js+myghty', 'javascript+myghty'), (), ('application/x-javascript+myghty', 'text/x-javascript+myghty', 'text/javascript+mygthy')),

pygments/lexers/other.py

 from pygments.util import shebang_matches
 
 
-__all__ = ['SqlLexer', 'BrainfuckLexer', 'BashLexer', 'BatchLexer',
-           'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer']
+__all__ = ['SqlLexer', 'MySqlLexer', 'BrainfuckLexer', 'BashLexer',
+           'BatchLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer']
 
 
 class SqlLexer(RegexLexer):
             # TODO: Backslash escapes?
             (r"'(''|[^'])*'", String.Single),
             (r'"(""|[^"])*"', String.Symbol), # not a real string literal in ANSI SQL
-            (r"`(``|[^`])*`", String.Backtick),
             (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
             (r'[;:()\[\],\.]', Punctuation)
         ],
     }
 
 
+class MySqlLexer(RegexLexer):
+    """
+    Special lexer for MySQL.
+    """
+
+    name = 'MySQL'
+    aliases = ['mysql']
+    mimetypes = ['text/x-mysql']
+
+    flags = re.IGNORECASE
+    tokens = {
+        'root': [
+            (r'\s+', Text),
+            (r'(#|--\s+).*?\n', Comment.Single),
+            (r'/\*', Comment.Multiline, 'multiline-comments'),
+            (r'[0-9]+', Number.Integer),
+            (r'[0-9]*\.[0-9]+(e[+-][0-9]+)', Number.Float),
+            # TODO: add backslash escapes
+            (r"'(''|[^'])*'", String.Single),
+            (r'"(""|[^"])*"', String.Double),
+            (r"`(``|[^`])*`", String.Symbol),
+            (r'[+*/<>=~!@#%^&|`?^-]', Operator),
+            (r'\b(tinyint|smallint|mediumint|int|integer|bigint|date|'
+             r'datetime|time|bit|bool|tinytext|mediumtext|longtext|text|'
+             r'tinyblob|mediumblob|longblob|blob|float|double|double\s+'
+             r'precision|real|numeric|dec|decimal|timestamp|year|char|'
+             r'varchar|varbinary|varcharacter|enum|set)(\b\s*)(\()?',
+             bygroups(Keyword.Type, Text, Punctuation)),
+            (r'\b(add|all|alter|analyze|and|as|asc|asensitive|before|between|'
+             r'bigint|binary|blob|both|by|call|cascade|case|change|char|'
+             r'character|check|collate|column|condition|constraint|continue|'
+             r'convert|create|cross|current_date|current_time|'
+             r'current_timestamp|current_user|cursor|database|databases|'
+             r'day_hour|day_microsecond|day_minute|day_second|dec|decimal|'
+             r'declare|default|delayed|delete|desc|describe|deterministic|'
+             r'distinct|distinctrow|div|double|drop|dual|each|else|elseif|'
+             r'enclosed|escaped|exists|exit|explain|fetch|float|float4|float8'
+             r'|for|force|foreign|from|fulltext|grant|group|having|'
+             r'high_priority|hour_microsecond|hour_minute|hour_second|if|'
+             r'ignore|in|index|infile|inner|inout|insensitive|insert|int|'
+             r'int1|int2|int3|int4|int8|integer|interval|into|is|iterate|'
+             r'join|key|keys|kill|leading|leave|left|like|limit|lines|load|'
+             r'localtime|localtimestamp|lock|long|loop|low_priority|match|'
+             r'minute_microsecond|minute_second|mod|modifies|natural|'
+             r'no_write_to_binlog|not|numeric|on|optimize|option|optionally|'
+             r'or|order|out|outer|outfile|precision|primary|procedure|purge|'
+             r'raid0|read|reads|real|references|regexp|release|rename|repeat|'
+             r'replace|require|restrict|return|revoke|right|rlike|schema|'
+             r'schemas|second_microsecond|select|sensitive|separator|set|'
+             r'show|smallint|soname|spatial|specific|sql|sql_big_result|'
+             r'sql_calc_found_rows|sql_small_result|sqlexception|sqlstate|'
+             r'sqlwarning|ssl|starting|straight_join|table|terminated|then|'
+             r'to|trailing|trigger|undo|union|unique|unlock|unsigned|update|'
+             r'usage|use|using|utc_date|utc_time|utc_timestamp|values|'
+             r'varying|when|where|while|with|write|x509|xor|year_month|'
+             r'zerofill)\b', Keyword),
+            # TODO: this list is not complete
+            (r'\b(auto_increment|engine|charset|tables)\b', Keyword.Pseudo),
+            (r'(true|false|null)', Name.Constant),
+            (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\()',
+             bygroups(Name.Function, Text, Punctuation)),
+            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
+            (r'@[A-Za-z0-9]*[._]*[A-Za-z0-9]*', Name.Variable),
+            (r'[;:()\[\],\.]', Punctuation)
+        ],
+        'multiline-comments': [
+            (r'/\*', Comment.Multiline, 'multiline-comments'),
+            (r'\*/', Comment.Multiline, '#pop'),
+            (r'[^/\*]+', Comment.Multiline),
+            (r'[/*]', Comment.Multiline)
+        ]
+    }
+
+
 class BrainfuckLexer(RegexLexer):
     """
     Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_