PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://github.com/bootstrapworld/wescheme-compiler2012
Scheme | 371 lines | 261 code | 88 blank | 22 comment | 0 complexity | 9c32ae139709862c1d4eabf93f31d2dd MD5 | raw file
  1. #lang s-exp "../../../private/restricted-runtime-scheme.ss"
  2. (require "stx.ss")
  3. (require "arity-struct.ss")
  4. (define-struct moby-error (location error-type))
  5. ;; The following provides colored message support. A Message is a kind of moby-error-type.
  6. (define-struct Message (parts))
  7. (define-struct ColoredPart (text loc))
  8. (define-struct GradientPart (parts)) ;; (listof ColoredPart)
  9. (define-struct MultiPart (text locs solid))
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;; The parser errors:
  12. ;; A lexical token hasn't been closed (e.g. a string literal without closing quote)
  13. (define-struct moby-error-type:unclosed-lexical-token (type opener closer))
  14. ;; A lexical token has been seen that we don't know how to lex.
  15. (define-struct moby-error-type:unrecognized-lexical-token (token))
  16. ;; A lexical token has been seen that we don't support (e.g. dotted pairs)
  17. (define-struct moby-error-type:unsupported-lexical-token (token))
  18. ;; An unsupported expression form has shown up
  19. (define-struct moby-error-type:unsupported-expression-form (expr))
  20. ;; e.g. "("
  21. (define-struct moby-error-type:unclosed-parentheses (opener closer))
  22. ;; e.g. ")",
  23. (define-struct moby-error-type:closing-parenthesis-before-opener (closer))
  24. ;; If the parentheses are closed by a paren of unexpected shape, we raise
  25. ;; unbalanced-parentheses.
  26. ;; e.g. "( ]"
  27. (define-struct moby-error-type:unbalanced-parentheses (opener closer observed other-location))
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. (define-struct moby-error-type:syntax-not-applied (keyword example))
  30. (define-struct moby-error-type:duplicate-identifier (id second-location))
  31. (define-struct moby-error-type:expected-identifier (observed))
  32. (define-struct moby-error-type:expected-list-of-identifiers (who observed))
  33. (define-struct moby-error-type:undefined-identifier (id))
  34. (define-struct moby-error-type:structure-identifier-not-expression (id))
  35. (define-struct moby-error-type:provided-name-not-defined (id))
  36. (define-struct moby-error-type:provided-structure-not-structure (id))
  37. (define-struct moby-error-type:unknown-module (path))
  38. (define-struct moby-error-type:redefinition-not-allowed (id))
  39. (define-struct moby-error-type:conditional-missing-question-answer ())
  40. (define-struct moby-error-type:conditional-malformed-clause ())
  41. (define-struct moby-error-type:conditional-clause-too-few-elements ())
  42. (define-struct moby-error-type:conditional-clause-too-many-elements ())
  43. (define-struct moby-error-type:conditional-exhausted ())
  44. (define-struct moby-error-type:branch-value-not-boolean (observed))
  45. (define-struct moby-error-type:if-too-few-elements ())
  46. (define-struct moby-error-type:if-too-many-elements ())
  47. (define-struct moby-error-type:missing-expression-following-quote (quote-stx)) ;; e.g. (list hello ')
  48. (define-struct moby-error-type:quote-too-few-elements ())
  49. (define-struct moby-error-type:quote-too-many-elements ())
  50. (define-struct moby-error-type:quasiquote-too-few-elements ())
  51. (define-struct moby-error-type:quasiquote-too-many-elements ())
  52. (define-struct moby-error-type:unquote-too-few-elements ())
  53. (define-struct moby-error-type:unquote-too-many-elements ())
  54. (define-struct moby-error-type:unquote-splicing-too-few-elements ())
  55. (define-struct moby-error-type:unquote-splicing-too-many-elements ())
  56. (define-struct moby-error-type:begin-body-empty ())
  57. (define-struct moby-error-type:boolean-chain-too-few-elements (id))
  58. (define-struct moby-error-type:lambda-too-few-elements ())
  59. (define-struct moby-error-type:lambda-too-many-elements ())
  60. (define-struct moby-error-type:when-no-body ())
  61. (define-struct moby-error-type:unless-no-body ())
  62. (define-struct moby-error-type:check-expect (expected observed))
  63. (define-struct moby-error-type:check-within (expected observed within))
  64. (define-struct moby-error-type:check-error (expected observed))
  65. (define-struct moby-error-type:check-error-no-error (expected observed))
  66. (define-struct moby-error-type:application-arity (who expected observed))
  67. (define-struct moby-error-type:application-operator-not-a-function (who val))
  68. (define-struct moby-error-type:type-mismatch (who position expected observed))
  69. (define-struct moby-error-type:index-out-of-bounds (minimum maximum observed))
  70. (define-struct moby-error-type:generic-runtime-error (reason))
  71. ;; FIXME: the generic-syntactic-error class should die as soon as I fully enumerate
  72. ;; the errors.
  73. (define-struct moby-error-type:generic-syntactic-error (reason other-locations))
  74. (define-struct moby-error-type:generic-read-error (message locations))
  75. ;; moby-error-type: any -> boolean
  76. ;; Produces true if x is a moby-error-type.
  77. (define (moby-error-type? x)
  78. (or (Message? x)
  79. (moby-error-type:unclosed-lexical-token? x)
  80. (moby-error-type:unrecognized-lexical-token? x)
  81. (moby-error-type:unsupported-lexical-token? x)
  82. (moby-error-type:unsupported-expression-form? x)
  83. (moby-error-type:unclosed-parentheses? x)
  84. (moby-error-type:unbalanced-parentheses? x)
  85. (moby-error-type:syntax-not-applied? x)
  86. (moby-error-type:closing-parenthesis-before-opener? x)
  87. (moby-error-type:duplicate-identifier? x)
  88. (moby-error-type:expected-identifier? x)
  89. (moby-error-type:expected-list-of-identifiers? x)
  90. (moby-error-type:undefined-identifier? x)
  91. (moby-error-type:structure-identifier-not-expression? x)
  92. (moby-error-type:provided-name-not-defined? x)
  93. (moby-error-type:provided-structure-not-structure? x)
  94. (moby-error-type:unknown-module? x)
  95. (moby-error-type:redefinition-not-allowed? x)
  96. (moby-error-type:conditional-missing-question-answer? x)
  97. (moby-error-type:conditional-exhausted? x)
  98. (moby-error-type:conditional-missing-question-answer? x)
  99. (moby-error-type:conditional-malformed-clause? x)
  100. (moby-error-type:conditional-clause-too-few-elements? x)
  101. (moby-error-type:conditional-clause-too-many-elements? x)
  102. (moby-error-type:branch-value-not-boolean? x)
  103. (moby-error-type:if-too-few-elements? x)
  104. (moby-error-type:if-too-many-elements? x)
  105. (moby-error-type:boolean-chain-too-few-elements? x)
  106. (moby-error-type:begin-body-empty? x)
  107. (moby-error-type:lambda-too-many-elements? x)
  108. (moby-error-type:lambda-too-few-elements? x)
  109. (moby-error-type:missing-expression-following-quote? x)
  110. (moby-error-type:quote-too-few-elements? x)
  111. (moby-error-type:quote-too-many-elements? x)
  112. (moby-error-type:quasiquote-too-few-elements? x)
  113. (moby-error-type:quasiquote-too-many-elements? x)
  114. (moby-error-type:unquote-too-few-elements? x)
  115. (moby-error-type:unquote-too-many-elements? x)
  116. (moby-error-type:unquote-splicing-too-few-elements? x)
  117. (moby-error-type:unquote-splicing-too-many-elements? x)
  118. (moby-error-type:when-no-body? x)
  119. (moby-error-type:unless-no-body? x)
  120. (moby-error-type:check-expect? x)
  121. (moby-error-type:check-within? x)
  122. (moby-error-type:check-error? x)
  123. (moby-error-type:check-error-no-error? x)
  124. (moby-error-type:application-arity? x)
  125. (moby-error-type:application-operator-not-a-function? x)
  126. (moby-error-type:type-mismatch? x)
  127. (moby-error-type:index-out-of-bounds? x)
  128. (moby-error-type:generic-runtime-error? x)
  129. (moby-error-type:generic-syntactic-error? x)
  130. (moby-error-type:generic-read-error? x)))
  131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. (define-struct moby-expected:string ())
  133. (define-struct moby-expected:integer ())
  134. (define-struct moby-expected:natural ())
  135. (define-struct moby-expected:rational ())
  136. (define-struct moby-expected:real ())
  137. (define-struct moby-expected:complex ())
  138. (define-struct moby-expected:number ())
  139. (define-struct moby-expected:boolean ())
  140. (define-struct moby-expected:char ())
  141. (define-struct moby-expected:symbol ())
  142. (define-struct moby-expected:list ())
  143. (define-struct moby-expected:listof (thing))
  144. (define-struct moby-expected:vector ())
  145. (define-struct moby-expected:struct ())
  146. (define-struct moby-expected:box ())
  147. (define-struct moby-expected:hash ())
  148. (define-struct moby-expected:function ())
  149. (define-struct moby-expected:something (description))
  150. ;; moby-expected?: any -> boolean
  151. ;; Produces true if x is an expected value.
  152. (define (moby-expected? x)
  153. (ormap (lambda (pred?)
  154. (pred? x))
  155. (list
  156. moby-expected:string?
  157. moby-expected:integer?
  158. moby-expected:natural?
  159. moby-expected:rational?
  160. moby-expected:real?
  161. moby-expected:complex?
  162. moby-expected:number?
  163. moby-expected:boolean?
  164. moby-expected:char?
  165. moby-expected:symbol?
  166. moby-expected:list?
  167. moby-expected:vector?
  168. moby-expected:struct?
  169. moby-expected:box?
  170. moby-expected:hash?
  171. moby-expected:function?
  172. moby-expected:something?)))
  173. (define (-make-Message . args)
  174. (make-Message args))
  175. (provide [rename-out [-make-Message make-Message]]
  176. Message? Message-parts
  177. [struct-out ColoredPart]
  178. [struct-out GradientPart])
  179. (provide/contract
  180. [struct MultiPart ([text string?]
  181. [locs (non-empty-listof Loc?)]
  182. [solid boolean?])])
  183. (provide/contract
  184. [struct moby-error ([location Loc?]
  185. [error-type moby-error-type?])]
  186. [moby-error-type? (any/c . -> . boolean?)]
  187. [struct moby-error-type:unclosed-lexical-token ([type string?]
  188. [opener symbol?]
  189. [closer symbol?])]
  190. [struct moby-error-type:unrecognized-lexical-token ([token symbol?])]
  191. [struct moby-error-type:unsupported-lexical-token ([token symbol?])]
  192. [struct moby-error-type:unsupported-expression-form ([expr stx?])]
  193. [struct moby-error-type:unclosed-parentheses ([opener symbol?]
  194. [closer symbol?])]
  195. [struct moby-error-type:unbalanced-parentheses ([opener symbol?]
  196. [closer symbol?]
  197. [observed symbol?]
  198. [other-location Loc?])]
  199. [struct moby-error-type:closing-parenthesis-before-opener ([closer symbol?])]
  200. [struct moby-error-type:syntax-not-applied ([keyword stx?]
  201. [example any/c])]
  202. [struct moby-error-type:duplicate-identifier ([id symbol?]
  203. [second-location Loc?])]
  204. [struct moby-error-type:expected-identifier ([observed stx?])]
  205. [struct moby-error-type:expected-list-of-identifiers ([who stx?]
  206. [observed stx?])]
  207. [struct moby-error-type:undefined-identifier ([id symbol?])]
  208. [struct moby-error-type:structure-identifier-not-expression ([id symbol?])]
  209. [struct moby-error-type:provided-name-not-defined ([id symbol?])]
  210. [struct moby-error-type:provided-structure-not-structure ([id symbol?])]
  211. [struct moby-error-type:unknown-module ([path module-path?])]
  212. [struct moby-error-type:redefinition-not-allowed ([id symbol?])]
  213. [struct moby-error-type:conditional-missing-question-answer ()] ;; missing clauses
  214. [struct moby-error-type:conditional-malformed-clause ()] ;; a clause which isn't an [question answer]
  215. [struct moby-error-type:conditional-clause-too-few-elements ()] ;; a clause without a question or an answer
  216. ;; a clause with too many answer values. stx stx
  217. [struct moby-error-type:conditional-clause-too-many-elements ()]
  218. [struct moby-error-type:conditional-exhausted ()] ;; runtime: no answer was true
  219. [struct moby-error-type:branch-value-not-boolean ([observed any/c])]
  220. [struct moby-error-type:if-too-few-elements ()] ;; e.g. (if x)
  221. [struct moby-error-type:if-too-many-elements ()] ;; (if x y z w)
  222. [struct moby-error-type:begin-body-empty ()] ;; e.g. (begin)
  223. [struct moby-error-type:boolean-chain-too-few-elements ([id symbol?])]
  224. [struct moby-error-type:lambda-too-many-elements ()]
  225. [struct moby-error-type:lambda-too-few-elements ()]
  226. [struct moby-error-type:missing-expression-following-quote ([quote-stx stx?])]
  227. [struct moby-error-type:quote-too-few-elements ()]
  228. [struct moby-error-type:quote-too-many-elements ()]
  229. [struct moby-error-type:quasiquote-too-few-elements ()]
  230. [struct moby-error-type:quasiquote-too-many-elements ()]
  231. [struct moby-error-type:unquote-too-few-elements ()]
  232. [struct moby-error-type:unquote-too-many-elements ()]
  233. [struct moby-error-type:unquote-splicing-too-few-elements ()]
  234. [struct moby-error-type:unquote-splicing-too-many-elements ()]
  235. [struct moby-error-type:when-no-body ()]
  236. [struct moby-error-type:unless-no-body ()]
  237. [struct moby-error-type:check-expect ([expected any/c]
  238. [observed any/c])]
  239. [struct moby-error-type:check-within ([expected any/c]
  240. [observed any/c]
  241. [within any/c])]
  242. [struct moby-error-type:check-error ([expected string?] ;; the expected string of the error message
  243. [observed string?])] ;; the observed string
  244. [struct moby-error-type:check-error-no-error ([expected string?]
  245. [observed any/c])]
  246. [struct moby-error-type:application-arity ([who any/c]
  247. [expected arity?]
  248. [observed any/c])]
  249. [struct moby-error-type:application-operator-not-a-function ([who any/c] ;; who is the operator
  250. [val any/c] ;; what value
  251. ;; did the operator produce?
  252. )]
  253. [struct moby-error-type:type-mismatch ([who any/c]
  254. [position number?]
  255. [expected any/c]
  256. [observed any/c])]
  257. [struct moby-error-type:index-out-of-bounds ([minimum number?]
  258. [maximum number?]
  259. [observed number?])]
  260. [struct moby-error-type:generic-runtime-error ([reason string?])]
  261. [struct moby-error-type:generic-syntactic-error ([reason string?]
  262. [other-locations (listof Loc?)])]
  263. [struct moby-error-type:generic-read-error ([message string?]
  264. [locations (listof Loc?)])]
  265. [moby-expected? (any/c . -> . boolean?)]
  266. [struct moby-expected:string ()]
  267. [struct moby-expected:integer ()]
  268. [struct moby-expected:natural ()]
  269. [struct moby-expected:rational ()]
  270. [struct moby-expected:real ()]
  271. [struct moby-expected:complex ()]
  272. [struct moby-expected:number ()]
  273. [struct moby-expected:boolean ()]
  274. [struct moby-expected:char ()]
  275. [struct moby-expected:symbol ()]
  276. [struct moby-expected:list ()]
  277. [struct moby-expected:listof ([thing moby-expected?])]
  278. [struct moby-expected:vector ()]
  279. [struct moby-expected:struct ()]
  280. [struct moby-expected:box ()]
  281. [struct moby-expected:hash ()]
  282. [struct moby-expected:function ()]
  283. [struct moby-expected:something ([description string?])])