PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/collects/moby/runtime/error-struct-to-dom.ss

http://github.com/cderici/moby-scheme
Scheme | 624 lines | 499 code | 99 blank | 26 comment | 0 complexity | 59c8c6cd1dfa74100e829ee146cb926b MD5 | raw file
  1. #lang s-exp "../../../private/restricted-runtime-scheme.ss"
  2. (require "arity-struct.ss")
  3. (require "error-struct.ss")
  4. (require "stx.ss")
  5. (require "scheme-value-to-dom.ss")
  6. (require "dom-helpers.ss")
  7. (require "dom-parameters.ss")
  8. ;; Error structure to dom code.
  9. ;; These functions produce DOMs out of the values in error-struct,
  10. ;; ready to be styled.
  11. ;; error-struct-to-dom-sexp: dom (dom-parameters | false) -> sexp
  12. ;; Convert an error structure to a dom-sexp. Optionally provide a dom-parameters
  13. ;; that defines custom dom converters.
  14. (define (error-struct->dom-sexp an-error maybe-dom-parameters)
  15. (local [(define embedded-location (moby-error-location an-error))
  16. (define error-type (moby-error-error-type an-error))
  17. (define (add-toplevel-dom-error-wrapper a-dom)
  18. `(span ((class "Error"))
  19. ,a-dom
  20. (span ((class "Error.location"))
  21. ,(Loc->dom-sexp embedded-location))))]
  22. (add-toplevel-dom-error-wrapper
  23. (cond
  24. [(moby-error-type:unclosed-lexical-token? error-type)
  25. `(span ((class "Error-UnclosedLexicalToken"))
  26. (span ((class "Error.reason"))
  27. "I saw "
  28. ,(scheme-value->dom-sexp (moby-error-type:unclosed-lexical-token-opener error-type)
  29. maybe-dom-parameters)
  30. " to start a "
  31. ,(moby-error-type:unclosed-lexical-token-type error-type)
  32. ", but no "
  33. ,(scheme-value->dom-sexp (moby-error-type:unclosed-lexical-token-closer error-type)
  34. maybe-dom-parameters)
  35. " to close it.")
  36. (span ((class "Error-UnclosedLexicalToken.type")
  37. (style "display:none"))
  38. ,(moby-error-type:unclosed-lexical-token-type error-type))
  39. (span ((class "Error-UnclosedLexicalToken.opener")
  40. (style "display:none"))
  41. ,(symbol->string (moby-error-type:unclosed-lexical-token-opener error-type)))
  42. (span ((class "Error-UnclosedLexicalToken.closer")
  43. (style "display:none"))
  44. ,(symbol->string (moby-error-type:unclosed-lexical-token-closer error-type))))]
  45. [(moby-error-type:unrecognized-lexical-token? error-type)
  46. `(span ((class "Error-UnrecognizedLexicalToken"))
  47. (span ((class "Error.reason"))
  48. "I saw "
  49. ,(scheme-value->dom-sexp (moby-error-type:unrecognized-lexical-token-token error-type)
  50. maybe-dom-parameters)
  51. " which I don't recognize as a program element.")
  52. (span ((class "Error-UnrecognizedLexicalToken.token")
  53. (style "display:none"))
  54. ,(symbol->string (moby-error-type:unrecognized-lexical-token-token error-type))))]
  55. [(moby-error-type:unsupported-lexical-token? error-type)
  56. `(span ((class "Error-UnsupportedLexicalToken"))
  57. (span ((class "Error.reason"))
  58. ,(scheme-value->dom-sexp (moby-error-type:unsupported-lexical-token-token error-type)
  59. maybe-dom-parameters)
  60. " is currently not supported.")
  61. (span ((class "Error-UnsupportedLexicalToken.token")
  62. (style "display:none"))
  63. ,(symbol->string (moby-error-type:unsupported-lexical-token-token error-type))))]
  64. [(moby-error-type:unsupported-expression-form? error-type)
  65. `(span ((class "Error-UnsupportedExpressionForm"))
  66. (span ((class "Error.reason"))
  67. ,(stx->dom-sexp (moby-error-type:unsupported-expression-form-expr error-type)
  68. maybe-dom-parameters)
  69. " is currently not supported.")
  70. (span ((class "Error-UnsupportedExpressionForm.expr")
  71. (style "display:none"))
  72. ,(stx->dom-sexp (moby-error-type:unsupported-expression-form-expr error-type)
  73. maybe-dom-parameters)))]
  74. [(moby-error-type:unclosed-parentheses? error-type)
  75. `(span ((class "Error-UnclosedParentheses"))
  76. (span ((class "Error.reason"))
  77. "I saw "
  78. ,(scheme-value->dom-sexp (moby-error-type:unclosed-parentheses-opener error-type)
  79. maybe-dom-parameters)
  80. " to start an expression, but no "
  81. ,(scheme-value->dom-sexp (moby-error-type:unclosed-parentheses-closer error-type)
  82. maybe-dom-parameters)
  83. " to close it.")
  84. (span ((class "Error-UnclosedParentheses.opener")
  85. (style "display:none"))
  86. ,(symbol->string (moby-error-type:unclosed-parentheses-opener error-type)))
  87. (span ((class "Error-UnclosedParentheses.closer")
  88. (style "display:none"))
  89. ,(symbol->string (moby-error-type:unclosed-parentheses-closer error-type))))]
  90. [(moby-error-type:unbalanced-parentheses? error-type)
  91. `(span ((class "Error-UnbalancedParentheses"))
  92. "I saw "
  93. ,(scheme-value->dom-sexp
  94. (moby-error-type:unbalanced-parentheses-opener error-type)
  95. maybe-dom-parameters)
  96. " earlier, and expected it to be matched with "
  97. ,(scheme-value->dom-sexp
  98. (moby-error-type:unbalanced-parentheses-closer error-type)
  99. maybe-dom-parameters)
  100. ", but instead I see "
  101. ,(scheme-value->dom-sexp
  102. (moby-error-type:unbalanced-parentheses-observed error-type)
  103. maybe-dom-parameters)
  104. ".")]
  105. [(moby-error-type:syntax-not-applied? error-type)
  106. `(span ((class "Error-SyntaxNotApplied"))
  107. "I saw "
  108. ,(stx->dom-sexp (moby-error-type:syntax-not-applied-keyword error-type)
  109. maybe-dom-parameters)
  110. ", which isn't supposed to be used as a bare expression. "
  111. "Rather, one example of its use is: "
  112. ,(scheme-value->dom-sexp
  113. (moby-error-type:syntax-not-applied-example error-type)
  114. maybe-dom-parameters)
  115. ".")]
  116. [(moby-error-type:closing-parenthesis-before-opener? error-type)
  117. `(span ((class "Error-ClosingParenthesisBeforeOpener"))
  118. "I saw "
  119. ,(scheme-value->dom-sexp
  120. (moby-error-type:closing-parenthesis-before-opener-closer error-type)
  121. maybe-dom-parameters)
  122. " without it being paired with a left parenthesis.")]
  123. [(moby-error-type:duplicate-identifier? error-type)
  124. `(span ((class "Error-DuplicateIdentifier"))
  125. (span ((class "Error.reason"))
  126. "The identifier "
  127. ,(scheme-value->dom-sexp (moby-error-type:duplicate-identifier-id error-type)
  128. maybe-dom-parameters)
  129. " has been duplicated.")
  130. (span ((class "Error-DuplicateIdentifier.secondLocation")
  131. (style "display:none"))
  132. ,(Loc->dom-sexp (moby-error-type:duplicate-identifier-second-location error-type))))]
  133. [(moby-error-type:expected-identifier? error-type)
  134. `(span ((class "Error-ExpectedIdentifier"))
  135. (span ((class "Error.reason"))
  136. "I expected an identifier but received "
  137. ,(stx->dom-sexp (moby-error-type:expected-identifier-observed error-type)
  138. maybe-dom-parameters)
  139. " instead."))]
  140. [(moby-error-type:expected-list-of-identifiers? error-type)
  141. `(span ((class "Error-ExpectedListOfIdentifiers"))
  142. (span ((class "Error.reason"))
  143. "Within " ,@(prepend-indefinite-article
  144. (stx->dom-sexp
  145. (moby-error-type:expected-list-of-identifiers-who error-type)
  146. maybe-dom-parameters))
  147. ", I expected a list of identifiers but received "
  148. ,(stx->dom-sexp (moby-error-type:expected-list-of-identifiers-observed error-type)
  149. maybe-dom-parameters)
  150. " instead."))]
  151. [(moby-error-type:undefined-identifier? error-type)
  152. `(span ((class "Error-UndefinedIdentifier"))
  153. (span ((class "Error.reason"))
  154. "I don't know what "
  155. ,(scheme-value->dom-sexp (moby-error-type:undefined-identifier-id error-type)
  156. maybe-dom-parameters)
  157. " is; it's not defined as an input or a primitive."))]
  158. [(moby-error-type:structure-identifier-not-expression? error-type)
  159. `(span ((class "Error-StructureIdentifierNotExpression"))
  160. (span ((class "Error.reason"))
  161. "The structure name "
  162. ,(scheme-value->dom-sexp (moby-error-type:structure-identifier-not-expression-id
  163. error-type)
  164. maybe-dom-parameters)
  165. " can't be used as an expression."))]
  166. [(moby-error-type:provided-name-not-defined? error-type)
  167. `(span ((class "Error-ProvidedNameNotDefined"))
  168. (span ((class "Error.reason"))
  169. "The provided name "
  170. ,(scheme-value->dom-sexp (moby-error-type:provided-name-not-defined-id error-type)
  171. maybe-dom-parameters)
  172. " is not defined in the program."))]
  173. [(moby-error-type:provided-structure-not-structure? error-type)
  174. `(span ((class "Error-ProvidedStructureNotStructure"))
  175. (span ((class "Error.reason"))
  176. "The provided name "
  177. ,(scheme-value->dom-sexp
  178. (moby-error-type:provided-structure-not-structure-id error-type)
  179. maybe-dom-parameters)
  180. "is defined in the program, but is not the name of a structure."))]
  181. [(moby-error-type:unknown-module? error-type)
  182. `(span ((class "Error-UnknownModule"))
  183. (span ((class "Error.reason"))
  184. "I see a require of the module "
  185. ,(scheme-value->dom-sexp (moby-error-type:unknown-module-path error-type)
  186. maybe-dom-parameters)
  187. ", but I don't yet know what this module is."))]
  188. [(moby-error-type:conditional-missing-question-answer? error-type)
  189. `(span ((class "Error-ConditionalMissingQuestionAnswer"))
  190. "After cond, I expect at least one question-answer branch, but I don't see anything.")]
  191. [(moby-error-type:conditional-malformed-clause? error-type)
  192. `(span ((class "Error-ConditionalMalformedClause"))
  193. "Inside a cond branch, I expect a question and an answer, but I don't "
  194. "see both things here.")]
  195. [(moby-error-type:conditional-clause-too-few-elements? error-type)
  196. `(span ((class "Error-ConditionalClauseTooFewElements"))
  197. "Inside a cond branch, I expect a question and an answer, but I don't see both.")]
  198. [(moby-error-type:conditional-clause-too-many-elements? error-type)
  199. `(span ((class "Error-ConditionalClauseTooManyElements"))
  200. "Inside a cond branch, I expect to see a question and an answer, "
  201. "but I see more than two things here.")]
  202. [(moby-error-type:branch-value-not-boolean? error-type)
  203. `(span ((class "Error-BranchValueNotBoolean"))
  204. "I expected the question's value to be a boolean expression, "
  205. "("
  206. ,(scheme-value->dom-sexp true maybe-dom-parameters)
  207. " or "
  208. ,(scheme-value->dom-sexp false maybe-dom-parameters)
  209. "), "
  210. "but instead I see "
  211. ,(scheme-value->dom-sexp
  212. (moby-error-type:branch-value-not-boolean-observed error-type)
  213. maybe-dom-parameters)
  214. ".")]
  215. [(moby-error-type:if-too-few-elements? error-type)
  216. `(span ((class "Error-IfTooFewElements"))
  217. "I expected a test, a consequence, and an alternative, "
  218. "but I don't see all these three.")]
  219. [(moby-error-type:if-too-many-elements? error-type)
  220. `(span ((class "Error-IfTooFewElements"))
  221. "I expected only a test, a consequence, and an alternative, "
  222. "but I see more than three of these.")]
  223. [(moby-error-type:begin-body-empty? error-type)
  224. `(span ((class "Error-BeginBodyEmpty"))
  225. "Inside a begin, I expect to see a body, but I don't see anything.")]
  226. [(moby-error-type:boolean-chain-too-few-elements? error-type)
  227. `(span ((class "Error-BooleanChainTooFewElements"))
  228. "Inside a "
  229. ,(scheme-value->dom-sexp (moby-error-type:boolean-chain-too-few-elements-id error-type)
  230. maybe-dom-parameters)
  231. ", I expect to see at least two expressions, but I don't see them both.")]
  232. [(moby-error-type:lambda-too-few-elements? error-type)
  233. `(span ((class "Error-LambdaTooFewElements"))
  234. "Inside a lambda, I expect to see a list of arguments and a single body, "
  235. "but I don't see both of these.")]
  236. [(moby-error-type:lambda-too-many-elements? error-type)
  237. `(span ((class "Error-LambdaTooManyElements"))
  238. "Inside a lambda, I expect to see a list of arguments and a single body, "
  239. "but I see more than these two.")]
  240. [(moby-error-type:missing-expression-following-quote? error-type)
  241. `(span ((class "Error-MissingExpressionFollowingQuote"))
  242. "After a "
  243. ,(stx->dom-sexp (moby-error-type:missing-expression-following-quote-quote-stx error-type)
  244. maybe-dom-parameters)
  245. ", I expected to see another expression immediately following it, but I don't see one.")]
  246. [(moby-error-type:quote-too-few-elements? error-type)
  247. `(span ((class "Error-QuoteTooFewElements"))
  248. "Inside a quote, I expect to see a single argument, but I don't see one.")]
  249. [(moby-error-type:quote-too-many-elements? error-type)
  250. `(span ((class "Error-QuoteTooManyElements"))
  251. "Inside a quote, I expect to single a single element, but I see more than one.")]
  252. [(moby-error-type:quasiquote-too-few-elements? error-type)
  253. `(span ((class "Error-QuasiquoteTooFewElements"))
  254. "Inside a quasiquote, I expect to see a single argument, but I don't see one.")]
  255. [(moby-error-type:quasiquote-too-many-elements? error-type)
  256. `(span ((class "Error-QuasiquoteTooManyElements"))
  257. "Inside a quasiquote, I expect to single a single element, but I see more than one.")]
  258. [(moby-error-type:unquote-too-few-elements? error-type)
  259. `(span ((class "Error-UnquoteTooFewElements"))
  260. "Inside an unquote, I expect to see a single argument, but I don't see one.")]
  261. [(moby-error-type:unquote-too-many-elements? error-type)
  262. `(span ((class "Error-UnquoteTooManyElements"))
  263. "Inside a unquote, I expect to single a single element, but I see more than one.")]
  264. [(moby-error-type:unquote-splicing-too-few-elements? error-type)
  265. `(span ((class "Error-UnquoteTooFewElements"))
  266. "Inside an unquote-splicing, I expect to see a single argument, but I don't see one.")]
  267. [(moby-error-type:unquote-splicing-too-many-elements? error-type)
  268. `(span ((class "Error-UnquoteTooManyElements"))
  269. "Inside a unquote-splicing, I expect to single a single element, but I see more than one.")]
  270. [(moby-error-type:when-no-body? error-type)
  271. `(span ((class "Error-WhenNoBody"))
  272. "Inside a " (scheme-value->dom-sexp 'when maybe-dom-parameters)
  273. ", I expect to see a body, but I don't see one.")]
  274. [(moby-error-type:unless-no-body? error-type)
  275. `(span ((class "Error-WhenNoBody"))
  276. "Inside an " (scheme-value->dom-sexp 'unless maybe-dom-parameters)
  277. ", I expect to see a body, but I don't see one.")]
  278. [(moby-error-type:check-expect? error-type)
  279. `(span ((class "Error-CheckExpect"))
  280. "Inside a "
  281. ,(scheme-value->dom-sexp 'check-expect maybe-dom-parameters)
  282. ", the observed value "
  283. ,(scheme-value->dom-sexp (moby-error-type:check-expect-observed error-type) maybe-dom-parameters)
  284. " does not match the expected value "
  285. ,(scheme-value->dom-sexp (moby-error-type:check-expect-expected error-type) maybe-dom-parameters)
  286. ".")]
  287. [(moby-error-type:check-within? error-type)
  288. `(span ((class "Error-CheckWithin"))
  289. "Inside a "
  290. ,(scheme-value->dom-sexp 'check-within maybe-dom-parameters)
  291. ", the observed value "
  292. ,(scheme-value->dom-sexp (moby-error-type:check-within-observed error-type) maybe-dom-parameters)
  293. " does not match the expected value "
  294. ,(scheme-value->dom-sexp (moby-error-type:check-within-expected error-type) maybe-dom-parameters)
  295. " within the bounds "
  296. ,(scheme-value->dom-sexp (moby-error-type:check-within-within error-type) maybe-dom-parameters)
  297. ".")]
  298. [(moby-error-type:check-error? error-type)
  299. `(span ((class "Error-CheckError"))
  300. "Inside a "
  301. ,(scheme-value->dom-sexp 'check-expect maybe-dom-parameters)
  302. ", the observed error "
  303. ,(scheme-value->dom-sexp (moby-error-type:check-error-observed error-type) maybe-dom-parameters)
  304. " does not match the expected error "
  305. ,(scheme-value->dom-sexp (moby-error-type:check-error-expected error-type) maybe-dom-parameters)
  306. ".")]
  307. [(moby-error-type:check-error-no-error? error-type)
  308. `(span ((class "Error-CheckErrorNoError"))
  309. "I expected an the expected error "
  310. ,(scheme-value->dom-sexp (moby-error-type:check-error-no-error-expected error-type) maybe-dom-parameters)
  311. " but instead I received the value "
  312. ,(scheme-value->dom-sexp (moby-error-type:check-error-no-error-observed error-type) maybe-dom-parameters))]
  313. [(moby-error-type:application-arity? error-type)
  314. `(span ((class "Error-ApplicationArity"))
  315. (span ((class "Error.reason"))
  316. "The function "
  317. ,(scheme-value->dom-sexp (moby-error-type:application-arity-who error-type) maybe-dom-parameters)
  318. " expects "
  319. ,(arity-to-dom-sexp (moby-error-type:application-arity-expected error-type))
  320. " inputs, but instead I see "
  321. ,(number->string (moby-error-type:application-arity-observed error-type))
  322. " inputs."))]
  323. [(moby-error-type:application-operator-not-a-function? error-type)
  324. `(span ((class "Error-ApplicationOperatorNotAFunction"))
  325. (span ((class "Error.reason"))
  326. "The operator "
  327. ,(scheme-value->dom-sexp
  328. (moby-error-type:application-operator-not-a-function-who error-type)
  329. maybe-dom-parameters)
  330. " has a value "
  331. ,(scheme-value->dom-sexp
  332. (moby-error-type:application-operator-not-a-function-val error-type)
  333. maybe-dom-parameters)
  334. ", but this value isn't a function."))]
  335. [(moby-error-type:type-mismatch? error-type)
  336. `(span ((class "Error-TypeMismatch"))
  337. (span ((class "Error.reason"))
  338. "The function "
  339. ,(scheme-value->dom-sexp
  340. (moby-error-type:type-mismatch-who error-type)
  341. maybe-dom-parameters)
  342. " expects "
  343. ,@(prepend-indefinite-article
  344. (expected-value-to-dom-sexp
  345. (moby-error-type:type-mismatch-expected error-type)))
  346. " as its "
  347. ,(number->string
  348. (moby-error-type:type-mismatch-position error-type))
  349. ,(ordinal-ending (moby-error-type:type-mismatch-position error-type))
  350. " argument, but instead I see "
  351. ,(scheme-value->dom-sexp
  352. (moby-error-type:type-mismatch-observed error-type)
  353. maybe-dom-parameters)
  354. "."))]
  355. [(moby-error-type:index-out-of-bounds? error-type)
  356. `(span ((class "Error-IndexOutOfBounds"))
  357. (span ((class "Error.reason"))
  358. "The index "
  359. ,(scheme-value->dom-sexp
  360. (moby-error-type:index-out-of-bounds-observed error-type)
  361. maybe-dom-parameters)
  362. " is not within the expected boundary ["
  363. ,(scheme-value->dom-sexp
  364. (moby-error-type:index-out-of-bounds-minimum error-type)
  365. maybe-dom-parameters)
  366. ", "
  367. ,(scheme-value->dom-sexp
  368. (moby-error-type:index-out-of-bounds-maximum error-type)
  369. maybe-dom-parameters)
  370. "]"
  371. ))]
  372. [(moby-error-type:conditional-exhausted? error-type)
  373. `(span ((class "Error-ConditionalExhausted"))
  374. (span ((class "Error.reason"))
  375. "All of the questions inside a cond were false, "
  376. "and at least one of them has to be true."))]
  377. [(moby-error-type:generic-runtime-error? error-type)
  378. `(span ((class "Error-GenericRuntimeError"))
  379. (span ((class "Error.reason"))
  380. ,(moby-error-type:generic-runtime-error-reason error-type)))]
  381. [(moby-error-type:generic-syntactic-error? error-type)
  382. `(span ((class "Error-GenericSyntacticError"))
  383. (span ((class "Error.reason"))
  384. ,(moby-error-type:generic-syntactic-error-reason error-type))
  385. (span ((class "Error-GenericSyntacticError.otherLocations"))
  386. ,@(map Loc->dom-sexp
  387. (moby-error-type:generic-syntactic-error-other-locations error-type))))]))))
  388. ;; Loc->dom-sexp: loc -> sexp
  389. ;; Given a location, produce a dom representation of that location.
  390. (define (Loc->dom-sexp a-loc)
  391. `(span ((class "Location")
  392. (style "display:none"))
  393. (span ((class "Location.offset")) ,(number->string (Loc-offset a-loc)))
  394. (span ((class "Location.line")) ,(number->string (Loc-line a-loc)))
  395. (span ((class "Location.column")) ,(number->string (Loc-column a-loc)))
  396. (span ((class "Location.span")) ,(number->string (Loc-span a-loc)))
  397. (span ((class "Location.id")) ,(Loc-id a-loc))))
  398. ;; ordinal-ending: natural-number -> string
  399. ;; Produces the ordinal ending of a number. For example, 1 => st, 4 => th.
  400. (define (ordinal-ending n)
  401. (cond
  402. [(= (modulo (quotient n 10) 10) 1)
  403. "th"]
  404. [else
  405. (list-ref '("th" "st" "nd" "rd" "th"
  406. "th" "th" "th" "th" "th")
  407. (modulo n 10))]))
  408. ;; prepend-indefinite-article: dom -> (listof dom)
  409. ;; Produces a list containting the appropriate indefinite article and the dom.
  410. (define (prepend-indefinite-article a-dom)
  411. (list (indefinite-article (dom-string-content a-dom))
  412. " "
  413. a-dom))
  414. ;; indefinite-article: string -> string
  415. ;; Tries to get the indefinite article of a word.
  416. (define (indefinite-article a-word)
  417. (cond
  418. [(begins-with-vowel-sound? a-word)
  419. "an"]
  420. [else
  421. "a"]))
  422. ;; begins-with-vowel-sound?: string -> boolean
  423. ;; Tries to produces true if there's a vowel sound at the beginning of the
  424. ;; word.
  425. ;; This is not quite right because it doesn't use a dictionary.
  426. (define (begins-with-vowel-sound? a-word)
  427. (cond
  428. [(= 0 (string-length a-word))
  429. false]
  430. [(vowel-character? (string-ref a-word 0))
  431. true]
  432. ;; Check to see if it's a "y" vowel sound
  433. [(and (> (string-length a-word) 2)
  434. (char=? (string-ref a-word 0) #\y)
  435. (not (vowel-character? (string-ref a-word 1))))
  436. true]
  437. [else
  438. false]))
  439. ;; vowel-character?: char -> boolean
  440. ;; Produces true if the given character is a vowel character.
  441. (define (vowel-character? a-char)
  442. (member a-char '(#\a #\e #\i #\o #\u)))
  443. ;; stx-to-dom-sexp: stx -> dom
  444. ;; Converts a stx to a dom s-expression.
  445. (define (stx->dom-sexp a-stx maybe-dom-parameters)
  446. (scheme-value->dom-sexp (stx->datum a-stx) maybe-dom-parameters))
  447. ;; expected-value-to-dom-sexp: moby-expected -> dom
  448. ;; Translates an expectation to a dom.
  449. (define (expected-value-to-dom-sexp expected)
  450. (cond
  451. [(moby-expected:string? expected)
  452. `(span ((class "Expected-String"))
  453. "string")]
  454. [(moby-expected:integer? expected)
  455. `(span ((class "Expected-Integer"))
  456. "integer")]
  457. [(moby-expected:natural? expected)
  458. `(span ((class "Expected-Natural"))
  459. "natural")]
  460. [(moby-expected:rational? expected)
  461. `(span ((class "Expected-Rational"))
  462. "rational")]
  463. [(moby-expected:real? expected)
  464. `(span ((class "Expected-Real"))
  465. "real")]
  466. [(moby-expected:complex? expected)
  467. `(span ((class "Expected-Complex"))
  468. "complex")]
  469. [(moby-expected:number? expected)
  470. `(span ((class "Expected-Number"))
  471. "number")]
  472. [(moby-expected:boolean? expected)
  473. `(span ((class "Expected-Boolean"))
  474. "boolean")]
  475. [(moby-expected:char? expected)
  476. `(span ((class "Expected-Char"))
  477. "char")]
  478. [(moby-expected:symbol? expected)
  479. `(span ((class "Expected-Symbol"))
  480. "symbol")]
  481. [(moby-expected:list? expected)
  482. `(span ((class "Expected-List"))
  483. "list")]
  484. [(moby-expected:listof? expected)
  485. `(span ((class "Expected-Listof"))
  486. "list of "
  487. (expected-value-to-dom-sexp (moby-expected:listof-thing expected))
  488. "" )]
  489. [(moby-expected:vector? expected)
  490. `(span ((class "Expected-Vector"))
  491. "vector")]
  492. [(moby-expected:struct? expected)
  493. `(span ((class "Expected-Struct"))
  494. "struct")]
  495. [(moby-expected:box? expected)
  496. `(span ((class "Expected-Box"))
  497. "box")]
  498. [(moby-expected:hash? expected)
  499. `(span ((class "Expected-Hash"))
  500. "hash")]
  501. [(moby-expected:function? expected)
  502. `(span ((class "Expected-Function"))
  503. "function")]
  504. [(moby-expected:something? expected)
  505. `(span ((class "Expected-Something"))
  506. ,(moby-expected:something-description expected))]))
  507. ;; Converts an arity to a dom sexpression.
  508. (define (arity-to-dom-sexp an-arity)
  509. (cond
  510. [(arity:fixed? an-arity)
  511. `(span ((class "Arity-Fixed"))
  512. ,(number->string (arity:fixed-n an-arity)))]
  513. [(arity:variable? an-arity)
  514. `(span ((class "Arity-Variable"))
  515. (span ((class "Arity-Variable.minimum"))
  516. ,(number->string (arity:variable-min an-arity)))
  517. (span ((class "Arity-Variable.maximum"))
  518. ,(number->string (arity:variable-max an-arity))))]
  519. [(arity:mixed? an-arity)
  520. `(span ((class "Arity-Mixed"))
  521. ,@(map (lambda (a)
  522. `(span ((class "Arity-Mixed.item"))
  523. ,(arity-to-dom-sexp a)))))]))
  524. (provide/contract
  525. [error-struct->dom-sexp (any/c (or/c false/c dom-parameters?) . -> . any)])