You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.0 KiB

7 months ago
  1. CodeMirror.defineMode("prism", function (config, parserConfig) {
  2. return {
  3. startState: function () {
  4. return {};
  5. },
  6. token: function (stream, state) {
  7. // Skip whitespace
  8. if (stream.eatSpace()) {
  9. return null;
  10. }
  11. // Single-line comments
  12. if (stream.match(/\/\/.*/)) {
  13. return "comment";
  14. }
  15. // Check for module keyword and the identifier after it
  16. if (state.afterModule && stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/)) {
  17. state.afterModule = false;
  18. return "variable"; // Return token type for module names
  19. }
  20. // Check for module keyword and set state to look for identifier
  21. if (stream.match(/\bmodule\b/)) {
  22. state.afterModule = true;
  23. return "keyword"; // Return token type for keywords
  24. }
  25. // Keywords
  26. if (
  27. stream.match(
  28. /\b(?:smg|mdp|dtmc|ctmc|pta|module|endmodule|player|endplayer|system|endsystem|invariant|endrewards|rewards|const|init|min|max|floor|ceil|round|pow|mod|log)\b/
  29. )
  30. ) {
  31. return "keyword";
  32. }
  33. // Constants
  34. if (stream.match(/\b(?:true|false)\b/)) {
  35. return "atom";
  36. }
  37. // Variable types
  38. if (stream.match(/\b(?:bool|double|int)\b/)) {
  39. return "keyword";
  40. }
  41. // Variable definitions
  42. if (stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*\s*(?=[:=!'`])/)) {
  43. return "variable";
  44. }
  45. // Strings
  46. if (stream.match(/"([^"\\]|\\.)*"/)) {
  47. return "string";
  48. }
  49. // Operators
  50. if (stream.match(/[+\-*/|&<>!=]/)) {
  51. return "operator";
  52. }
  53. // Numbers
  54. if (stream.match(/\b\d+(\.\d+)?\b/)) {
  55. return "number";
  56. }
  57. // Handle other characters
  58. stream.next();
  59. return null;
  60. },
  61. startState: function () {
  62. return {
  63. afterModule: false, // Track whether we are looking for an identifier after a module keyword
  64. };
  65. },
  66. };
  67. });
  68. // Register the mode with a MIME type
  69. CodeMirror.defineMIME("text-x/myLanguage", "prism");