delphi.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.highlight.languages.delphi"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.highlight.languages.delphi"] = true;
  8. dojo.provide("dojox.highlight.languages.delphi");
  9. dojo.require("dojox.highlight._base");
  10. (function(){
  11. var DELPHI_KEYWORDS = {
  12. 'and': 1, 'safecall': 1, 'cdecl': 1, 'then': 1, 'string': 1,
  13. 'exports': 1, 'library': 1, 'not': 1, 'pascal': 1, 'set': 1,
  14. 'virtual': 1, 'file': 1, 'in': 1, 'array': 1, 'label': 1, 'packed': 1,
  15. 'end.': 1, 'index': 1, 'while': 1, 'const': 1, 'raise': 1, 'for': 1,
  16. 'to': 1, 'implementation': 1, 'with': 1, 'except': 1, 'overload': 1,
  17. 'destructor': 1, 'downto': 1, 'finally': 1, 'program': 1, 'exit': 1,
  18. 'unit': 1, 'inherited': 1, 'override': 1, 'if': 1, 'type': 1,
  19. 'until': 1, 'function': 1, 'do': 1, 'begin': 1, 'repeat': 1, 'goto': 1,
  20. 'nil': 1, 'far': 1, 'initialization': 1, 'object': 1, 'else': 1,
  21. 'var': 1, 'uses': 1, 'external': 1, 'resourcestring': 1,
  22. 'interface': 1, 'end': 1, 'finalization': 1, 'class': 1, 'asm': 1,
  23. 'mod': 1, 'case': 1, 'on': 1, 'shr': 1, 'shl': 1, 'of': 1,
  24. 'register': 1, 'xorwrite': 1, 'threadvar': 1, 'try': 1, 'record': 1,
  25. 'near': 1, 'stored': 1, 'constructor': 1, 'stdcall': 1, 'inline': 1,
  26. 'div': 1, 'out': 1, 'or': 1, 'procedure': 1
  27. };
  28. var DELPHI_CLASS_KEYWORDS = {
  29. 'safecall': 1, 'stdcall': 1, 'pascal': 1, 'stored': 1, 'const': 1,
  30. 'implementation': 1, 'finalization': 1, 'except': 1, 'to': 1,
  31. 'finally': 1, 'program': 1, 'inherited': 1, 'override': 1, 'then': 1,
  32. 'exports': 1, 'string': 1, 'read': 1, 'not': 1, 'mod': 1, 'shr': 1,
  33. 'try': 1, 'div': 1, 'shl': 1, 'set': 1, 'library': 1, 'message': 1,
  34. 'packed': 1, 'index': 1, 'for': 1, 'near': 1, 'overload': 1,
  35. 'label': 1, 'downto': 1, 'exit': 1, 'public': 1, 'goto': 1,
  36. 'interface': 1, 'asm': 1, 'on': 1, 'of': 1, 'constructor': 1, 'or': 1,
  37. 'private': 1, 'array': 1, 'unit': 1, 'raise': 1, 'destructor': 1,
  38. 'var': 1, 'type': 1, 'until': 1, 'function': 1, 'else': 1,
  39. 'external': 1, 'with': 1, 'case': 1, 'default': 1, 'record': 1,
  40. 'while': 1, 'protected': 1, 'property': 1, 'procedure': 1,
  41. 'published': 1, 'and': 1, 'cdecl': 1, 'do': 1, 'threadvar': 1,
  42. 'file': 1, 'in': 1, 'if': 1, 'end': 1, 'virtual': 1, 'write': 1,
  43. 'far': 1, 'out': 1, 'begin': 1, 'repeat': 1, 'nil': 1,
  44. 'initialization': 1, 'object': 1, 'uses': 1, 'resourcestring': 1,
  45. 'class': 1, 'register': 1, 'xorwrite': 1, 'inline': 1
  46. };
  47. var dh = dojox.highlight, dhc = dh.constants;
  48. dh.languages.delphi = {
  49. defaultMode: {
  50. lexems: [dhc.IDENT_RE],
  51. illegal: '("|\\$[G-Zg-z]|\\/\\*|</)',
  52. contains: ['comment', 'string', 'number', 'function', 'class'],
  53. keywords: DELPHI_KEYWORDS
  54. },
  55. case_insensitive: true,
  56. modes: [
  57. {
  58. className: 'comment',
  59. begin: '{', end: '}'
  60. },
  61. {
  62. className: 'comment',
  63. begin: '\\(\\*', end: '\\*\\)',
  64. relevance: 10
  65. },
  66. dhc.C_LINE_COMMENT_MODE,
  67. {
  68. className: 'number',
  69. begin: dhc.NUMBER_RE, end: '^',
  70. relevance: 0
  71. },
  72. {
  73. className: 'string',
  74. begin: '\'', end: '\'',
  75. contains: ['quote'],
  76. relevance: 0
  77. },
  78. {
  79. className: 'string',
  80. begin: '(#\\d+)+', end: '^'
  81. },
  82. {
  83. className: 'quote',
  84. begin: '\'\'', end: '^'
  85. },
  86. {
  87. className: 'function',
  88. begin: 'function', end: '[:;]',
  89. lexems: [dhc.IDENT_RE],
  90. keywords: {'function': 1},
  91. contains: ['title', 'params', 'comment'],
  92. relevance: 0
  93. },
  94. {
  95. className: 'function',
  96. begin: '(procedure|constructor|destructor)', end: ';',
  97. lexems: [dhc.IDENT_RE],
  98. keywords: {'constructor': 1, 'destructor': 1, 'procedure': 1},
  99. contains: ['title', 'params', 'comment'],
  100. relevance: 10
  101. },
  102. {
  103. className: 'title',
  104. begin: dhc.IDENT_RE, end: '^'
  105. },
  106. {
  107. className: 'params',
  108. begin: '\\(', end: '\\)',
  109. lexems: [dhc.IDENT_RE],
  110. keywords: DELPHI_KEYWORDS,
  111. contains: ['string']
  112. },
  113. {
  114. className: 'class',
  115. begin: '=\\s*class', end: 'end;',
  116. lexems: [dhc.IDENT_RE],
  117. keywords: DELPHI_CLASS_KEYWORDS,
  118. contains: ['string', 'comment', 'function']
  119. }
  120. ]
  121. };
  122. })();
  123. }