Dustin Howett avatar Dustin Howett committed cf744b9

Add a lexer for the Logos language, which inherits functionality from the ObjectiveCppLexer.

Comments (0)

Files changed (3)

pygments/lexers/_mapping.py

     'LiterateHaskellLexer': ('pygments.lexers.functional', 'Literate Haskell', ('lhs', 'literate-haskell'), ('*.lhs',), ('text/x-literate-haskell',)),
     'LiveScriptLexer': ('pygments.lexers.web', 'LiveScript', ('live-script', 'livescript'), ('*.ls',), ('text/livescript',)),
     'LlvmLexer': ('pygments.lexers.asm', 'LLVM', ('llvm',), ('*.ll',), ('text/x-llvm',)),
+    'LogosLexer': ('pygments.lexers.compiled', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)),
     'LogtalkLexer': ('pygments.lexers.other', 'Logtalk', ('logtalk',), ('*.lgt',), ('text/x-logtalk',)),
     'LuaLexer': ('pygments.lexers.agile', 'Lua', ('lua',), ('*.lua', '*.wlua'), ('text/x-lua', 'application/x-lua')),
     'MOOCodeLexer': ('pygments.lexers.other', 'MOOCode', ('moocode',), ('*.moo',), ('text/x-moocode',)),

pygments/lexers/compiled.py

            'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
            'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
            'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
-           'DylanLidLexer', 'CobolLexer', 'CobolFreeformatLexer']
+           'DylanLidLexer', 'CobolLexer', 'CobolFreeformatLexer', 'LogosLexer']
 
 
 class CFamilyLexer(RegexLexer):
             (r'(\*>.*\n|^\w*\*.*$)', Comment),
         ],
     }
+
+class LogosLexer(ObjectiveCppLexer):
+    """
+    For Logos + Objective-C source code with preprocessor directives.
+    """
+
+    name = 'Logos'
+    aliases = ['logos']
+    filenames = ['*.x', '*.xi', '*.xm', '*.xmi']
+    mimetypes = ['text/x-logos']
+    priority = 0.25
+
+    tokens = {
+        'statements': [
+			(r'(%orig|%log)\b', Keyword),
+			(r'(%c)\b(\()(\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\))',
+			bygroups(Keyword, Punctuation, Text, Name.Class, Text, Punctuation)),
+			(r'(%init)\b(\()', bygroups(Keyword, Punctuation), 'logos_init_directive'),
+			(r'(%init)(?=\s*;)', bygroups(Keyword)),
+			(r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)', bygroups(Keyword, Text, Name.Class), '#pop'),
+			(r'(%subclass)(\s+)', bygroups(Keyword, Text),
+			('#pop', 'logos_classname')),
+			inherit,
+        ],
+		'logos_init_directive' : [
+			('\s+', Text),
+			(',', Punctuation, ('logos_init_directive', '#pop')),
+			('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(=)(\s*)([^);]*)', bygroups(Name.Class, Text, Punctuation, Text, Text)),
+			('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class),
+			('\)', Punctuation, '#pop'),
+		],
+		'logos_classname' : [
+			('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
+			 bygroups(Name.Class, Text, Name.Class), '#pop'),
+			('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
+		],
+		'root': [
+			(r'(%subclass)(\s+)', bygroups(Keyword, Text),
+			 'logos_classname'),
+			(r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)', bygroups(Keyword, Text, Name.Class)),
+			(r'(%config)(\s*\(\s*)(\w+)(\s*=\s*)(.*?)(\s*\)\s*)', bygroups(Keyword, Text, Name.Variable, Text, String, Text)),
+			(r'(%ctor)(\s*)({)', bygroups(Keyword, Text, Punctuation),
+			 'function'),
+			(r'(%new)(\s*)(\()(\s*.*?\s*)(\))', bygroups(Keyword, Text, Keyword, String, Keyword)),
+			(r'(\s*)(%end)(\s*)', bygroups(Text, Keyword, Text)),
+			inherit,
+		],
+    }
+
+    _logos_keywords = re.compile(r'%(?:hook|ctor|init|c\()')
+
+    def analyse_text(text):
+        if _logos_keywords.search(text):
+            return 1.0
+        return 0
+     

tests/examplefiles/logos_example.xm

+%hook ABC
+- (id)a:(B)b {
+	%log;
+	return %orig(nil);
+}
+%end
+
+%subclass DEF: NSObject
+- (id)init {
+	[%c(RuntimeAccessibleClass) alloc];
+	return nil;
+}
+%end
+
+%group OptionalHooks
+%hook ABC
+- (void)release {
+	[self retain];
+	%orig;
+}
+%end
+%end
+
+%ctor {
+	%init;
+	if(OptionalCondition)
+		%init(OptionalHooks);
+}
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.