1
1
"use strict" ;
2
2
3
- import { unescape , argument_list , type_with_extended_attributes , return_type } from "./productions/helpers.js" ;
3
+ import { unescape } from "./productions/helpers.js" ;
4
4
import { Tokeniser } from "./tokeniser.js" ;
5
5
import { Base } from "./productions/base.js" ;
6
6
import { Enum } from "./productions/enum.js" ;
@@ -11,6 +11,8 @@ import { Operation } from "./productions/operation.js";
11
11
import { Constant } from "./productions/constant.js" ;
12
12
import { Typedef } from "./productions/typedef.js" ;
13
13
import { Field } from "./productions/field.js" ;
14
+ import { CallbackFunction } from "./productions/callback.js" ;
15
+ import { IterableLike } from "./productions/iterable.js" ;
14
16
15
17
/**
16
18
* @param {Tokeniser } tokeniser
@@ -30,41 +32,14 @@ function parseByTokens(tokeniser, options) {
30
32
return tokeniser . consume ( ...candidates ) ;
31
33
}
32
34
33
- function unconsume ( position ) {
34
- return tokeniser . unconsume ( position ) ;
35
- }
36
-
37
- class CallbackFunction extends Base {
38
- static parse ( base ) {
39
- const tokens = { base } ;
40
- const ret = new CallbackFunction ( { source, tokens } ) ;
41
- tokens . name = consume ( ID ) || error ( "No name for callback" ) ;
42
- tokeniser . current = ret ;
43
- tokens . assign = consume ( "=" ) || error ( "No assignment in callback" ) ;
44
- ret . idlType = return_type ( tokeniser ) || error ( "Missing return type" ) ;
45
- tokens . open = consume ( "(" ) || error ( "No arguments in callback" ) ;
46
- ret . arguments = argument_list ( tokeniser ) ;
47
- tokens . close = consume ( ")" ) || error ( "Unterminated callback" ) ;
48
- tokens . termination = consume ( ";" ) || error ( "Unterminated callback" ) ;
49
- return ret ;
50
- }
51
-
52
- get type ( ) {
53
- return "callback" ;
54
- }
55
- get name ( ) {
56
- return unescape ( this . tokens . name . value ) ;
57
- }
58
- }
59
-
60
35
function callback ( ) {
61
36
const callback = consume ( "callback" ) ;
62
37
if ( ! callback ) return ;
63
38
const tok = consume ( "interface" ) ;
64
39
if ( tok ) {
65
40
return Interface . parse ( tok , { callback } ) ;
66
41
}
67
- return CallbackFunction . parse ( callback ) ;
42
+ return CallbackFunction . parse ( tokeniser , callback ) ;
68
43
}
69
44
70
45
function static_member ( ) {
@@ -85,49 +60,6 @@ function parseByTokens(tokeniser, options) {
85
60
return member ;
86
61
}
87
62
88
- class IterableLike extends Base {
89
- static parse ( ) {
90
- const start_position = tokeniser . position ;
91
- const tokens = { } ;
92
- const ret = new IterableLike ( { source, tokens } ) ;
93
- tokens . readonly = consume ( "readonly" ) ;
94
- tokens . base = tokens . readonly ?
95
- consume ( "maplike" , "setlike" ) :
96
- consume ( "iterable" , "maplike" , "setlike" ) ;
97
- if ( ! tokens . base ) {
98
- unconsume ( start_position ) ;
99
- return ;
100
- }
101
-
102
- const { type } = ret ;
103
- const secondTypeRequired = type === "maplike" ;
104
- const secondTypeAllowed = secondTypeRequired || type === "iterable" ;
105
-
106
- tokens . open = consume ( "<" ) || error ( `Error parsing ${ type } declaration` ) ;
107
- const first = type_with_extended_attributes ( tokeniser ) || error ( `Error parsing ${ type } declaration` ) ;
108
- ret . idlType = [ first ] ;
109
- if ( secondTypeAllowed ) {
110
- first . tokens . separator = consume ( "," ) ;
111
- if ( first . tokens . separator ) {
112
- ret . idlType . push ( type_with_extended_attributes ( tokeniser ) ) ;
113
- }
114
- else if ( secondTypeRequired )
115
- error ( `Missing second type argument in ${ type } declaration` ) ;
116
- }
117
- tokens . close = consume ( ">" ) || error ( `Unterminated ${ type } declaration` ) ;
118
- tokens . termination = consume ( ";" ) || error ( `Missing semicolon after ${ type } declaration` ) ;
119
-
120
- return ret ;
121
- }
122
-
123
- get type ( ) {
124
- return this . tokens . base . value ;
125
- }
126
- get readonly ( ) {
127
- return ! ! this . tokens . readonly ;
128
- }
129
- }
130
-
131
63
function inheritance ( ) {
132
64
const colon = consume ( ":" ) ;
133
65
if ( ! colon ) {
0 commit comments