Ergonomics: admit JS property-name syntax in PDict patterns
This commit is contained in:
parent
34f1617a62
commit
919ee891f6
|
@ -2,13 +2,13 @@
|
|||
/// SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||
|
||||
import {
|
||||
Token, Items,
|
||||
Token, Items, TokenBase, TokenType,
|
||||
Pattern,
|
||||
foldItems, match, anonymousTemplate as template, commaJoin,
|
||||
|
||||
scope, bind, seq, alt, upTo, atom, atomString, group,
|
||||
repeat, option, withoutSpace, map, mapm, rest, discard,
|
||||
value, succeed, fail, separatedOrTerminatedBy, not, TokenBase
|
||||
value, succeed, fail, separatedOrTerminatedBy, not,
|
||||
} from '../syntax/index.js';
|
||||
import * as Matcher from '../syntax/matcher.js';
|
||||
|
||||
|
@ -183,6 +183,14 @@ export class SyndicateParser {
|
|||
return withoutSpace(upTo(alt(this.exprBoundary, ... extraStops)));
|
||||
}
|
||||
|
||||
propertyNameExpr(): Pattern<Expr> {
|
||||
const dq = template`"`;
|
||||
return alt<Expr>(
|
||||
map(atom(), name => [... dq, name, ... dq]),
|
||||
map(atom(void 0, { tokenType: TokenType.STRING }), str => [str]),
|
||||
group('[', this.expr()));
|
||||
}
|
||||
|
||||
readonly type: (... extraStops: Pattern<any>[]) => Pattern<Type> = this.expr;
|
||||
|
||||
statement(acc: Items): Pattern<any> {
|
||||
|
@ -418,7 +426,7 @@ export class SyndicateParser {
|
|||
value<[Expr, ValuePattern]>(e => {
|
||||
e.value = [] as any;
|
||||
return seq(
|
||||
bind(e.value, '0', this.expr(atom(':'))),
|
||||
bind(e.value, '0', this.propertyNameExpr()),
|
||||
atom(':'),
|
||||
bind(e.value, '1', this.valuePattern(level)));
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue