summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-03 17:01:20 +0100
committerGeorg Brandl <georg@python.org>2011-01-03 17:01:20 +0100
commitc2afa9eda2a526a302dd7913ceec6e8b198fcac2 (patch)
treee40a4ef72383a476bceb2fd2690b13410671ed8d
parent5ac6007426cd8707de3538ef7ba19e67497dbf4a (diff)
downloadpygments-c2afa9eda2a526a302dd7913ceec6e8b198fcac2.tar.gz
Add Hybris lexer (#506).
-rw-r--r--AUTHORS1
-rw-r--r--CHANGES1
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/other.py80
-rw-r--r--tests/examplefiles/File.hy174
5 files changed, 256 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index cfa833f5..07235bdb 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -47,6 +47,7 @@ Other contributors, listed alphabetically, are:
* Gerd Kurzbach -- Modelica lexer
* Mark Lee -- Vala lexer
* Ben Mabey -- Gherkin lexer
+* Simone Margaritelli -- Hybris lexer
* Kirk McDonald -- D lexer
* Stephen McKamey -- Duel/JBST lexer
* Lukas Meuser -- BBCode formatter, Lua lexer
diff --git a/CHANGES b/CHANGES
index 873819c2..17036a16 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@ Version 1.4
* SSP (#473)
* Autohotkey (#417)
* Google Protocol Buffers
+ * Hybris (#506)
- Do not fail in analyse_text methods (#618).
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 01393f9b..4444e7b0 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -99,6 +99,7 @@ LEXERS = {
'HtmlLexer': ('pygments.lexers.web', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml', '*.xslt'), ('text/html', 'application/xhtml+xml')),
'HtmlPhpLexer': ('pygments.lexers.templates', 'HTML+PHP', ('html+php',), ('*.phtml',), ('application/x-php', 'application/x-httpd-php', 'application/x-httpd-php3', 'application/x-httpd-php4', 'application/x-httpd-php5')),
'HtmlSmartyLexer': ('pygments.lexers.templates', 'HTML+Smarty', ('html+smarty',), (), ('text/html+smarty',)),
+ 'HybrisLexer': ('pygments.lexers.other', 'Hybris', ('hybris', 'hy'), ('*.hy', '*.hyb'), ('text/x-hybris', 'application/x-hybris')),
'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg'), ('*.ini', '*.cfg'), ('text/x-ini',)),
'IoLexer': ('pygments.lexers.agile', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)),
'IokeLexer': ('pygments.lexers.agile', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)),
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index ab355447..69e4ccb7 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -26,7 +26,7 @@ __all__ = ['SqlLexer', 'MySqlLexer', 'SqliteConsoleLexer', 'BrainfuckLexer',
'BashSessionLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer',
'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer',
'PostScriptLexer', 'AutohotkeyLexer', 'GoodDataCLLexer',
- 'MaqlLexer', 'ProtoBufLexer']
+ 'MaqlLexer', 'ProtoBufLexer', 'HybrisLexer']
line_re = re.compile('.*?\n')
@@ -2763,3 +2763,81 @@ class ProtoBufLexer(RegexLexer):
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name, '#pop')
],
}
+
+
+class HybrisLexer(RegexLexer):
+ """
+ For `Hybris <http://www.hybris-lang.org>`_ source code.
+
+ *New in Pygments 1.4.*
+ """
+
+ name = 'Hybris'
+ aliases = ['hybris', 'hy']
+ filenames = ['*.hy', '*.hyb']
+ mimetypes = ['text/x-hybris', 'application/x-hybris']
+
+ flags = re.MULTILINE | re.DOTALL
+
+ tokens = {
+ 'root': [
+ # method names
+ (r'^(\s*(?:function|method|operator\s+)+?)'
+ r'([a-zA-Z_][a-zA-Z0-9_]*)'
+ r'(\s*)(\()', bygroups(Name.Function, Text, Operator)),
+ (r'[^\S\n]+', Text),
+ (r'//.*?\n', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
+ (r'(break|case|catch|next|default|do|else|finally|for|foreach|of|'
+ r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword),
+ (r'(extends|private|protected|public|static|throws|function|method|'
+ r'operator)\b', Keyword.Declaration),
+ (r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|'
+ r'__INC_PATH__)\b', Keyword.Constant),
+ (r'(class|struct)(\s+)',
+ bygroups(Keyword.Declaration, Text), 'class'),
+ (r'(import|include)(\s+)',
+ bygroups(Keyword.Namespace, Text), 'import'),
+ (r'(gc_collect|gc_mm_items|gc_mm_usage|gc_collect_threshold|'
+ r'urlencode|urldecode|base64encode|base64decode|sha1|crc32|sha2|'
+ r'md5|md5_file|acos|asin|atan|atan2|ceil|cos|cosh|exp|fabs|floor|'
+ r'fmod|log|log10|pow|sin|sinh|sqrt|tan|tanh|isint|isfloat|ischar|'
+ r'isstring|isarray|ismap|isalias|typeof|sizeof|toint|tostring|'
+ r'fromxml|toxml|binary|pack|load|eval|var_names|var_values|'
+ r'user_functions|dyn_functions|methods|call|call_method|mknod|'
+ r'mkfifo|mount|umount2|umount|ticks|usleep|sleep|time|strtime|'
+ r'strdate|dllopen|dlllink|dllcall|dllcall_argv|dllclose|env|exec|'
+ r'fork|getpid|wait|popen|pclose|exit|kill|pthread_create|'
+ r'pthread_create_argv|pthread_exit|pthread_join|pthread_kill|'
+ r'smtp_send|http_get|http_post|http_download|socket|bind|listen|'
+ r'accept|getsockname|getpeername|settimeout|connect|server|recv|'
+ r'send|close|print|println|printf|input|readline|serial_open|'
+ r'serial_fcntl|serial_get_attr|serial_get_ispeed|serial_get_ospeed|'
+ r'serial_set_attr|serial_set_ispeed|serial_set_ospeed|serial_write|'
+ r'serial_read|serial_close|xml_load|xml_parse|fopen|fseek|ftell|'
+ r'fsize|fread|fwrite|fgets|fclose|file|readdir|pcre_replace|size|'
+ r'pop|unmap|has|keys|values|length|find|substr|replace|split|trim|'
+ r'remove|contains|join)\b', Name.Builtin),
+ (r'(MethodReference|Runner|Dll|Thread|Pipe|Process|Runnable|'
+ r'CGI|ClientSocket|Socket|ServerSocket|File|Console|Directory|'
+ r'Exception)\b', Keyword.Type),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
+ (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)',
+ bygroups(Operator, Name.Attribute)),
+ (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
+ (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+ (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?\-@]+', Operator),
+ (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
+ (r'0x[0-9a-f]+', Number.Hex),
+ (r'[0-9]+L?', Number.Integer),
+ (r'\n', Text),
+ ],
+ 'class': [
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
+ ],
+ 'import': [
+ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
+ ],
+ }
diff --git a/tests/examplefiles/File.hy b/tests/examplefiles/File.hy
new file mode 100644
index 00000000..9c86c641
--- /dev/null
+++ b/tests/examplefiles/File.hy
@@ -0,0 +1,174 @@
+/*
+ * This file is part of the Hybris programming language.
+ *
+ * Copyleft of Francesco Morucci aka merlok <merlok@ihteam.net>
+ *
+ * Hybris is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Hybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Hybris. If not, see <http://www.gnu.org/licenses/>.
+*/
+import std.io.file;
+
+class File {
+
+ protected file, fileName, mode;
+
+ public method File( fileName, mode ){
+ me.fileName = fileName;
+ me.mode = mode;
+ me.file = fopen ( me.fileName, me.mode);
+ }
+
+ private method isBinary(){
+ return me.mode.find("b") != false;
+ }
+
+ public method File ( file ){
+ me.file = file;
+ }
+
+ private method __expire() {
+ me.close();
+ }
+
+ public method close(){
+ fclose( me.file );
+ }
+
+ public method readLine(){
+ return line = fgets( me.file );
+ }
+
+ public method getFileName(){
+ return me.fileName;
+ }
+
+ public method getSize(){
+ return fsize( me.fileName );
+ }
+
+ public method getPosition(){
+ return ftell( me.file );
+ }
+
+ public method readAll(){
+ text = "";
+ line = "";
+ while ( ( line = fgets(me.file) ) != 0 ){
+ text += line;
+ }
+ return text;
+ }
+
+ public method read(){
+ byte = ' ';
+ if ( fread( me.file, byte) > 0 ) {
+ return byte;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ public method read( bytes ) {
+ word = "";
+ byte = ' ';
+ if ( fread( me.file, byte, bytes) > 0 ) {
+ word += byte;
+ }
+ else {
+ return -1;
+ }
+ return word;
+ }
+
+ public method read ( seek, seekType ){
+ if ( me.seek( seek, seekType) == 0 ) {
+ return -1;
+ }
+
+ return me.read();
+ }
+
+ public method read ( bytes, seek, seekType ){
+ if ( me.seek( seek, seekType) == 0 ) {
+ return -1;
+ }
+
+ return me.read( bytes );
+ }
+
+ public method readType ( type ){
+ if ( me.isBinary() == false ) {
+ return -1;
+ }
+ if ( fread (me.file, type ) > 0 ) {
+ return type;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ operator >> ( object ){
+ return me.readType(object);
+ }
+
+ public method readType ( type, bytes ){
+ if ( me.isBinary() == false ) {
+ return -1;
+ }
+ if ( fread (me.file, type, bytes ) > 0){
+ return type;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ public method readType ( type, seek, seekType ){
+ if ( ( me.isBinary() == false ) | ( me.seek( seek, seekType) == 0 ) ) {
+ return -1;
+ }
+
+ return me.readType( type );
+ }
+
+ public method readType( type, bytes, seek, seekType){
+ if ( ( me.isBinary() == false ) | ( me.seek( seek, seekType) == 0 ) ) {
+ return -1;
+ }
+
+ return me.readType( type, bytes );
+ }
+
+ public method write( data ){
+ return fwrite( me.file, data );
+ }
+
+ operator << ( object ){
+ return me.write(object);
+ }
+
+ public method write ( data, bytes ){
+ return fwrite( me.file, data, bytes);
+ }
+
+ public method seek( pos, mode ){
+ return fseek( me.file, pos, mode );
+ }
+
+ public method merge ( fileName ){
+ text = file ( fileName );
+ return me.write ( me.file, text );
+ }
+}