Commits

Georg Brandl committed 129b87f

Add Hybris lexer (#506).

Comments (0)

Files changed (5)

 * 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
   * SSP (#473)
   * Autohotkey (#417)
   * Google Protocol Buffers
+  * Hybris (#506)
 
 - Do not fail in analyse_text methods (#618).
 

pygments/lexers/_mapping.py

     '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',)),

pygments/lexers/other.py

            'BashSessionLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer',
            'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer',
            'PostScriptLexer', 'AutohotkeyLexer', 'GoodDataCLLexer',
-           'MaqlLexer', 'ProtoBufLexer']
+           'MaqlLexer', 'ProtoBufLexer', 'HybrisLexer']
 
 line_re  = re.compile('.*?\n')
 
             (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')
+        ],
+    }

tests/examplefiles/File.hy

+/*
+ * 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 );
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.