File size: 10,765 Bytes
f1ff2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ==========================================================================\
|
|   To learn how to make your own language parser, please check the following
|   link:
|       https://npp-user-manual.org/docs/function-list/
|
\=========================================================================== -->
<NotepadPlus>
	<functionList>
		<!-- ==================================================== [ Pascal ] -->

		<parser
			displayName="Pascal"
			id         ="pascal_syntax"
			commentExpr="(?x)                                                                      # Utilize inline comments (see `RegEx - Pattern Modifiers`)
						   (?m-s:\x2F{2}.*$)                                                       # Single Line Comment
						 | (?s:\x7B.*?\x7D)                                                        # Multi Line Comment 1st variant
						 | (?s:\x28\x2A.*?\x2A\x29)                                                # Multi Line Comment 2nd variant
						 | (?is:^\h*INTERFACE\h*$.*?^\h*IMPLEMENTATION\h*$)                        # Prevent matching procedure/function declarations in interface section of unit
						"
		>
			<classRange
				mainExpr="(?x)                                                                     # Utilize inline comments (see `RegEx - Pattern Modifiers`)
						  (?im-s)                                                                  # multi-line mode on, single-line mode off
						  ^\h*                                                                     # optional leading whitespace
						  (?:                                                                      # indicator that following element exists on class level instead of instance level
							 CLASS\s+
						  )?
						  (?:
							   (?'CONSTRUCTOR_HEADER'                                              # constructor
								 CONSTRUCTOR
							   )
							 | (?'DESTRUCTOR_HEADER'                                               # or destructor
								 DESTRUCTOR
							   )
							 | (?'PROCEDURE_HEADER'                                                # or procedure
								 PROCEDURE
							   )
							 | (?'FUNCTION_HEADER'                                                 # or function
								 FUNCTION
							   )
							 | (?'OPERATOR_HEADER'                                                 # or operator
								 OPERATOR
							   )
						  )\s+
						  (?'CLASS_NAME'                                                           # class/interface name
							(?:
							   [A-Z_]\w*
							   (?:                                                                   # match generic classes too
								 \s*&lt;[^&gt;]+&gt;
							   )?
							   \s*\.\s*
							)+                                                                       # match nested classes too
						  )
						  (?'METHOD_NAME'                                                          # method name
							[A-Z_]\w*
							(?:                                                                      # match generic methods too
							  \s*&lt;[^&gt;]+&gt;
							)?
						  )
						  (?'PARAM_LIST'                                                           # optional parameter list
							\s*\(                                                                    # start-of-parameter-list indicator
							[^()]*                                                                   # parameter list
							\)                                                                       # end-of-parameter-list indicator
						  )?
						  (?('CONSTRUCTOR_HEADER')                                                 # constructors don't have a return type
							\s*
							;                                                                        # end-of-statement indicator
						  )
						  (?('DESTRUCTOR_HEADER')                                                  # destructors don't have a return type
							\s*
							;                                                                        # end-of-statement indicator
						  )
						  (?('PROCEDURE_HEADER')                                                   # procedures don't have a return type
							\s*
							;                                                                        # end-of-statement indicator
						  )
						  (?('FUNCTION_HEADER')                                                    # functions have a return type
							\s*:                                                                     # return type indicator
							\s*[^;]+                                                                 # return type identifier
							;                                                                        # end-of-statement indicator
						  )
						  (?('OPERATOR_HEADER')                                                    # operators have a return type
							\s*:                                                                     # type indicator
							\s*[^;]+                                                                 # type identifier
							;                                                                        # end-of-statement indicator
						  )
						 "
			>
				<className>
					<nameExpr expr="(?i)(?:(CONSTRUCTOR|DESTRUCTOR|PROCEDURE|FUNCTION|OPERATOR)\s+)\K(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)(?:[A-Z_]\w*)" />
					<nameExpr expr="(?i)(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)(?=[A-Z_])" />
					<nameExpr expr="(?i)(?:(?:\s*\.\s*)?[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)+(?!\Z)" />
				</className>
				<function
					mainExpr="(?x)                                                                 # Utilize inline comments (see `RegEx - Pattern Modifiers`)
							  (?im-s)                                                              # multi-line mode on, single-line mode off
							  \s+
							  (                                                                    # class/interface name
								(?:
								   [A-Z_]\w*
								   (?:                                                               # match generic classes too
									 \s*&lt;[^&gt;]+&gt;
								   )?
								   \s*\.\s*
								)+                                                                   # match nested classes too
							  )
							  (                                                                    # method name
								[A-Z_]\w*
								(?:                                                                  # match generic methods too
								   \s*&lt;[^&gt;]+&gt;
								)?
							  )
							  (                                                                    # optional parameter list
								\s*\(                                                                # start-of-parameter-list indicator
								[^()]*                                                               # parameter list
								\)                                                                   # end-of-parameter-list indicator
							  )?
							 "
				>
					<functionName>
						<funcNameExpr expr="(?i)(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)\K(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)(?:\s*\([^()]*\))*" />
						<!-- comment out the following node to display the method with its parameters -->
						<funcNameExpr expr="(?i)(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)(?=\s*|\(|\Z)" />
					</functionName>
				</function>
			</classRange>
			<function
				mainExpr="(?x)                                                                     # Utilize inline comments (see `RegEx - Pattern Modifiers`)
						  (?im-s)                                                                  # multi-line mode on, single-line mode off
						  ^\h*                                                                     # optional leading whitespace
						  (?:
							   (?:
								  PROCEDURE\s+                                                     # procedure
								  ([A-Z_]\w*)\s*                                                     #  name
								  (?:                                                                #  optional parameter list
									\([^()]*\)
								  )?
								  \s*;                                                               #  end-of-statement indicator
							   )
							 | (?:
								  FUNCTION\s+                                                      # or function
								  ([A-Z_]\w*)\s*                                                     # name
								  (?:                                                                # optional parameter list
									\([^()]*\)
								  )?
								  \s*:                                                               # return type indicator
								  \s*[^;]+                                                           # return type identifier
								  ;                                                                  # end-of-statement indicator
							   )
						  )
						  (?:\s*OVERLOAD\s*;)?                                                     # function/procedure overloading
						  (?:\s*INLINE\s*;)?                                                       # function/procedure inlining
						  (?:\s*(?:REGISTER|PASCAL|CDECL|STDCALL|SAFECALL|WINAPI)\s*;)?            # calling convention
						  (?:                                                                      # external function from object file
							   (?:\s*(?:VARARGS)\s*;)                                                # variadic C function with cdecl calling convention
							 | (?:\s*(?:EXTERNAL)\s+[^;]+;)                                          # or normal function
						  )?
						  (?!
							 (?:\s*FORWARD\s*;)                                                    # prevent matching forward declarations in implementation section of unit
						  )
						  (?=                                                                      # only match function/procedure definitions
							 (?:\s*
								(?:                                                                  # optional comment
									 (?s:\x7B.*?\x7D)                                                  #     multi line comment 1st variant
								   | (?s:\x28\x2A.*?\x2A\x29)                                          # or  multi line comment 2nd variant
								   | (?-s:\x2F{2}.*$)                                                  # or single line comment
								)
							 )*
							 \s*(?:CONST|TYPE|VAR|LABEL|BEGIN|(?R))\s*                               # declaration block
						  )
						 "
			>
				<functionName>
					<nameExpr expr="(?i)(?:(PROCEDURE|FUNCTION)\s+)\K(?:[A-Z_]\w*)(?:\s*\([^()]*\))*" />
					<!-- comment out the following node to display the routine with its parameters -->
					<nameExpr expr="(?i)(?:[A-Z_]\w*)(?=\s*|\(|$)" />
				</functionName>
			</function>
		</parser>
	</functionList>
</NotepadPlus>