"Masen Furer"  committed 92bcfc3

AdaLexer: fix support for record types

In the previous implementation, a record type would
trigger a descent into 'formal_part' which is
for formal parameter lists in a task, procedure, or function

The 'formal_part' is inappropriate for the record type, which
lists Variable_Name : Variable_Type for all members of the
record, like the declaration section of a procedure.

Now the code can take advantage of highlighting
built-in types for record declarations.

Further, the 'formal_part' only pops on a right paren \)
This doesn't work for record declarations which end with a
'end record'. The previous implementation caused highlighting
inconsistencies after a record declaration because the lexer would
get stuck in 'formal_part' and wouldn't pop on 'end record'

Finally, null records would also exhibit the same behavior
described, however a null record declaration doesn't contain
an 'end record'. It is a shorthand notation which has been
special-cased into 'type_def'.

For a comparison, look at output before and after this commit
on: tests/examplefiles/test.adb

  • Participants
  • Parent commits 2948d38

Comments (0)

Files changed (1)

File pygments/lexers/

             (r'\(', Punctuation, 'formal_part'),
             (r'with|and|use', Keyword.Reserved),
             (r'array\b', Keyword.Reserved, ('#pop', 'array_def')),
-            (r'record\b', Keyword.Reserved, ('formal_part')),
+            (r'record\b', Keyword.Reserved, ('record_def')),
+            (r'(null record)(;)', bygroups(Keyword.Reserved, Punctuation), '#pop'),
         'array_def' : [
+        'record_def' : [
+            (r'end record', Keyword.Reserved, '#pop'),
+            include('root'),
+        ],
         'import': [
             (r'[a-z0-9_.]+', Name.Namespace, '#pop'),
             (r'', Text, '#pop'),