smalltalk.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Language: Smalltalk
  3. Description: Smalltalk is an object-oriented, dynamically typed reflective programming language.
  4. Author: Vladimir Gubarkov <xonixx@gmail.com>
  5. Website: https://en.wikipedia.org/wiki/Smalltalk
  6. */
  7. function smalltalk(hljs) {
  8. const VAR_IDENT_RE = '[a-z][a-zA-Z0-9_]*';
  9. const CHAR = {
  10. className: 'string',
  11. begin: '\\$.{1}'
  12. };
  13. const SYMBOL = {
  14. className: 'symbol',
  15. begin: '#' + hljs.UNDERSCORE_IDENT_RE
  16. };
  17. return {
  18. name: 'Smalltalk',
  19. aliases: [ 'st' ],
  20. keywords: 'self super nil true false thisContext', // only 6
  21. contains: [
  22. hljs.COMMENT('"', '"'),
  23. hljs.APOS_STRING_MODE,
  24. {
  25. className: 'type',
  26. begin: '\\b[A-Z][A-Za-z0-9_]*',
  27. relevance: 0
  28. },
  29. {
  30. begin: VAR_IDENT_RE + ':',
  31. relevance: 0
  32. },
  33. hljs.C_NUMBER_MODE,
  34. SYMBOL,
  35. CHAR,
  36. {
  37. // This looks more complicated than needed to avoid combinatorial
  38. // explosion under V8. It effectively means `| var1 var2 ... |` with
  39. // whitespace adjacent to `|` being optional.
  40. begin: '\\|[ ]*' + VAR_IDENT_RE + '([ ]+' + VAR_IDENT_RE + ')*[ ]*\\|',
  41. returnBegin: true,
  42. end: /\|/,
  43. illegal: /\S/,
  44. contains: [ {
  45. begin: '(\\|[ ]*)?' + VAR_IDENT_RE
  46. } ]
  47. },
  48. {
  49. begin: '#\\(',
  50. end: '\\)',
  51. contains: [
  52. hljs.APOS_STRING_MODE,
  53. CHAR,
  54. hljs.C_NUMBER_MODE,
  55. SYMBOL
  56. ]
  57. }
  58. ]
  59. };
  60. }
  61. module.exports = smalltalk;