Guest User

Untitled

a guest
Feb 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. { scopeName = 'source.scheme';
  2. comment = '
  3. The foldings do not currently work the way I want them to. This
  4. may be a limitation of the way they are applied rather than the
  5. regexps in use. Nonetheless, the foldings will end on the last
  6. identically indented blank line following an s-expression. Not
  7. ideal perhaps, but it works. Also, the #illegal pattern never
  8. matches an unpaired ( as being illegal. Why?! -- Rob Rix
  9.  
  10. This grammar still needs a bit of work, but I have tried to separate
  11. out disparate parts a bit. -- Jacob Rus
  12. ';
  13. fileTypes = ( 'scm', 'sch' );
  14. foldingStartMarker = '(?x)^ [ \t]* \(
  15. (?<par>
  16. ( [^()\n]++ | \( \g<par> \)? )*+
  17. )
  18. $';
  19. foldingStopMarker = '(?x)^ [ \t]*
  20. (?<par>
  21. ( [^()\n]++ | \( \g<par> \) )*+
  22. )
  23. ( \) [ \t]*+ ) ++
  24. $';
  25. patterns = (
  26. { include = '#comment'; },
  27. { include = '#sexp'; },
  28. { include = '#string'; },
  29. { include = '#language-functions'; },
  30. { include = '#quote'; },
  31. { include = '#illegal'; },
  32. );
  33. repository =
  34. { comment =
  35. { name = 'comment.line.semicolon.scheme';
  36. match = '(;).*$\n?';
  37. captures = { 1 = { name = 'punctuation.definition.comment.semicolon.scheme'; }; };
  38. };
  39. illegal =
  40. { name = 'invalid.illegal.parenthesis.scheme';
  41. match = '[()]';
  42. };
  43. string = {
  44. name = 'string.quoted.double.scheme';
  45. begin = '(")';
  46. end = '(")';
  47. beginCaptures = { 1 = { name = 'punctuation.definition.string.begin.scheme'; }; };
  48. endCaptures = { 1 = { name = 'punctuation.definition.string.end.scheme'; }; };
  49. patterns = (
  50. { name = 'constant.character.escape.scheme';
  51. match = '\\.';
  52. }
  53. );
  54. };
  55. language-functions = {
  56. patterns = (
  57. { name = 'keyword.control.scheme';
  58. match = '(?x)
  59. (?<=(\s|\()) # preceded by space or (
  60. ( do|or|and|else|quasiquote|begin|if|case|set!|
  61. cond|let|unquote|define|let\*|unquote-splicing|delay|
  62. letrec)
  63. (?=(\s|\())';
  64. },
  65. { name = 'support.function.boolean-test.scheme';
  66. comment = '
  67. These functions run a test, and return a boolean
  68. answer.
  69. ';
  70. match = '(?x)
  71. (?<=(\s|\()) # preceded by space or (
  72. ( char-alphabetic|char-lower-case|char-numeric|
  73. char-ready|char-upper-case|char-whitespace|
  74. (?:char|string)(?:-ci)?(?:=|<=?|>=?)|
  75. atom|boolean|bound-identifier=|char|complex|
  76. identifier|integer|symbol|free-identifier=|inexact|
  77. eof-object|exact|list|(?:input|output)-port|pair|
  78. real|rational|zero|vector|negative|odd|null|string|
  79. eq|equal|eqv|even|number|positive|procedure
  80. )
  81. (\?) # name ends with ? sign
  82. (?=(\s|\()) # followed by space or (
  83. ';
  84. },
  85. { name = 'support.function.convert-type.scheme';
  86. comment = '
  87. These functions change one type into another.
  88. ';
  89. match = '(?x)
  90. (?<=(\s|\()) # preceded by space or (
  91. ( char->integer|exact->inexact|inexact->exact|
  92. integer->char|symbol->string|list->vector|
  93. list->string|identifier->symbol|vector->list|
  94. string->list|string->number|string->symbol|
  95. number->string
  96. )
  97. (?=(\s|\()) # followed by space or (
  98. ';
  99. },
  100. { name = 'support.function.with-side-effects.scheme';
  101. comment = '
  102. These functions are potentially dangerous because
  103. they have side-effects which could affect other
  104. parts of the program.
  105. ';
  106. match = '(?x)
  107. (?<=(\s|\()) # preceded by space or (
  108. ( set-(?:car|cdr)| # set car/cdr
  109. (?:vector|string)-(?:fill|set) # fill/set string/vector
  110. )
  111. (!) # name ends with ! sign
  112. (?=(\s|\()) # followed by space or (
  113. ';
  114. },
  115. { name = 'support.function.arithmetic-operators.scheme';
  116. comment = '
  117. +, -, *, /, =, >, etc.
  118. ';
  119. match = '(?x)
  120. (?<=(\s|\()) # preceded by space or (
  121. ( >=?|<=?|=|[*/+-])
  122. (?=(\s|\()) # followed by space or (
  123. ';
  124. },
  125. { name = 'support.function.general.scheme';
  126. match = '(?x)
  127. (?<=(\s|\()) # preceded by space or (
  128. ( append|apply|approximate|
  129. call-with-current-continuation|call/cc|catch|
  130. construct-identifier|define-syntax|display|foo|
  131. for-each|force|cd|gen-counter|gen-loser|
  132. generate-identifier|last-pair|length|let-syntax|
  133. letrec-syntax|list|list-ref|list-tail|load|log|
  134. macro|magnitude|map|map-streams|max|member|memq|
  135. memv|min|newline|nil|not|peek-char|rationalize|
  136. read|read-char|return|reverse|sequence|substring|
  137. syntax|syntax-rules|transcript-off|transcript-on|
  138. truncate|unwrap-syntax|values-list|write|write-char|
  139.  
  140. # cons, car, cdr, etc
  141. cons|c(a|d){1,4}r|
  142.  
  143. # unary math operators
  144. abs|acos|angle|asin|assoc|assq|assv|atan|ceiling|
  145. cos|floor|round|sin|sqrt|tan|
  146. (?:real|imag)-part|numerator|denominator
  147.  
  148. # other math operators
  149. modulo|exp|expt|remainder|quotient|lcm|
  150.  
  151. # ports / files
  152. call-with-(?:input|output)-file|
  153. (?:close|current)-(?:input|output)-port|
  154. with-(?:input|output)-from-file|
  155. open-(?:input|output)-file|
  156.  
  157. # char-«foo»
  158. char-(?:downcase|upcase|ready)|
  159.  
  160. # make-«foo»
  161. make-(?:polar|promise|rectangular|string|vector)
  162.  
  163. # string-«foo», vector-«foo»
  164. string(?:-(?:append|copy|length|ref))?|
  165. vector(?:-length|-ref)
  166. )
  167. (?=(\s|\()) # followed by space or (
  168. ';
  169. },
  170. );
  171. };
  172. constants = {
  173. patterns = (
  174. { name = 'constant.language.boolean.scheme';
  175. match = '#[t|f]';
  176. },
  177. { name = 'constant.other.symbol.scheme';
  178. match = "(')[[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*";
  179. captures = { 1 = { name = 'punctuation.definition.symbol.scheme'; }; };
  180. },
  181. { name = 'constant.numeric.scheme';
  182. match = '(?<=[\(\s])(#e|#i)?[0-9][0-9.]*';
  183. },
  184. { name = 'constant.numeric.scheme';
  185. match = '(?<=[\(\s])(#x)[0-9a-fA-F]+';
  186. },
  187. { name = 'constant.numeric.scheme';
  188. match = '(?<=[\(\s])(#o)[0-7]+';
  189. },
  190. { name = 'constant.numeric.scheme';
  191. match = '(?<=[\(\s])(#b)[01]+';
  192. },
  193. );
  194. };
  195. quote = {
  196. comment = '
  197. We need to be able to quote any kind of item, which creates
  198. a tiny bit of complexity in our grammar. It is hopefully
  199. not overwhelming complexity
  200. ';
  201. patterns = (
  202. { contentName = 'string.other.quoted-object.scheme';
  203. comment = 'quoted double-quoted string';
  204. begin = '('')\s*(?=")';
  205. end = '(?<=")';
  206. beginCaptures = {
  207. 1 = { name = 'punctuation.section.quoted-code.scheme'; };
  208. };
  209. patterns = (
  210. { include = '#quoted'; },
  211. );
  212. },
  213. { contentName = 'string.other.quoted-object.scheme';
  214. comment = 'quoted s-expression';
  215. begin = '('')\s*(?=\()';
  216. end = '(?<=\))';
  217. beginCaptures = {
  218. 1 = { name = 'punctuation.section.quoted-code.scheme'; };
  219. };
  220. patterns = (
  221. { include = '#quoted'; },
  222. );
  223. },
  224. { contentName = 'string.other.quoted-object.scheme';
  225. comment = 'quoted anything else';
  226. begin = '('')\s*(?=[^\s])';
  227. end = '(?<=\s)';
  228. beginCaptures = {
  229. 1 = { name = 'punctuation.section.quoted-code.scheme'; };
  230. };
  231. patterns = (
  232. { include = '#quoted'; },
  233. );
  234. },
  235. { begin = '(?<=\()\s*(quote)\b\s*';
  236. end = '(?=\)|[ ])';
  237. beginCaptures = {
  238. 1 = { name = 'keyword.control.quote.scheme'; };
  239. };
  240. patterns = (
  241. { name = 'string.other.quoted-code.scheme';
  242. comment = 'quoted s-expression';
  243. begin = '(?=\()';
  244. end = '(?<=\))';
  245. patterns = (
  246. { include = '#quoted'; },
  247. );
  248. },
  249. { name = 'string.other.quoted-code.scheme';
  250. comment = 'quoted string';
  251. begin = '(?=")';
  252. end = '(?<=")';
  253. patterns = (
  254. { include = '#quoted'; },
  255. );
  256. },
  257. { name = 'string.other.quoted-code.scheme';
  258. comment = 'quoted anything else';
  259. match = '[^\s()"]+';
  260. },
  261. );
  262. }
  263. );
  264. };
  265. quoted = {
  266. patterns = (
  267. { include = '#string'; },
  268. { name = 'meta.expression.scheme';
  269. begin = '(\()';
  270. end = '(\))(\n)?';
  271. beginCaptures = { 1 = { name = 'punctuation.section.expression.begin.scheme'; }; };
  272. endCaptures =
  273. { 1 = { name = 'punctuation.section.expression.end.scheme'; };
  274. 2 = { name = 'meta.after-expression.scheme'; };
  275. };
  276. patterns = (
  277. { include = '#quoted'; },
  278. );
  279. },
  280. { include = '#quote'; },
  281. { include = '#illegal'; },
  282. );
  283. };
  284. sexp =
  285. { name = 'meta.expression.scheme';
  286. begin = '(\()';
  287. end = '(\))(\n)?';
  288. beginCaptures = { 1 = { name = 'punctuation.section.expression.begin.scheme'; }; };
  289. endCaptures =
  290. { 1 = { name = 'punctuation.section.expression.end.scheme'; };
  291. 2 = { name = 'meta.after-expression.scheme'; };
  292. };
  293. patterns = (
  294. { include = '#comment'; },
  295. { name = 'meta.declaration.procedure.scheme';
  296. begin = '(?x)
  297. (?<=\() # preceded by (
  298. (define)\s+ # define
  299. \( # list of parameters
  300. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)
  301. ((\s+
  302. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._])
  303. )*
  304. )\s*
  305. \)
  306. ';
  307. end = '(?=\))';
  308. captures =
  309. { 1 = { name = 'keyword.other.scheme'; };
  310. 2 = { name = 'entity.name.function.scheme'; };
  311. 3 = { name = 'variable.parameter.function.scheme'; };
  312. };
  313. patterns = (
  314. { include = '#comment'; },
  315. { include = '#sexp'; },
  316. { include = '#illegal'; },
  317. );
  318. },
  319. { name = 'meta.declaration.procedure.scheme';
  320. comment = '
  321. Not sure this one is quite correct. That \s* is
  322. particularly troubling
  323. ';
  324. begin = '(?x)
  325. (?<=\() # preceded by (
  326. (lambda)\s+
  327. (\() # opening paren
  328. ((?:
  329. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._])
  330. \s*
  331. )*)
  332. (\)) # closing paren
  333. ';
  334. end = '(?=\))';
  335. captures =
  336. { 1 = { name = 'keyword.other.scheme'; };
  337. 2 = { name = 'variable.parameter.scheme'; };
  338. };
  339. patterns = (
  340. { include = '#comment'; },
  341. { include = '#sexp'; },
  342. { include = '#illegal'; },
  343. );
  344. },
  345. { name = 'meta.declaration.variable.scheme';
  346. begin = '(?<=\()(define)\s([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)\s*.*?';
  347. end = '(?=\))';
  348. captures =
  349. { 1 = { name = 'keyword.other.scheme'; };
  350. 2 = { name = 'variable.language.scheme'; };
  351. };
  352. patterns = (
  353. { include = '#comment'; },
  354. { include = '#sexp'; },
  355. { include = '#illegal'; },
  356. );
  357. },
  358. { include = '#quote'; },
  359. { include = '#language-functions'; },
  360. { include = '#string'; },
  361. { include = '#constants'; },
  362. { name = 'constant.character.escape.scheme';
  363. match = '(?<=[\(\s])(#\\).';
  364. },
  365. { include = '#sexp'; },
  366. { include = '#illegal'; },
  367. );
  368. };
  369. };
  370. }
Add Comment
Please, Sign In to add comment