pascal.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- ==========================================================================\
  3. |
  4. | To learn how to make your own language parser, please check the following
  5. | link:
  6. | https://npp-user-manual.org/docs/function-list/
  7. |
  8. \=========================================================================== -->
  9. <NotepadPlus>
  10. <functionList>
  11. <!-- ==================================================== [ Pascal ] -->
  12. <parser
  13. displayName="Pascal"
  14. id ="pascal_syntax"
  15. commentExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
  16. (?m-s:\x2F{2}.*$) # Single Line Comment
  17. | (?s:\x7B.*?\x7D) # Multi Line Comment 1st variant
  18. | (?s:\x28\x2A.*?\x2A\x29) # Multi Line Comment 2nd variant
  19. | (?is:^\h*INTERFACE\h*$.*?^\h*IMPLEMENTATION\h*$) # Prevent matching procedure/function declarations in interface section of unit
  20. "
  21. >
  22. <classRange
  23. mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
  24. (?im-s) # multi-line mode on, single-line mode off
  25. ^\h* # optional leading whitespace
  26. (?: # indicator that following element exists on class level instead of instance level
  27. CLASS\s+
  28. )?
  29. (?:
  30. (?'CONSTRUCTOR_HEADER' # constructor
  31. CONSTRUCTOR
  32. )
  33. | (?'DESTRUCTOR_HEADER' # or destructor
  34. DESTRUCTOR
  35. )
  36. | (?'PROCEDURE_HEADER' # or procedure
  37. PROCEDURE
  38. )
  39. | (?'FUNCTION_HEADER' # or function
  40. FUNCTION
  41. )
  42. | (?'OPERATOR_HEADER' # or operator
  43. OPERATOR
  44. )
  45. )\s+
  46. (?'CLASS_NAME' # class/interface name
  47. (?:
  48. [A-Z_]\w*
  49. (?: # match generic classes too
  50. \s*&lt;[^&gt;]+&gt;
  51. )?
  52. \s*\.\s*
  53. )+ # match nested classes too
  54. )
  55. (?'METHOD_NAME' # method name
  56. [A-Z_]\w*
  57. (?: # match generic methods too
  58. \s*&lt;[^&gt;]+&gt;
  59. )?
  60. )
  61. (?'PARAM_LIST' # optional parameter list
  62. \s*\( # start-of-parameter-list indicator
  63. [^()]* # parameter list
  64. \) # end-of-parameter-list indicator
  65. )?
  66. (?('CONSTRUCTOR_HEADER') # constructors don't have a return type
  67. \s*
  68. ; # end-of-statement indicator
  69. )
  70. (?('DESTRUCTOR_HEADER') # destructors don't have a return type
  71. \s*
  72. ; # end-of-statement indicator
  73. )
  74. (?('PROCEDURE_HEADER') # procedures don't have a return type
  75. \s*
  76. ; # end-of-statement indicator
  77. )
  78. (?('FUNCTION_HEADER') # functions have a return type
  79. \s*: # return type indicator
  80. \s*[^;]+ # return type identifier
  81. ; # end-of-statement indicator
  82. )
  83. (?('OPERATOR_HEADER') # operators have a return type
  84. \s*: # type indicator
  85. \s*[^;]+ # type identifier
  86. ; # end-of-statement indicator
  87. )
  88. "
  89. >
  90. <className>
  91. <nameExpr expr="(?i)(?:(CONSTRUCTOR|DESTRUCTOR|PROCEDURE|FUNCTION|OPERATOR)\s+)\K(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)(?:[A-Z_]\w*)" />
  92. <nameExpr expr="(?i)(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)(?=[A-Z_])" />
  93. <nameExpr expr="(?i)(?:(?:\s*\.\s*)?[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)+(?!\Z)" />
  94. </className>
  95. <function
  96. mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
  97. (?im-s) # multi-line mode on, single-line mode off
  98. \s+
  99. ( # class/interface name
  100. (?:
  101. [A-Z_]\w*
  102. (?: # match generic classes too
  103. \s*&lt;[^&gt;]+&gt;
  104. )?
  105. \s*\.\s*
  106. )+ # match nested classes too
  107. )
  108. ( # method name
  109. [A-Z_]\w*
  110. (?: # match generic methods too
  111. \s*&lt;[^&gt;]+&gt;
  112. )?
  113. )
  114. ( # optional parameter list
  115. \s*\( # start-of-parameter-list indicator
  116. [^()]* # parameter list
  117. \) # end-of-parameter-list indicator
  118. )?
  119. "
  120. >
  121. <functionName>
  122. <funcNameExpr expr="(?i)(?:(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?\s*\.\s*)+)\K(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)(?:\s*\([^()]*\))*" />
  123. <!-- comment out the following node to display the method with its parameters -->
  124. <funcNameExpr expr="(?i)(?:[A-Z_]\w*(?:\s*&lt;[^&gt;]+&gt;)?)(?=\s*|\(|\Z)" />
  125. </functionName>
  126. </function>
  127. </classRange>
  128. <function
  129. mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
  130. (?im-s) # multi-line mode on, single-line mode off
  131. ^\h* # optional leading whitespace
  132. (?:
  133. (?:
  134. PROCEDURE\s+ # procedure
  135. ([A-Z_]\w*)\s* # name
  136. (?: # optional parameter list
  137. \([^()]*\)
  138. )?
  139. \s*; # end-of-statement indicator
  140. )
  141. | (?:
  142. FUNCTION\s+ # or function
  143. ([A-Z_]\w*)\s* # name
  144. (?: # optional parameter list
  145. \([^()]*\)
  146. )?
  147. \s*: # return type indicator
  148. \s*[^;]+ # return type identifier
  149. ; # end-of-statement indicator
  150. )
  151. )
  152. (?:\s*OVERLOAD\s*;)? # function/procedure overloading
  153. (?:\s*INLINE\s*;)? # function/procedure inlining
  154. (?:\s*(?:REGISTER|PASCAL|CDECL|STDCALL|SAFECALL|WINAPI)\s*;)? # calling convention
  155. (?: # external function from object file
  156. (?:\s*(?:VARARGS)\s*;) # variadic C function with cdecl calling convention
  157. | (?:\s*(?:EXTERNAL)\s+[^;]+;) # or normal function
  158. )?
  159. (?!
  160. (?:\s*FORWARD\s*;) # prevent matching forward declarations in implementation section of unit
  161. )
  162. (?= # only match function/procedure definitions
  163. (?:\s*
  164. (?: # optional comment
  165. (?s:\x7B.*?\x7D) # multi line comment 1st variant
  166. | (?s:\x28\x2A.*?\x2A\x29) # or multi line comment 2nd variant
  167. | (?-s:\x2F{2}.*$) # or single line comment
  168. )
  169. )*
  170. \s*(?:CONST|TYPE|VAR|LABEL|BEGIN|(?R))\s* # declaration block
  171. )
  172. "
  173. >
  174. <functionName>
  175. <nameExpr expr="(?i)(?:(PROCEDURE|FUNCTION)\s+)\K(?:[A-Z_]\w*)(?:\s*\([^()]*\))*" />
  176. <!-- comment out the following node to display the routine with its parameters -->
  177. <nameExpr expr="(?i)(?:[A-Z_]\w*)(?=\s*|\(|$)" />
  178. </functionName>
  179. </function>
  180. </parser>
  181. </functionList>
  182. </NotepadPlus>