MCPcopy Create free account
hub / github.com/HarmonicLabs/pebble / parseUsingDecl

Method parseUsingDecl

packages/pebble/src/parser/Parser.ts:605–687  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

603 tn.skip( Token.Semicolon ); // if any
604
605 return new StateDecl(
606 name,
607 fields,
608 spendMethods,
609 tn.range( startPos, tn.pos )
610 );
611 }
612 parseUsingDecl(): UsingStmt | UsingAliasStmt | undefined
613 {
614 const tn = this.tn;
615 const startPos = tn.tokenPos;
616
617 // alias form: `using <ident> = <NamespacePath>;`
618 if( !tn.skip( Token.OpenBrace ) )
619 {
620 if( !tn.skipIdentifier() ) return this.error(
621 DiagnosticCode._0_expected,
622 tn.range(), "{"
623 );
624
625 const alias = new Identifier( tn.readIdentifier(), tn.range() );
626
627 if( !tn.skip( Token.Equals ) ) return this.error(
628 DiagnosticCode._0_expected,
629 tn.range(), "="
630 );
631
632 const path = this.parseUsingPath();
633 if( !path ) return undefined;
634
635 return new UsingAliasStmt(
636 alias,
637 path,
638 tn.range( startPos, tn.pos )
639 );
640 }
641
642 // destructure form: `using { a, b: c } = <rhs>;`
643 const members = new Array<UsingStmtDeclaredConstructor>();
644 while( !tn.skip( Token.CloseBrace ) )
645 {
646 const thisStartPos = tn.tokenPos;
647
648 if( !tn.skipIdentifier() ) return this.error(
649 DiagnosticCode.Identifier_expected,
650 tn.range()
651 );
652
653 const identifier = new Identifier( tn.readIdentifier(), tn.range() );
654
655 let renamed: Identifier | undefined = undefined;
656 if( tn.skip( Token.Colon ) )
657 {
658 if( !tn.skipIdentifier() ) return this.error(
659 DiagnosticCode.Identifier_expected,
660 tn.range()
661 );
662 renamed = new Identifier( tn.readIdentifier(), tn.range() );

Callers 2

parseStatementMethod · 0.95

Calls 6

parseUsingPathMethod · 0.95
parseUsingRhsMethod · 0.95
skipMethod · 0.80
skipIdentifierMethod · 0.80
readIdentifierMethod · 0.80
rangeMethod · 0.45

Tested by

no test coverage detected