prism-pascal.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Based on Free Pascal
  2. /* TODO
  3. Support inline asm ?
  4. */
  5. Prism.languages.pascal = {
  6. 'directive': {
  7. pattern: /\{\$[\s\S]*?\}/,
  8. greedy: true,
  9. alias: ['marco', 'property']
  10. },
  11. 'comment': {
  12. pattern: /\(\*[\s\S]*?\*\)|\{[\s\S]*?\}|\/\/.*/,
  13. greedy: true
  14. },
  15. 'string': {
  16. pattern: /(?:'(?:''|[^'\r\n])*'(?!')|#[&$%]?[a-f\d]+)+|\^[a-z]/i,
  17. greedy: true
  18. },
  19. 'asm': {
  20. pattern: /(\basm\b)[\s\S]+?(?=\bend\s*[;[])/i,
  21. lookbehind: true,
  22. greedy: true,
  23. inside: null // see below
  24. },
  25. 'keyword': [
  26. {
  27. // Turbo Pascal
  28. pattern: /(^|[^&])\b(?:absolute|array|asm|begin|case|const|constructor|destructor|do|downto|else|end|file|for|function|goto|if|implementation|inherited|inline|interface|label|nil|object|of|operator|packed|procedure|program|record|reintroduce|repeat|self|set|string|then|to|type|unit|until|uses|var|while|with)\b/i,
  29. lookbehind: true
  30. },
  31. {
  32. // Free Pascal
  33. pattern: /(^|[^&])\b(?:dispose|exit|false|new|true)\b/i,
  34. lookbehind: true
  35. },
  36. {
  37. // Object Pascal
  38. pattern: /(^|[^&])\b(?:class|dispinterface|except|exports|finalization|finally|initialization|inline|library|on|out|packed|property|raise|resourcestring|threadvar|try)\b/i,
  39. lookbehind: true
  40. },
  41. {
  42. // Modifiers
  43. pattern: /(^|[^&])\b(?:absolute|abstract|alias|assembler|bitpacked|break|cdecl|continue|cppdecl|cvar|default|deprecated|dynamic|enumerator|experimental|export|external|far|far16|forward|generic|helper|implements|index|interrupt|iochecks|local|message|name|near|nodefault|noreturn|nostackframe|oldfpccall|otherwise|overload|override|pascal|platform|private|protected|public|published|read|register|reintroduce|result|safecall|saveregisters|softfloat|specialize|static|stdcall|stored|strict|unaligned|unimplemented|varargs|virtual|write)\b/i,
  44. lookbehind: true
  45. }
  46. ],
  47. 'number': [
  48. // Hexadecimal, octal and binary
  49. /(?:[&%]\d+|\$[a-f\d]+)/i,
  50. // Decimal
  51. /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?/i
  52. ],
  53. 'operator': [
  54. /\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=]/,
  55. {
  56. pattern: /(^|[^&])\b(?:and|as|div|exclude|in|include|is|mod|not|or|shl|shr|xor)\b/,
  57. lookbehind: true
  58. }
  59. ],
  60. 'punctuation': /\(\.|\.\)|[()\[\]:;,.]/
  61. };
  62. Prism.languages.pascal.asm.inside = Prism.languages.extend('pascal', {
  63. 'asm': undefined,
  64. 'keyword': undefined,
  65. 'operator': undefined
  66. });
  67. Prism.languages.objectpascal = Prism.languages.pascal;