home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / TSYNTAX.ZIP / Scripts.ZIP / Cppscript.txt < prev    next >
Encoding:
Text File  |  1998-08-14  |  15.3 KB  |  303 lines

  1. /*
  2.  * TSyntaxMemoParser Script
  3.  * ------------------------
  4.  *
  5.  * Author  :          David Brock / Torbjorn Drevin
  6.  * Date    :          October 18 1997
  7.  * Language:          ANSI C/C++
  8.  */
  9.  
  10. //--------------------------------------------------------------------------------------------------------------------
  11. //
  12. //
  13. //
  14. // Macro definitions. Parameters may be specified and the replacement text terminates with the end of
  15. // line (watch trailing blanks).
  16. //
  17. #define ct_DEFAULT                  0
  18. #define ct_COMMENT_LINE             1
  19. #define ct_COMMENT_STAR             2
  20. #define ct_IDENTIFIER               3
  21. #define ct_STRING                   4
  22. #define ct_NUMBER                   5
  23. #define ct_COMMENT                  6
  24. #define ct_OPERATOR                 7
  25. #define ct_RESERVED                 8
  26. #define ct_CHAR                     9
  27. #define ct_DIRECTIVE                10
  28. #define ct_MISC                     11
  29. #define ct_KEYWORD                  12
  30. #define ct_HEXNUMBER                13
  31.  
  32. #define _non_alpha_                 '[^_A-Za-z0-9]'
  33. #define _all_chars_                 '[\x00-\xFF]'
  34. #define _no_chars_                  '[]'
  35. #define _dont_care_                 _all_chars_
  36. #define _DEFAULT_BACKGROUND         clWhite
  37. #define _DEFAULT_FOREGROUND         clBlack
  38.  
  39.  
  40.  
  41. //--------------------------------------------------------------------------------------------------------------------
  42. //
  43. // %%language section
  44. //
  45. // Header section. Describes the textual name of the language, case sensitivity and options used by the language.
  46. //
  47. %%language
  48. Name                      = 'ANSI C'
  49. Case                      = __SENSITIVE
  50. Options                   = __DEFAULT_OPTIONS
  51. WordWrapColumn            = _EDGE
  52. Gutter                    = _DEFAULT_GUTTER
  53. Anchor                    = _DEFAULT_START_ANCHOR
  54. ExampleText               = '/* Comment */\n\
  55.                             \#include <stdio.h>\n\
  56.                             \char *documentation[] = {\n\
  57.                             \     "String text\\n"}\n\
  58.                             \a >> 2 > 3 ? 4 ? 5\n'
  59.  
  60. EditableStyles              ('Comment',       ct_COMMENT),
  61.                             ('String',        ct_STRING),
  62.                             ('Reserved word', ct_KEYWORD),
  63.                             ('Operator',      ct_MISC),
  64.                             ('Identifier',    ct_IDENTIFIER),
  65.                             ('Directive',     ct_DIRECTIVE),
  66.                             ('Number',        ct_NUMBER),
  67.                             ('Default',       ct_DEFAULT)
  68.  
  69.  
  70.  
  71.  
  72. //--------------------------------------------------------------------------------------------------------------------
  73. //
  74. // %%words section
  75. //
  76. // Used to specify simple languge keywords. These are constant value lexemes that always contain the same characters
  77. // and only require the end style to be specified. The words present here will always be tried first. If they fail
  78. // then the entries in the %%tokens section will be allowed to try a match.
  79. //
  80. // %%words table entries have 3 columns:
  81. //     Column 1          Quoted string giving the characters that make up the word
  82. //     Column 2          Quoted string that specifies how the word is terminated
  83. //     Column 3          Token value returned when word is recognised
  84. //
  85. %%words
  86. '++'                    _dont_care_               ct_OPERATOR
  87. '--'                    _dont_care_               ct_OPERATOR
  88. '+'                     _dont_care_               ct_OPERATOR
  89. '-'                     _dont_care_               ct_OPERATOR
  90. '*'                     _dont_care_               ct_OPERATOR
  91. '/'                     _dont_care_               ct_OPERATOR
  92. '&'                     _dont_care_               ct_OPERATOR
  93. '!'                     _dont_care_               ct_OPERATOR
  94. '~'                     _dont_care_               ct_OPERATOR
  95. '%'                     _dont_care_               ct_OPERATOR
  96. '>'                     _dont_care_               ct_OPERATOR
  97. '<'                     _dont_care_               ct_OPERATOR
  98. '>>'                    _dont_care_               ct_OPERATOR
  99. '<<'                    _dont_care_               ct_OPERATOR
  100. '>='                    _dont_care_               ct_OPERATOR
  101. '<='                    _dont_care_               ct_OPERATOR
  102. '=='                    _dont_care_               ct_OPERATOR
  103. '='                     _dont_care_               ct_OPERATOR
  104. '!='                    _dont_care_               ct_OPERATOR
  105. '^'                     _dont_care_               ct_OPERATOR
  106. '|'                     _dont_care_               ct_OPERATOR
  107. '&&'                    _dont_care_               ct_OPERATOR
  108. '||'                    _dont_care_               ct_OPERATOR
  109. '?'                     _dont_care_               ct_OPERATOR
  110. ':'                     _dont_care_               ct_OPERATOR
  111. '+='                    _dont_care_               ct_OPERATOR
  112. '-='                    _dont_care_               ct_OPERATOR
  113. '*='                    _dont_care_               ct_OPERATOR
  114. '/='                    _dont_care_               ct_OPERATOR
  115. '%='                    _dont_care_               ct_OPERATOR
  116. '>>='                   _dont_care_               ct_OPERATOR
  117. '<<='                   _dont_care_               ct_OPERATOR
  118. '&='                    _dont_care_               ct_OPERATOR
  119. '^='                    _dont_care_               ct_OPERATOR
  120. '|='                    _dont_care_               ct_OPERATOR
  121. ';'                     _dont_care_               ct_MISC
  122. '('                     _dont_care_               ct_MISC
  123. ')'                     _dont_care_               ct_MISC
  124. '['                     _dont_care_               ct_MISC
  125. ']'                     _dont_care_               ct_MISC
  126. '{'                     _dont_care_               ct_MISC
  127. '}'                     _dont_care_               ct_MISC
  128.  
  129. //'"'                   _dont_care_               ct_STRING
  130. //'\''                  _dont_care_               ct_CHAR
  131. '\/*'                   _dont_care_               ct_COMMENT_STAR
  132. '\/\/'                  _dont_care_               ct_COMMENT_LINE
  133. '#'                     _dont_care_               ct_DIRECTIVE
  134. '0'                     '[xX]'                    ct_HEXNUMBER
  135. 'auto'                  _non_alpha_               ct_KEYWORD
  136. 'break'                 _non_alpha_               ct_KEYWORD
  137. 'case'                  _non_alpha_               ct_KEYWORD
  138. 'char'                  _non_alpha_               ct_KEYWORD
  139. 'continue'              _non_alpha_               ct_KEYWORD
  140. 'default'               _non_alpha_               ct_KEYWORD
  141. 'do'                    _non_alpha_               ct_KEYWORD
  142. 'double'                _non_alpha_               ct_KEYWORD
  143. 'else'                  _non_alpha_               ct_KEYWORD
  144. 'entry'                 _non_alpha_               ct_KEYWORD
  145. 'extern'                _non_alpha_               ct_KEYWORD
  146. 'float'                 _non_alpha_               ct_KEYWORD
  147. 'for'                   _non_alpha_               ct_KEYWORD
  148. 'goto'                  _non_alpha_               ct_KEYWORD
  149. 'if'                    _non_alpha_               ct_KEYWORD
  150. 'int'                   _non_alpha_               ct_KEYWORD
  151. 'long'                  _non_alpha_               ct_KEYWORD
  152. 'register'              _non_alpha_               ct_KEYWORD
  153. 'return'                _non_alpha_               ct_KEYWORD
  154. 'short'                 _non_alpha_               ct_KEYWORD
  155. 'sizeof'                _non_alpha_               ct_KEYWORD
  156. 'static'                _non_alpha_               ct_KEYWORD
  157. 'struct'                _non_alpha_               ct_KEYWORD
  158. 'switch'                _non_alpha_               ct_KEYWORD
  159. 'typedef'               _non_alpha_               ct_KEYWORD
  160. 'union'                 _non_alpha_               ct_KEYWORD
  161. 'unsigned'              _non_alpha_               ct_KEYWORD
  162. 'while'                 _non_alpha_               ct_KEYWORD
  163.  
  164. 'based'                 _non_alpha_               ct_KEYWORD
  165. '__cdecl'               _non_alpha_               ct_KEYWORD
  166. 'const'                 _non_alpha_               ct_KEYWORD
  167. 'dllexport'             _non_alpha_               ct_KEYWORD
  168. 'dllimport'             _non_alpha_               ct_KEYWORD
  169. 'enum'                  _non_alpha_               ct_KEYWORD
  170. '__except'              _non_alpha_               ct_KEYWORD
  171. '__export'              _non_alpha_               ct_KEYWORD
  172. '__far'                 _non_alpha_               ct_KEYWORD
  173. '__fastcall'            _non_alpha_               ct_KEYWORD
  174. '__finally'             _non_alpha_               ct_KEYWORD
  175. '__inline'              _non_alpha_               ct_KEYWORD
  176. '__interrupt'           _non_alpha_               ct_KEYWORD
  177. '__leave'               _non_alpha_               ct_KEYWORD
  178. '__near'                _non_alpha_               ct_KEYWORD
  179. '__pascal'              _non_alpha_               ct_KEYWORD
  180. 'signed'                _non_alpha_               ct_KEYWORD
  181. '__stdcall'             _non_alpha_               ct_KEYWORD
  182. '__try'                 _non_alpha_               ct_KEYWORD
  183. 'void'                  _non_alpha_               ct_KEYWORD
  184. 'volatile'              _non_alpha_               ct_KEYWORD
  185. 'class'                 _non_alpha_               ct_KEYWORD
  186. 'delete'                _non_alpha_               ct_KEYWORD
  187. 'friend'                _non_alpha_               ct_KEYWORD
  188. 'inline'                _non_alpha_               ct_KEYWORD
  189. 'new'                   _non_alpha_               ct_KEYWORD
  190. 'operator'              _non_alpha_               ct_KEYWORD
  191. 'private'               _non_alpha_               ct_KEYWORD
  192. 'protected'             _non_alpha_               ct_KEYWORD
  193. 'public'                _non_alpha_               ct_KEYWORD
  194. 'this'                  _non_alpha_               ct_KEYWORD
  195. 'virtual'               _non_alpha_               ct_KEYWORD
  196.  
  197.  
  198. //--------------------------------------------------------------------------------------------------------------------
  199. //
  200. // %%handler section
  201. //
  202. // The %%handler section gives rules to be applied once an entry in the %%words table has been recognised. Normally
  203. // no further processing is required but sometimes a token starts with a fixed set of characters but may be followed
  204. // by a character class rather than a known sequence.
  205. //
  206. // %%handler table entries have 4 columns:
  207. //     Column 1          Token value to be processed
  208. //     Column 2          Character specifier that follows recognised word
  209. //     Column 3          Quoted string specifying end sequence
  210. //     Column 4          Whether end sequence is part of lexeme
  211. //
  212. // The <character specifier> is defined as:
  213. //     Column 2          A single character specifier or pre-defined system character macro:
  214. //                         _PASCAL_CHAR         Pascal style character specifier
  215. //                         _C_CHAR              C style character specifier
  216. //                       If the lexeme can optionally have these characters then append '?' to the end
  217. //                       of the quoted string.
  218. //     Column 3          Up to 2 characters may be given as a sequence to terminate the lexeme.
  219. //                       Characters are specified using a simplified regular expression. If this
  220. //                       string is empty then the lexeme will never be matched.
  221. //
  222. %%handler
  223. ct_COMMENT_LINE         '[^\n]'?                    '\n'           _discard_
  224. ct_COMMENT_STAR         _all_chars_?                '*\/'          _use_
  225. ct_DIRECTIVE            '[^\n]'?                    '\n'           _discard_
  226. ct_HEXNUMBER            '[xX0-9A-Fa-f]'             '[^0-9a-fA-F]' _discard_
  227.  
  228. //--------------------------------------------------------------------------------------------------------------------
  229. //
  230. // %%tokens section
  231. //
  232. // Used to specify how to recognise non-fixed lexemes. Non-fixed lexemes are only tried if the table entries in the
  233. // %%words section have failed. The non-fixed lexeme is defiened by 5 columns as below:
  234. //     Column 1          Token value
  235. //     Column 2          Single start character specifier
  236. //     Column 3          Single contains character specifier
  237. //     Column 4          End sequence specifier
  238. //     Column 5          Whether end sequence is part of lexeme
  239. // Pre-defined token styles are implemented. If used they should be specified in Column 2. The implemented ones
  240. // are:
  241. //  __STD_PASCALSTRING   Pascal string -- starts with ' ands with ' and uses '' to represent
  242. //                       ' within a string. Does not extend beywond end of line.
  243. //  __STD_IDENTIFIER     Standard identifier. Starts with [_a-zA-Z], contains [_a-zA-Z0-9] and ends with
  244. //                       a non-alpha numeric character that is not part of the lexeme
  245. //  __STD_NUMBER_OR_FP   Integer or floating point constant of syntax:
  246. //                           <Digit String> [ '.' <Digit string> ] [ e|E [+-] <Digit string> ]
  247. //
  248. %%tokens
  249. ct_STRING               __STD_C_STRING
  250. ct_CHAR                 __STD_C_CHAR
  251. ct_IDENTIFIER           __STD_IDENTIFIER
  252. ct_NUMBER               __STD_NUMBER_OR_FP
  253.  
  254. //--------------------------------------------------------------------------------------------------------------------
  255. //
  256. // %%effects section
  257. //
  258. // Used to specify the default colors and font styles used for each token
  259. //
  260. //     Column 1          Token value
  261. //     Column 2          Font styles
  262. //     Column 3          Foreground color
  263. //     Column 4          Background color
  264. //     Column 5          Optional column specifying whether map entry is a 'hotspot'
  265. //
  266. // Columns 1-4 must be completed for all rows, Column 5 defaults to non-hotspot.
  267. //
  268. %%effects
  269. ct_DEFAULT              []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  270. ct_IDENTIFIER           []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  271. ct_STRING               [fsItalic]                  clNavy                      _DEFAULT_BACKGROUND
  272. ct_COMMENT              []                          clGreen                     _DEFAULT_BACKGROUND
  273. ct_KEYWORD              [fsBold]                    clBlack                     _DEFAULT_BACKGROUND
  274. ct_NUMBER               []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  275. ct_DIRECTIVE            []                          clNavy                      _DEFAULT_BACKGROUND
  276. ct_MISC                 []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  277.  
  278.  
  279.  
  280. //--------------------------------------------------------------------------------------------------------------------
  281. //
  282. // %%map section
  283. //
  284. // Used to specify which entry in the %%effects table each token value uses. By default all token values map onto
  285. // __DEFAULT_TOKEN which is defined as zero. Table has 2 columns:
  286. //     Column 1          Recognised token value
  287. //     Column 2          Map table entry (i.e. %%effects table entry)
  288. // Normally the %%map table consists of identical value entries.
  289. %%map
  290. ct_IDENTIFIER           ct_IDENTIFIER
  291. ct_STRING               ct_STRING
  292. ct_NUMBER               ct_NUMBER
  293. ct_COMMENT              ct_COMMENT
  294. ct_COMMENT_LINE         ct_COMMENT
  295. ct_COMMENT_STAR         ct_COMMENT
  296. ct_KEYWORD              ct_KEYWORD
  297. ct_MISC                 ct_MISC
  298. ct_DIRECTIVE            ct_DIRECTIVE
  299. ct_CHAR                 ct_STRING
  300. ct_OPERATOR             ct_MISC
  301. ct_HEXNUMBER            ct_NUMBER
  302.  
  303.