eric6/ThirdParty/Pygments/pygments/lexers/jvm.py

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
--- a/eric6/ThirdParty/Pygments/pygments/lexers/jvm.py	Tue Apr 21 19:44:19 2020 +0200
+++ b/eric6/ThirdParty/Pygments/pygments/lexers/jvm.py	Tue Apr 21 19:47:10 2020 +0200
@@ -5,7 +5,7 @@
 
     Pygments lexers for JVM languages.
 
-    :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
@@ -21,12 +21,12 @@
 __all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
            'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'ClojureScriptLexer',
            'KotlinLexer', 'XtendLexer', 'AspectJLexer', 'CeylonLexer',
-           'PigLexer', 'GoloLexer', 'JasminLexer']
+           'PigLexer', 'GoloLexer', 'JasminLexer', 'SarlLexer']
 
 
 class JavaLexer(RegexLexer):
     """
-    For `Java <http://www.sun.com/java/>`_ source code.
+    For `Java <https://www.oracle.com/technetwork/java/>`_ source code.
     """
 
     name = 'Java'
@@ -50,7 +50,7 @@
             (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)'  # return arguments
              r'((?:[^\W\d]|\$)[\w$]*)'                  # method name
              r'(\s*)(\()',                              # signature start
-             bygroups(using(this), Name.Function, Text, Operator)),
+             bygroups(using(this), Name.Function, Text, Punctuation)),
             (r'@[^\W\d][\w.]*', Name.Decorator),
             (r'(abstract|const|enum|extends|final|implements|native|private|'
              r'protected|public|static|strictfp|super|synchronized|throws|'
@@ -61,11 +61,14 @@
             (r'(true|false|null)\b', Keyword.Constant),
             (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text),
              'class'),
+            (r'(var)(\s+)', bygroups(Keyword.Declaration, Text),
+             'var'),
             (r'(import(?:\s+static)?)(\s+)', bygroups(Keyword.Namespace, Text),
              'import'),
             (r'"(\\\\|\\"|[^"])*"', String),
             (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
-            (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Operator, Name.Attribute)),
+            (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation,
+                                                     Name.Attribute)),
             (r'^\s*([^\W\d]|\$)[\w$]*:', Name.Label),
             (r'([^\W\d]|\$)[\w$]*', Name),
             (r'([0-9][0-9_]*\.([0-9][0-9_]*)?|'
@@ -80,12 +83,16 @@
             (r'0[bB][01][01_]*[lL]?', Number.Bin),
             (r'0[0-7_]+[lL]?', Number.Oct),
             (r'0|[1-9][0-9_]*[lL]?', Number.Integer),
-            (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
+            (r'[~^*!%&\[\]<>|+=/?-]', Operator),
+            (r'[{}();:.,]', Punctuation),
             (r'\n', Text)
         ],
         'class': [
             (r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop')
         ],
+        'var': [
+            (r'([^\W\d]|\$)[\w$]*', Name, '#pop')
+        ],
         'import': [
             (r'[\w.]+\*?', Name.Namespace, '#pop')
         ],
@@ -104,7 +111,7 @@
     filenames = ['*.aj']
     mimetypes = ['text/x-aspectj']
 
-    aj_keywords = set((
+    aj_keywords = {
         'aspect', 'pointcut', 'privileged', 'call', 'execution',
         'initialization', 'preinitialization', 'handler', 'get', 'set',
         'staticinitialization', 'target', 'args', 'within', 'withincode',
@@ -114,9 +121,9 @@
         'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart',
         'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow',
         'pertypewithin', 'lock', 'unlock', 'thisAspectInstance'
-    ))
-    aj_inter_type = set(('parents:', 'warning:', 'error:', 'soft:', 'precedence:'))
-    aj_inter_type_annotation = set(('@type', '@method', '@constructor', '@field'))
+    }
+    aj_inter_type = {'parents:', 'warning:', 'error:', 'soft:', 'precedence:'}
+    aj_inter_type_annotation = {'@type', '@method', '@constructor', '@field'}
 
     def get_tokens_unprocessed(self, text):
         for index, token, value in JavaLexer.get_tokens_unprocessed(self, text):
@@ -264,8 +271,7 @@
             # method names
             (r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'),
             (r'[^\S\n]+', Text),
-            (r'//.*?\n', Comment.Single),
-            (r'/\*', Comment.Multiline, 'comment'),
+            include('comments'),
             (u'@%s' % idrest, Name.Decorator),
             (u'(abstract|ca(?:se|tch)|d(?:ef|o)|e(?:lse|xtends)|'
              u'f(?:inal(?:ly)?|or(?:Some)?)|i(?:f|mplicit)|'
@@ -300,16 +306,17 @@
         ],
         'class': [
             (u'(%s|%s|`[^`]+`)(\\s*)(\\[)' % (idrest, op),
-             bygroups(Name.Class, Text, Operator), 'typeparam'),
+             bygroups(Name.Class, Text, Operator), ('#pop', 'typeparam')),
             (r'\s+', Text),
+            include('comments'),
             (r'\{', Operator, '#pop'),
             (r'\(', Operator, '#pop'),
-            (r'//.*?\n', Comment.Single, '#pop'),
             (u'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'),
         ],
         'type': [
             (r'\s+', Text),
-            (r'<[%:]|>:|[#_]|forSome|type', Keyword),
+            include('comments'),
+            (r'<[%:]|>:|[#_]|\bforSome\b|\btype\b', Keyword),
             (u'([,);}]|=>|=|\u21d2)(\\s*)', bygroups(Operator, Text), '#pop'),
             (r'[({]', Operator, '#push'),
             (u'((?:%s|%s|`[^`]+`)(?:\\.(?:%s|%s|`[^`]+`))*)(\\s*)(\\[)' %
@@ -318,16 +325,21 @@
             (u'((?:%s|%s|`[^`]+`)(?:\\.(?:%s|%s|`[^`]+`))*)(\\s*)$' %
              (idrest, op, idrest, op),
              bygroups(Keyword.Type, Text), '#pop'),
-            (r'//.*?\n', Comment.Single, '#pop'),
             (u'\\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
         ],
         'typeparam': [
-            (r'[\s,]+', Text),
-            (u'<[%:]|=>|>:|[#_\u21D2]|forSome|type', Keyword),
+            (r'\s+', Text),
+            include('comments'),
+            (r',+', Punctuation),
+            (u'<[%:]|=>|>:|[#_\u21D2]|\bforSome\b|\btype\b', Keyword),
             (r'([\])}])', Operator, '#pop'),
             (r'[(\[{]', Operator, '#push'),
             (u'\\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
         ],
+        'comments': [
+            (r'//.*?\n', Comment.Single),
+            (r'/\*', Comment.Multiline, 'comment'),
+        ],
         'comment': [
             (r'[^/*]+', Comment.Multiline),
             (r'/\*', Comment.Multiline, '#push'),
@@ -1006,7 +1018,7 @@
 
     .. versionadded:: 1.5
     """
-
+    
     name = 'Kotlin'
     aliases = ['kotlin']
     filenames = ['*.kt']
@@ -1017,15 +1029,22 @@
     kt_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
                '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf',
                                  'Mn', 'Mc') + ']*')
-    kt_id = '(' + kt_name + '|`' + kt_name + '`)'
+    
+    kt_space_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
+               '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf',
+                                 'Mn', 'Mc', 'Zs') + ',-]*')
+
+    kt_id = '(' + kt_name + '|`' + kt_space_name + '`)'
 
     tokens = {
         'root': [
             (r'^\s*\[.*?\]', Name.Attribute),
             (r'[^\S\n]+', Text),
+            (r'\s+', Text),
             (r'\\\n', Text),  # line continuation
             (r'//.*?\n', Comment.Single),
             (r'/[*].*?[*]/', Comment.Multiline),
+            (r'""".*?"""', String),
             (r'\n', Text),
             (r'::|!!|\?[:.]', Operator),
             (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
@@ -1035,11 +1054,14 @@
             (r"'\\.'|'[^\\]'", String.Char),
             (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|"
              r"0[xX][0-9a-fA-F]+[Ll]?", Number),
-            (r'(class)(\s+)(object)', bygroups(Keyword, Text, Keyword)),
+            (r'(object)(\s+)(:)(\s+)', bygroups(Keyword, Text, Punctuation, Text), 'class'),
+            (r'(companion)(\s+)(object)', bygroups(Keyword, Text, Keyword)),
             (r'(class|interface|object)(\s+)', bygroups(Keyword, Text), 'class'),
             (r'(package|import)(\s+)', bygroups(Keyword, Text), 'package'),
+            (r'(val|var)(\s+)([(])', bygroups(Keyword, Text, Punctuation), 'property_dec'),
             (r'(val|var)(\s+)', bygroups(Keyword, Text), 'property'),
             (r'(fun)(\s+)', bygroups(Keyword, Text), 'function'),
+            (r'(inline fun)(\s+)', bygroups(Keyword, Text), 'function'),
             (r'(abstract|annotation|as|break|by|catch|class|companion|const|'
              r'constructor|continue|crossinline|data|do|dynamic|else|enum|'
              r'external|false|final|finally|for|fun|get|if|import|in|infix|'
@@ -1058,9 +1080,26 @@
         'property': [
             (kt_id, Name.Property, '#pop')
         ],
+        'property_dec': [
+            (r'(,)(\s*)', bygroups(Punctuation, Text)),
+            (r'(:)(\s*)', bygroups(Punctuation, Text)),
+            (r'<', Punctuation, 'generic'),
+            (r'([)])', Punctuation, '#pop'),
+            (kt_id, Name.Property)
+        ],
         'function': [
+            (r'<', Punctuation, 'generic'),
+            (r''+kt_id+'([.])'+kt_id, bygroups(Name.Class, Punctuation, Name.Function), '#pop'),
             (kt_id, Name.Function, '#pop')
         ],
+        'generic': [
+            (r'(>)(\s*)', bygroups(Punctuation, Text), '#pop'),
+            (r':',Punctuation),
+            (r'(reified|out|in)\b', Keyword),
+            (r',',Text),
+            (r'\s+',Text),
+            (kt_id,Name)
+        ]
     }
 
 
@@ -1571,3 +1610,57 @@
                      re.MULTILINE):
             score += 0.6
         return score
+
+
+class SarlLexer(RegexLexer):
+	"""
+	For `SARL <http://www.sarl.io>`_ source code.
+	
+	.. versionadded:: 2.4
+	"""
+	
+	name = 'SARL'
+	aliases = ['sarl']
+	filenames = ['*.sarl']
+	mimetypes = ['text/x-sarl']
+	
+	flags = re.MULTILINE | re.DOTALL
+	
+	tokens = {
+		'root': [
+			# method names
+			(r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)'  # return arguments
+			 r'([a-zA-Z_$][\w$]*)'                      # method name
+			 r'(\s*)(\()',                             # signature start
+			 bygroups(using(this), Name.Function, Text, Operator)),
+			(r'[^\S\n]+', Text),
+			(r'//.*?\n', Comment.Single),
+			(r'/\*.*?\*/', Comment.Multiline),
+			(r'@[a-zA-Z_][\w.]*', Name.Decorator),
+			(r'(as|break|case|catch|default|do|else|extends|extension|finally|fires|for|if|implements|instanceof|new|on|requires|return|super|switch|throw|throws|try|typeof|uses|while|with)\b',
+			 Keyword),
+			(r'(abstract|def|dispatch|final|native|override|private|protected|public|static|strictfp|synchronized|transient|val|var|volatile)\b', Keyword.Declaration),
+			 (r'(boolean|byte|char|double|float|int|long|short|void)\b',
+			  Keyword.Type),
+			 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
+			 (r'(false|it|null|occurrence|this|true|void)\b', Keyword.Constant),
+			 (r'(agent|annotation|artifact|behavior|capacity|class|enum|event|interface|skill|space)(\s+)', bygroups(Keyword.Declaration, Text),
+			  'class'),
+			 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
+			 (r'"(\\\\|\\"|[^"])*"', String),
+			 (r"'(\\\\|\\'|[^'])*'", String),
+			 (r'[a-zA-Z_]\w*:', Name.Label),
+			 (r'[a-zA-Z_$]\w*', Name),
+			 (r'[~^*!%&\[\](){}<>\|+=:;,./?-]', Operator),
+			 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
+			 (r'0x[0-9a-fA-F]+', Number.Hex),
+			 (r'[0-9]+L?', Number.Integer),
+			 (r'\n', Text)
+		],
+		'class': [
+			(r'[a-zA-Z_]\w*', Name.Class, '#pop')
+		],
+		'import': [
+			(r'[\w.]+\*?', Name.Namespace, '#pop')
+		],
+	}

eric ide

mercurial