Guest User

Untitled

a guest
Feb 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 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 = '(?<=\([ ]?)(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. begin = '(?=[^\s])';
  260. end = '(?<=\s)';
  261. patterns = (
  262. { include = '#quoted'; },
  263. );
  264. },
  265. );
  266. }
  267. );
  268. };
  269. quoted = {
  270. patterns = (
  271. { include = '#string'; },
  272. { name = 'meta.expression.scheme';
  273. begin = '(\()';
  274. end = '(\))(\n)?';
  275. beginCaptures = { 1 = { name = 'punctuation.section.expression.begin.scheme'; }; };
  276. endCaptures =
  277. { 1 = { name = 'punctuation.section.expression.end.scheme'; };
  278. 2 = { name = 'meta.after-expression.scheme'; };
  279. };
  280. patterns = (
  281. { include = '#quoted'; },
  282. );
  283. },
  284. { include = '#quote'; },
  285. { include = '#illegal'; },
  286. );
  287. };
  288. sexp =
  289. { name = 'meta.expression.scheme';
  290. begin = '(\()';
  291. end = '(\))(\n)?';
  292. beginCaptures = { 1 = { name = 'punctuation.section.expression.begin.scheme'; }; };
  293. endCaptures =
  294. { 1 = { name = 'punctuation.section.expression.end.scheme'; };
  295. 2 = { name = 'meta.after-expression.scheme'; };
  296. };
  297. patterns = (
  298. { include = '#comment'; },
  299. { name = 'meta.declaration.procedure.scheme';
  300. begin = '(?x)
  301. (?<=\() # preceded by (
  302. (define)\s+ # define
  303. \( # list of parameters
  304. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)
  305. ((\s+
  306. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._])
  307. )*
  308. )\s*
  309. \)
  310. ';
  311. end = '(?=\))';
  312. captures =
  313. { 1 = { name = 'keyword.other.scheme'; };
  314. 2 = { name = 'entity.name.function.scheme'; };
  315. 3 = { name = 'variable.parameter.function.scheme'; };
  316. };
  317. patterns = (
  318. { include = '#comment'; },
  319. { include = '#sexp'; },
  320. { include = '#illegal'; },
  321. );
  322. },
  323. { name = 'meta.declaration.procedure.scheme';
  324. comment = '
  325. Not sure this one is quite correct. That \s* is
  326. particularly troubling
  327. ';
  328. begin = '(?x)
  329. (?<=\() # preceded by (
  330. (lambda)\s+
  331. (\() # opening paren
  332. ((?:
  333. ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._])
  334. \s*
  335. )*)
  336. (\)) # closing paren
  337. ';
  338. end = '(?=\))';
  339. captures =
  340. { 1 = { name = 'keyword.other.scheme'; };
  341. 2 = { name = 'variable.parameter.scheme'; };
  342. };
  343. patterns = (
  344. { include = '#comment'; },
  345. { include = '#sexp'; },
  346. { include = '#illegal'; },
  347. );
  348. },
  349. { name = 'meta.declaration.variable.scheme';
  350. begin = '(?<=\()(define)\s([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)\s*.*?';
  351. end = '(?=\))';
  352. captures =
  353. { 1 = { name = 'keyword.other.scheme'; };
  354. 2 = { name = 'variable.language.scheme'; };
  355. };
  356. patterns = (
  357. { include = '#comment'; },
  358. { include = '#sexp'; },
  359. { include = '#illegal'; },
  360. );
  361. },
  362. { include = '#language-functions'; },
  363. { include = '#string'; },
  364. { include = '#constants'; },
  365. { name = 'constant.character.escape.scheme';
  366. match = '(?<=[\(\s])(#\\).';
  367. },
  368. { include = '#sexp'; },
  369. { include = '#illegal'; },
  370. );
  371. };
  372. };
  373. }
Add Comment
Please, Sign In to add comment