julia.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export var conf = {
  6. brackets: [
  7. ['{', '}'],
  8. ['[', ']'],
  9. ['(', ')']
  10. ],
  11. autoClosingPairs: [
  12. { open: '{', close: '}' },
  13. { open: '[', close: ']' },
  14. { open: '(', close: ')' },
  15. { open: '"', close: '"' },
  16. { open: "'", close: "'" }
  17. ],
  18. surroundingPairs: [
  19. { open: '{', close: '}' },
  20. { open: '[', close: ']' },
  21. { open: '(', close: ')' },
  22. { open: '"', close: '"' },
  23. { open: "'", close: "'" }
  24. ]
  25. };
  26. export var language = {
  27. tokenPostfix: '.julia',
  28. keywords: [
  29. 'begin',
  30. 'while',
  31. 'if',
  32. 'for',
  33. 'try',
  34. 'return',
  35. 'break',
  36. 'continue',
  37. 'function',
  38. 'macro',
  39. 'quote',
  40. 'let',
  41. 'local',
  42. 'global',
  43. 'const',
  44. 'do',
  45. 'struct',
  46. 'module',
  47. 'baremodule',
  48. 'using',
  49. 'import',
  50. 'export',
  51. 'end',
  52. 'else',
  53. 'elseif',
  54. 'catch',
  55. 'finally',
  56. 'mutable',
  57. 'primitive',
  58. 'abstract',
  59. 'type',
  60. 'in',
  61. 'isa',
  62. 'where',
  63. 'new'
  64. ],
  65. types: [
  66. 'LinRange',
  67. 'LineNumberNode',
  68. 'LinearIndices',
  69. 'LoadError',
  70. 'MIME',
  71. 'Matrix',
  72. 'Method',
  73. 'MethodError',
  74. 'Missing',
  75. 'MissingException',
  76. 'Module',
  77. 'NTuple',
  78. 'NamedTuple',
  79. 'Nothing',
  80. 'Number',
  81. 'OrdinalRange',
  82. 'OutOfMemoryError',
  83. 'OverflowError',
  84. 'Pair',
  85. 'PartialQuickSort',
  86. 'PermutedDimsArray',
  87. 'Pipe',
  88. 'Ptr',
  89. 'QuoteNode',
  90. 'Rational',
  91. 'RawFD',
  92. 'ReadOnlyMemoryError',
  93. 'Real',
  94. 'ReentrantLock',
  95. 'Ref',
  96. 'Regex',
  97. 'RegexMatch',
  98. 'RoundingMode',
  99. 'SegmentationFault',
  100. 'Set',
  101. 'Signed',
  102. 'Some',
  103. 'StackOverflowError',
  104. 'StepRange',
  105. 'StepRangeLen',
  106. 'StridedArray',
  107. 'StridedMatrix',
  108. 'StridedVecOrMat',
  109. 'StridedVector',
  110. 'String',
  111. 'StringIndexError',
  112. 'SubArray',
  113. 'SubString',
  114. 'SubstitutionString',
  115. 'Symbol',
  116. 'SystemError',
  117. 'Task',
  118. 'Text',
  119. 'TextDisplay',
  120. 'Timer',
  121. 'Tuple',
  122. 'Type',
  123. 'TypeError',
  124. 'TypeVar',
  125. 'UInt',
  126. 'UInt128',
  127. 'UInt16',
  128. 'UInt32',
  129. 'UInt64',
  130. 'UInt8',
  131. 'UndefInitializer',
  132. 'AbstractArray',
  133. 'UndefKeywordError',
  134. 'AbstractChannel',
  135. 'UndefRefError',
  136. 'AbstractChar',
  137. 'UndefVarError',
  138. 'AbstractDict',
  139. 'Union',
  140. 'AbstractDisplay',
  141. 'UnionAll',
  142. 'AbstractFloat',
  143. 'UnitRange',
  144. 'AbstractIrrational',
  145. 'Unsigned',
  146. 'AbstractMatrix',
  147. 'AbstractRange',
  148. 'Val',
  149. 'AbstractSet',
  150. 'Vararg',
  151. 'AbstractString',
  152. 'VecElement',
  153. 'AbstractUnitRange',
  154. 'VecOrMat',
  155. 'AbstractVecOrMat',
  156. 'Vector',
  157. 'AbstractVector',
  158. 'VersionNumber',
  159. 'Any',
  160. 'WeakKeyDict',
  161. 'ArgumentError',
  162. 'WeakRef',
  163. 'Array',
  164. 'AssertionError',
  165. 'BigFloat',
  166. 'BigInt',
  167. 'BitArray',
  168. 'BitMatrix',
  169. 'BitSet',
  170. 'BitVector',
  171. 'Bool',
  172. 'BoundsError',
  173. 'CapturedException',
  174. 'CartesianIndex',
  175. 'CartesianIndices',
  176. 'Cchar',
  177. 'Cdouble',
  178. 'Cfloat',
  179. 'Channel',
  180. 'Char',
  181. 'Cint',
  182. 'Cintmax_t',
  183. 'Clong',
  184. 'Clonglong',
  185. 'Cmd',
  186. 'Colon',
  187. 'Complex',
  188. 'ComplexF16',
  189. 'ComplexF32',
  190. 'ComplexF64',
  191. 'CompositeException',
  192. 'Condition',
  193. 'Cptrdiff_t',
  194. 'Cshort',
  195. 'Csize_t',
  196. 'Cssize_t',
  197. 'Cstring',
  198. 'Cuchar',
  199. 'Cuint',
  200. 'Cuintmax_t',
  201. 'Culong',
  202. 'Culonglong',
  203. 'Cushort',
  204. 'Cvoid',
  205. 'Cwchar_t',
  206. 'Cwstring',
  207. 'DataType',
  208. 'DenseArray',
  209. 'DenseMatrix',
  210. 'DenseVecOrMat',
  211. 'DenseVector',
  212. 'Dict',
  213. 'DimensionMismatch',
  214. 'Dims',
  215. 'DivideError',
  216. 'DomainError',
  217. 'EOFError',
  218. 'Enum',
  219. 'ErrorException',
  220. 'Exception',
  221. 'ExponentialBackOff',
  222. 'Expr',
  223. 'Float16',
  224. 'Float32',
  225. 'Float64',
  226. 'Function',
  227. 'GlobalRef',
  228. 'HTML',
  229. 'IO',
  230. 'IOBuffer',
  231. 'IOContext',
  232. 'IOStream',
  233. 'IdDict',
  234. 'IndexCartesian',
  235. 'IndexLinear',
  236. 'IndexStyle',
  237. 'InexactError',
  238. 'InitError',
  239. 'Int',
  240. 'Int128',
  241. 'Int16',
  242. 'Int32',
  243. 'Int64',
  244. 'Int8',
  245. 'Integer',
  246. 'InterruptException',
  247. 'InvalidStateException',
  248. 'Irrational',
  249. 'KeyError'
  250. ],
  251. keywordops: ['<:', '>:', ':', '=>', '...', '.', '->', '?'],
  252. allops: /[^\w\d\s()\[\]{}"'#]+/,
  253. constants: [
  254. 'true',
  255. 'false',
  256. 'nothing',
  257. 'missing',
  258. 'undef',
  259. 'Inf',
  260. 'pi',
  261. 'NaN',
  262. 'π',
  263. 'ℯ',
  264. 'ans',
  265. 'PROGRAM_FILE',
  266. 'ARGS',
  267. 'C_NULL',
  268. 'VERSION',
  269. 'DEPOT_PATH',
  270. 'LOAD_PATH'
  271. ],
  272. operators: [
  273. '!',
  274. '!=',
  275. '!==',
  276. '%',
  277. '&',
  278. '*',
  279. '+',
  280. '-',
  281. '/',
  282. '//',
  283. '<',
  284. '<<',
  285. '<=',
  286. '==',
  287. '===',
  288. '=>',
  289. '>',
  290. '>=',
  291. '>>',
  292. '>>>',
  293. '\\',
  294. '^',
  295. '|',
  296. '|>',
  297. '~',
  298. '÷',
  299. '∈',
  300. '∉',
  301. '∋',
  302. '∌',
  303. '∘',
  304. '√',
  305. '∛',
  306. '∩',
  307. '∪',
  308. '≈',
  309. '≉',
  310. '≠',
  311. '≡',
  312. '≢',
  313. '≤',
  314. '≥',
  315. '⊆',
  316. '⊇',
  317. '⊈',
  318. '⊉',
  319. '⊊',
  320. '⊋',
  321. '⊻'
  322. ],
  323. brackets: [
  324. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  325. { open: '{', close: '}', token: 'delimiter.curly' },
  326. { open: '[', close: ']', token: 'delimiter.square' }
  327. ],
  328. ident: /π|ℯ|\b(?!\d)\w+\b/,
  329. // escape sequences
  330. escape: /(?:[abefnrstv\\"'\n\r]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4})/,
  331. escapes: /\\(?:C\-(@escape|.)|c(@escape|.)|@escape)/,
  332. // The main tokenizer for our languages
  333. tokenizer: {
  334. root: [
  335. [/(::)\s*|\b(isa)\s+/, 'keyword', '@typeanno'],
  336. [/\b(isa)(\s*\(@ident\s*,\s*)/, ['keyword', { token: '', next: '@typeanno' }]],
  337. [/\b(type|struct)[ \t]+/, 'keyword', '@typeanno'],
  338. // symbols
  339. [/^\s*:@ident[!?]?/, 'metatag'],
  340. [/(return)(\s*:@ident[!?]?)/, ['keyword', 'metatag']],
  341. [/(\(|\[|\{|@allops)(\s*:@ident[!?]?)/, ['', 'metatag']],
  342. [/:\(/, 'metatag', '@quote'],
  343. // regular expressions
  344. [/r"""/, 'regexp.delim', '@tregexp'],
  345. [/r"/, 'regexp.delim', '@sregexp'],
  346. // strings
  347. [/raw"""/, 'string.delim', '@rtstring'],
  348. [/[bv]?"""/, 'string.delim', '@dtstring'],
  349. [/raw"/, 'string.delim', '@rsstring'],
  350. [/[bv]?"/, 'string.delim', '@dsstring'],
  351. [
  352. /(@ident)\{/,
  353. {
  354. cases: {
  355. '$1@types': { token: 'type', next: '@gen' },
  356. '@default': { token: 'type', next: '@gen' }
  357. }
  358. }
  359. ],
  360. [
  361. /@ident[!?'']?(?=\.?\()/,
  362. {
  363. cases: {
  364. '@types': 'type',
  365. '@keywords': 'keyword',
  366. '@constants': 'variable',
  367. '@default': 'keyword.flow'
  368. }
  369. }
  370. ],
  371. [
  372. /@ident[!?']?/,
  373. {
  374. cases: {
  375. '@types': 'type',
  376. '@keywords': 'keyword',
  377. '@constants': 'variable',
  378. '@default': 'identifier'
  379. }
  380. }
  381. ],
  382. [/\$\w+/, 'key'],
  383. [/\$\(/, 'key', '@paste'],
  384. [/@@@ident/, 'annotation'],
  385. // whitespace
  386. { include: '@whitespace' },
  387. // characters
  388. [/'(?:@escapes|.)'/, 'string.character'],
  389. // delimiters and operators
  390. [/[()\[\]{}]/, '@brackets'],
  391. [
  392. /@allops/,
  393. {
  394. cases: {
  395. '@keywordops': 'keyword',
  396. '@operators': 'operator'
  397. }
  398. }
  399. ],
  400. [/[;,]/, 'delimiter'],
  401. // numbers
  402. [/0[xX][0-9a-fA-F](_?[0-9a-fA-F])*/, 'number.hex'],
  403. [/0[_oO][0-7](_?[0-7])*/, 'number.octal'],
  404. [/0[bB][01](_?[01])*/, 'number.binary'],
  405. [/[+\-]?\d+(\.\d+)?(im?|[eE][+\-]?\d+(\.\d+)?)?/, 'number']
  406. ],
  407. // type
  408. typeanno: [
  409. [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*\{/, 'type', '@gen'],
  410. [/([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(\s*<:\s*)/, ['type', 'keyword']],
  411. [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*/, 'type', '@pop'],
  412. ['', '', '@pop']
  413. ],
  414. // generic type
  415. gen: [
  416. [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*\{/, 'type', '@push'],
  417. [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*/, 'type'],
  418. [/<:/, 'keyword'],
  419. [/(\})(\s*<:\s*)/, ['type', { token: 'keyword', next: '@pop' }]],
  420. [/\}/, 'type', '@pop'],
  421. { include: '@root' }
  422. ],
  423. // $(...)
  424. quote: [
  425. [/\$\(/, 'key', '@paste'],
  426. [/\(/, '@brackets', '@paren'],
  427. [/\)/, 'metatag', '@pop'],
  428. { include: '@root' }
  429. ],
  430. // :(...)
  431. paste: [
  432. [/:\(/, 'metatag', '@quote'],
  433. [/\(/, '@brackets', '@paren'],
  434. [/\)/, 'key', '@pop'],
  435. { include: '@root' }
  436. ],
  437. // (...)
  438. paren: [
  439. [/\$\(/, 'key', '@paste'],
  440. [/:\(/, 'metatag', '@quote'],
  441. [/\(/, '@brackets', '@push'],
  442. [/\)/, '@brackets', '@pop'],
  443. { include: '@root' }
  444. ],
  445. // r"egex string"
  446. sregexp: [
  447. [/^.*/, 'invalid'],
  448. [/[^\\"()\[\]{}]/, 'regexp'],
  449. [/[()\[\]{}]/, '@brackets'],
  450. [/\\./, 'operator.scss'],
  451. [/"[imsx]*/, 'regexp.delim', '@pop']
  452. ],
  453. tregexp: [
  454. [/[^\\"()\[\]{}]/, 'regexp'],
  455. [/[()\[\]{}]/, '@brackets'],
  456. [/\\./, 'operator.scss'],
  457. [/"(?!"")/, 'string'],
  458. [/"""[imsx]*/, 'regexp.delim', '@pop']
  459. ],
  460. // raw"string"
  461. rsstring: [
  462. [/^.*/, 'invalid'],
  463. [/[^\\"]/, 'string'],
  464. [/\\./, 'string.escape'],
  465. [/"/, 'string.delim', '@pop']
  466. ],
  467. rtstring: [
  468. [/[^\\"]/, 'string'],
  469. [/\\./, 'string.escape'],
  470. [/"(?!"")/, 'string'],
  471. [/"""/, 'string.delim', '@pop']
  472. ],
  473. // "string".
  474. dsstring: [
  475. [/^.*/, 'invalid'],
  476. [/[^\\"\$]/, 'string'],
  477. [/\$/, '', '@interpolated'],
  478. [/@escapes/, 'string.escape'],
  479. [/\\./, 'string.escape.invalid'],
  480. [/"/, 'string.delim', '@pop']
  481. ],
  482. dtstring: [
  483. [/[^\\"\$]/, 'string'],
  484. [/\$/, '', '@interpolated'],
  485. [/@escapes/, 'string.escape'],
  486. [/\\./, 'string.escape.invalid'],
  487. [/"(?!"")/, 'string'],
  488. [/"""/, 'string.delim', '@pop']
  489. ],
  490. // interpolated sequence
  491. interpolated: [
  492. [/\(/, { token: '', switchTo: '@interpolated_compound' }],
  493. [/[a-zA-Z_]\w*/, 'identifier'],
  494. ['', '', '@pop'] // just a $ is interpreted as a $
  495. ],
  496. // any code
  497. interpolated_compound: [[/\)/, '', '@pop'], { include: '@root' }],
  498. // whitespace & comments
  499. whitespace: [
  500. [/[ \t\r\n]+/, ''],
  501. [/#=/, 'comment', '@multi_comment'],
  502. [/#.*$/, 'comment']
  503. ],
  504. multi_comment: [
  505. [/#=/, 'comment', '@push'],
  506. [/=#/, 'comment', '@pop'],
  507. [/=(?!#)|#(?!=)/, 'comment'],
  508. [/[^#=]+/, 'comment']
  509. ]
  510. }
  511. };