Advertisement
Guest User

algorithm.ts

a guest
Jun 11th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import {
  2. JupyterFrontEnd,
  3. JupyterFrontEndPlugin
  4. } from '@jupyterlab/application';
  5.  
  6. import {
  7. IEditorLanguageRegistry
  8. } from '@jupyterlab/codemirror'
  9. import { LanguageSupport, LRLanguage } from '@codemirror/language';
  10.  
  11. import { buildParser } from '@lezer/generator';
  12.  
  13. /**
  14. * Initialization data for the unicodelab-ts extension.
  15. */
  16. export const algorithm_plugin: JupyterFrontEndPlugin<void> = {
  17. id: 'unicodelab-ts:algorithm',
  18. autoStart: true,
  19. // provides: snippetToken, // For providing services
  20. requires: [IEditorLanguageRegistry],
  21. optional: [],
  22. activate: (
  23. app: JupyterFrontEnd,
  24. lang_registry: IEditorLanguageRegistry
  25. ) => {
  26.  
  27. lang_registry.addLanguage({
  28. name: 'algorithm',
  29. mime: 'text/algorithm',
  30. support: new LanguageSupport(
  31. // dummy parser that accepts nothing
  32. LRLanguage.define({
  33. parser: buildParser(`
  34. @top Program { word word* ";" }
  35.  
  36. @tokens {
  37. spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
  38. newline[@export] { $[\r\n\u2028\u2029] }
  39.  
  40. wordLetter { @asciiLetter }
  41.  
  42. word { wordLetter+ }
  43.  
  44. @precedence { spaces, newline, word }
  45.  
  46. ";"
  47. }
  48.  
  49. @external propSource algorithmHighlight from "./highlight.ts"
  50. `)
  51. })
  52. )
  53. });
  54. }
  55. };
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement