diff options
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 128 | ||||
-rw-r--r-- | tests/examplefiles/test.adb | 211 |
4 files changed, 342 insertions, 3 deletions
@@ -7,8 +7,6 @@ Version 1.3 ----------- (in development) -- Gherkin lexer: Fixed single apostrophe bug and added new i18n keywords. - - Lexers added: * Coldfusion @@ -16,6 +14,9 @@ Version 1.3 * R console * Objective-J * Haml and Sass + * Ada + +- Gherkin lexer: Fixed single apostrophe bug and added new i18n keywords. Version 1.2.2 diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index bdd220d7..b8c691f9 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -17,6 +17,7 @@ LEXERS = { 'ABAPLexer': ('pygments.lexers.other', 'ABAP', ('abap',), ('*.abap',), ('text/x-abap',)), 'ActionScript3Lexer': ('pygments.lexers.web', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')), 'ActionScriptLexer': ('pygments.lexers.web', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')), + 'AdaLexer': ('pygments.lexers.compiled', 'Ada', ('ada', 'ada95ada2005'), ('*.adb', '*.ads', '*.ada'), ('text/x-ada',)), 'AntlrActionScriptLexer': ('pygments.lexers.parsers', 'ANTLR With ActionScript Target', ('antlr-as', 'antlr-actionscript'), ('*.G', '*.g'), ()), 'AntlrCSharpLexer': ('pygments.lexers.parsers', 'ANTLR With C# Target', ('antlr-csharp', 'antlr-c#'), ('*.G', '*.g'), ()), 'AntlrCppLexer': ('pygments.lexers.parsers', 'ANTLR With CPP Target', ('antlr-cpp',), ('*.G', '*.g'), ()), diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index cf61e625..4601c12c 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -25,7 +25,7 @@ from pygments.lexers.functional import OcamlLexer __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer', 'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', - 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer'] + 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer'] class CLexer(RegexLexer): @@ -2040,3 +2040,129 @@ class FelixLexer(RegexLexer): include('nl') ], } + + +class AdaLexer(RegexLexer): + """ + For Ada source code. + + *New in Pygments 1.3.* + """ + + name = 'Ada' + aliases = ['ada', 'ada95' 'ada2005'] + filenames = ['*.adb', '*.ads', '*.ada'] + mimetypes = ['text/x-ada'] + + flags = re.MULTILINE | re.I # Ignore case + + _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + + tokens = { + 'root': [ + (r'[^\S\n]+', Text), + (r'--.*?\n', Comment.Single), + (r'[^\S\n]+', Text), + (r'function|procedure|entry', Keyword.Declaration, 'subprogram'), + (r'(subtype|type)(\s+)([a-z0-9_]+)', + bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), + (r'task|protected', Keyword.Declaration), + (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)), + (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'), + (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text, + Comment.Preproc)), + (r'(true|false|null)\b', Keyword.Constant), + (r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|' + r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|' + r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|' + r'Wide_String|Duration)\b', Keyword.Type), + (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word), + (r'generic|private', Keyword.Declaration), + (r'package', Keyword.Declaration, 'package'), + (r'array\b', Keyword.Reserved, 'array_def'), + (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), + (r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)', + bygroups(Name.Constant, Text, Punctuation, Text, + Keyword.Reserved)), + (r'<<[a-z0-9_]+>>', Name.Label), + (r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)', + bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)), + (r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|' + r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|' + r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|' + r'null|of|or|others|out|overriding|pragma|protected|raise|range|' + r'record|renames|requeue|return|reverse|select|separate|subtype|' + r'synchronized|task|tagged|terminate|then|type|until|when|while|' + r'xor)\b', + Keyword.Reserved), + (r'"[^"]*"', String), + include('attribute'), + include('numbers'), + (r"'[^']'", String.Character), + (r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))), + (r"(<>|=>|:=|[\(\)\|:;,.'])", Punctuation), + (r'[*<>+=/&-]', Operator), + (r'\n+', Text), + ], + 'numbers' : [ + (r'[0-9_]+#[0-9a-f]+#', Number.Hex), + (r'[0-9_]+\.[0-9_]*', Number.Float), + (r'[0-9_]+', Number.Integer), + ], + 'attribute' : [ + (r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)), + ], + 'subprogram' : [ + (r'\(', Punctuation, ('#pop', 'formal_part')), + (r';', Punctuation, '#pop'), + (r'is\b', Keyword.Reserved, '#pop'), + (r'"[^"]+"|[a-z0-9_]+', Name.Function), + include('root'), + ], + 'end' : [ + ('(if|case|record|loop|select)', Keyword.Reserved), + ('"[^"]+"|[a-zA-Z0-9_]+', Name.Function), + ('[\n\s]+', Text), + (';', Punctuation, '#pop'), + ], + 'type_def': [ + (r';', Punctuation, '#pop'), + (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')), + include('root'), + ], + 'array_def' : [ + (r';', Punctuation, '#pop'), + (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text, + Keyword.Reserved)), + include('root'), + ], + 'import': [ + (r'[a-z0-9_.]+', Name.Namespace, '#pop'), + ], + 'formal_part' : [ + (r'\)', Punctuation, '#pop'), + (r'([a-z0-9_]+)(\s*)(,|:[^=])', bygroups(Name.Variable, + Text, Punctuation)), + (r'(in|not|null|out|access)\b', Keyword.Reserved), + include('root'), + ], + 'package': [ + ('body', Keyword.Declaration), + ('is\s+new|renames', Keyword.Reserved), + ('is', Keyword.Reserved, '#pop'), + (';', Punctuation, '#pop'), + ('\(', Punctuation, 'package_instantiation'), + ('([a-zA-Z0-9_.]+)', Name.Class), + include('root'), + ], + 'package_instantiation': [ + (r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable, + Text, Punctuation)), + (r'[a-z0-9._\'"]', Text), + (r'\)', Punctuation, '#pop'), + include('root'), + ], + } diff --git a/tests/examplefiles/test.adb b/tests/examplefiles/test.adb new file mode 100644 index 00000000..b79f3a5b --- /dev/null +++ b/tests/examplefiles/test.adb @@ -0,0 +1,211 @@ +-- Model IED Simulator +-- COL Gene Ressler, 1 December 2007 +with Ada.Text_IO; + +with Ada.Characters.Latin_1; +use Ada.Characters.Latin_1; + +with Ada.Strings.Fixed; +use Ada.Strings.Fixed; + +with Ada.Strings; +with Ada.Strings.Bounded; + +with Binary_Search; + +with Ada.Containers.Generic_Array_Sort; + +package body Scanner is + + Constant_123 : constant Character := Character'Val (16#00#); + MAX_KEYWORD_LENGTH_C : constant Natural := 24; + + New_Constant : constant New_Type + := 2; + + KEYWORDS_C : constant Keyword_Array_T := + (To_BS("description"), + To_BS("with")); + + procedure Blah; + + procedure blah is + begin + + Declaration: + declare + Joe : Type_Type := Random; + begin + Do_Something; + end Declaration; + Loop_ID: + loop + Loop_Do; + exit when 1=2; + end loop Loop_ID; + if True or else False then + Do_This(); + elsif not False and then True then + Do_That; + else + Panic; + end if; + end blah; + + function "*" (Left, Right : in Integer) return Integer is + begin + <<Goto_Label>> + goto Goto_Label; + return Left + Right; + end "*"; + + function Function_Specification + (Param_1 : in Blah; + Param2, param3 : in access Blah_Type := 0) + return It_Type; + + package Rename_Check renames Ada.Text_IO; + + type New_Float is delta 0.001 digits 12; + + package Package_Inst is new Ada.Strings.Bounded.Generic_Bounded_Length + (Max => MAX_KEYWORD_LENGTH_C); + + type Array_Decl12 is array (Positive range <>) of SB.Bounded_String; + type Array_Decl3 is array (New_Type range Thing_1 .. Thing_2) of SB.Bounded_String; + + type Boring_Type is + (Start, + End_Error); + + subtype Sub_Type_check is Character range '0' .. '9'; + + Initialized_Array : constant Transistion_Array_T := + (Start => + (Letter_Lower | Letter_Upper => Saw_Alpha, + ' ' | HT | CR | LF => Start, + others => Begin_Error), + + End_Error => (others => Start) + + ); + + type Recorder is record + Advance : Boolean; + Return_Token : Token_T; + end record; + + for Recorder use 8; + + type Null_Record is null record; + + type Discriminated_Record (Size : Natural) is + record + A : String (1 .. Size); + end record; + + pragma Unchecked_Union (Union); + pragma Convention (C, Union); + + type Person is tagged + record + Name : String (1 .. 10); + Gender : Gender_Type; + end record; + + type Programmer is new Person with + record + Skilled_In : Language_List; + Favorite_Langauge : Python_Type; + end record; + + type Programmer is new Person + and Printable + with + record + Skilled_In : Language_List; + Blah : aliased Integer; + end record; + + --------------------- + -- Scan_Next_Token -- + --------------------- + + task Cyclic_Buffer_Task_Type is + entry Insert (An_Item : in Item); + entry Remove (An_Item : out Item); + end Cyclic_Buffer_Task_Type; + + task body Cyclic_Buffer_Task_Type is + Q_Size : constant := 100; + subtype Q_Range is Positive range 1 .. Q_Size; + Length : Natural range 0 .. Q_Size := 0; + Head, Tail : Q_Range := 1; + Data : array (Q_Range) of Item; + begin + loop + select + when Length < Q_Size => + accept Insert (An_Item : in Item) do + Data(Tail) := An_Item; + end Insert; + Tail := Tail mod Q_Size + 1; + Length := Length + 1; + or + when Length > 0 => + accept Remove (An_Item : out Item) do + An_Item := Data(Head); + end Remove; + Head := Head mod Q_Size + 1; + Length := Length - 1; + end select; + end loop; + end Cyclic_Buffer_Task_Type; + + + + procedure Scan_Next_Token + (S : in String; + Start_Index : out Positive; + End_Index : in out Natural; -- Tricky comment + Line_Number : in out Positive; + Token : out Token_T); + + procedure Scan_Next_Token + (S : in String; + Start_Index : out Positive; + End_Index : in out Natural; -- Another comment + Line_Number : in out Positive; + Token : out Token_T) + is + begin + Scanner_Loop: + loop + if New_State = End_Error then + exit Scanner_Loop; + end if; + + if State = Start and New_State /= Start then + Start_Index := Peek_Index; + end if; + end loop Scanner_Loop; + end Scan_Next_Token; + + procedure Advance is + begin + Peek_Index := Peek_Index + 1; + end Advance; + + + -- Eliminate the leading space that Ada puts in front of positive + -- integer images. + function Image(N : in Integer) return String is + S : String := Integer'Image(N); + begin + if S(1) = ' ' then + return S(2 .. S'Last); + end if; + return S; + end Image; + +end Scanner; |