0 | module Text.WebIDL.Types.Token
 1 |
 2 | import Derive.Prelude
 3 | import Text.WebIDL.Types.Identifier
 4 | import Text.WebIDL.Types.Numbers
 5 | import Text.WebIDL.Types.StringLit
 6 | import Text.WebIDL.Types.Symbol
 7 |
 8 | %default total
 9 |
10 | %language ElabReflection
11 |
12 | public export
13 | data IdlError : Type where
14 |   ExpectedStringLit : IdlError
15 |   InvalidArgName : String -> IdlError
16 |
17 | %runElab derive "IdlError" [Show,Eq]
18 |
19 | export
20 | Interpolation IdlError where
21 |   interpolate ExpectedStringLit = "Expected string literal"
22 |   interpolate (InvalidArgName s) = "Invalid argument name: \{s}"
23 |
24 | ||| Text tokens in the WebIDL grammar. The `Invalid` token
25 | ||| is not recognized by any parser and will lead to a
26 | ||| failure during parsing.
27 | public export
28 | data IdlToken : Type where
29 |   ||| A string literal
30 |   SLit      : StringLit  -> IdlToken
31 |
32 |   ||| An integer literal (in decimal, hexadecimal, or
33 |   ||| octal representation)
34 |   ILit      : IntLit     -> IdlToken
35 |
36 |   ||| A floating point literal
37 |   FLit      : FloatLit   -> IdlToken
38 |
39 |   ||| Any valid identifier that is not also a
40 |   ||| keyword.
41 |   Ident     : Identifier -> IdlToken
42 |
43 |   ||| A WebIDL keyword
44 |   Key       : Keyword    -> IdlToken
45 |
46 |   ||| A single symbol character (or an ellipsis: ...)
47 |   Other     : Symbol     -> IdlToken
48 |
49 |   ||| Single or multiline comment
50 |   Comment   : IdlToken
51 |
52 |   ||| A sequence of whitespace characters
53 |   Space     : IdlToken
54 |
55 | %runElab derive "IdlToken" [Eq,Show]
56 |
57 | export
58 | Interpolation IdlToken where
59 |   interpolate (SLit x)  = interpolate x
60 |   interpolate (ILit x)  = interpolate x
61 |   interpolate (FLit x)  = interpolate x
62 |   interpolate (Ident x) = interpolate x
63 |   interpolate (Key x)   = interpolate x
64 |   interpolate (Other x) = interpolate x
65 |   interpolate Comment   = "<comment>"
66 |   interpolate Space     = "<space>"
67 |