@@ -126,30 +126,21 @@ export abstract class ContextKeyExpr {
126
126
return ContextKeySmallerEqualsExpr . create ( key , value ) ;
127
127
}
128
128
129
- public static deserializeNew ( serialized : string | null | undefined ) : ContextKeyExpression | undefined {
129
+ /**
130
+ * Warning: experimental; the API might change.
131
+ */
132
+ public static deserializeOrErrorNew ( serialized : string | null | undefined ) : { type : 'ok' ; expr : ContextKeyExpr } | { type : 'error' ; readonly lexingErrors : string [ ] ; readonly parsingErrors : readonly string [ ] } {
130
133
if ( ! serialized ) {
131
- return undefined ;
134
+ return { type : 'error' , lexingErrors : [ ] , parsingErrors : [ ] } ;
132
135
}
133
136
134
137
const parser = new Parser ( ) ;
135
138
const expr = parser . parse ( serialized ) ;
136
- if ( expr === undefined ) { // print a console warning
137
- const warning = [ ] ;
138
- warning . push ( `Failed to parse context key expression ("when clause"): ${ serialized } \n` ) ;
139
- if ( parser . lexingErrors . length > 0 ) {
140
- warning . push ( 'Lexing errors:\n\n' ) ;
141
- parser . lexingErrors . forEach ( token => warning . push ( Scanner . reportError ( token ) , '\n' ) ) ;
142
- }
143
-
144
- if ( parser . parsingErrors . length > 0 ) {
145
- if ( parser . lexingErrors . length > 0 ) { warning . push ( '\n\n' ) ; } // separate lexing errors from parsing errors
146
- warning . push ( 'Parsing errors:\n\n' ) ;
147
- parser . parsingErrors . forEach ( message => warning . push ( `${ message } ` , '\n' ) ) ;
148
- }
149
- console . warn ( warning . join ( '' ) ) ;
139
+ if ( expr === undefined ) {
140
+ return { type : 'error' , lexingErrors : parser . lexingErrors . map ( token => Scanner . reportError ( token ) ) , parsingErrors : parser . parsingErrors } ;
141
+ } else {
142
+ return { type : 'ok' , expr } ;
150
143
}
151
-
152
- return expr ;
153
144
}
154
145
155
146
public static deserialize ( serialized : string | null | undefined ) : ContextKeyExpression | undefined {
@@ -1488,8 +1479,7 @@ export class ContextKeyRegexExpr implements IContextKeyExpression {
1488
1479
1489
1480
public serialize ( ) : string {
1490
1481
const value = this . regexp
1491
- // ? `/${this.regexp.source}/${this.regexp.flags}`
1492
- ? `/${ this . regexp . source } /`
1482
+ ? `/${ this . regexp . source } /${ this . regexp . flags } `
1493
1483
: '/invalid/' ;
1494
1484
return `${ this . key } =~ ${ value } ` ;
1495
1485
}
0 commit comments