• Home
  • Raw
  • Download

Lines Matching full:lexer

24 #include "lexer/ASLexer.h"
81 std::unique_ptr<lexer::Lexer> ASParser::InitLexer(const SourceFile &sourceFile) in InitLexer()
84 auto lexer = std::make_unique<lexer::ASLexer>(&GetContext(), ErrorLogger()); in InitLexer() local
85 SetLexer(lexer.get()); in InitLexer()
86 return lexer; in InitLexer()
91 ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_AT); in ParseDecorator()
93 lexer::SourcePosition start = Lexer()->GetToken().Start(); in ParseDecorator()
94 Lexer()->NextToken(); // eat '@' in ParseDecorator()
117 ASSERT(Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_TYPE); in ParseTypeAliasDeclaration()
118 lexer::SourcePosition typeStart = Lexer()->GetToken().Start(); in ParseTypeAliasDeclaration()
119 Lexer()->NextToken(); // eat type keyword in ParseTypeAliasDeclaration()
120 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseTypeAliasDeclaration()
124 const util::StringView &ident = Lexer()->GetToken().Ident(); in ParseTypeAliasDeclaration()
127 id->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAliasDeclaration()
128 Lexer()->NextToken(); in ParseTypeAliasDeclaration()
131 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParseTypeAliasDeclaration()
136 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in ParseTypeAliasDeclaration()
140 Lexer()->NextToken(); // eat '=' in ParseTypeAliasDeclaration()
142 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { in ParseTypeAliasDeclaration()
143 Lexer()->NextToken(); // eat '|' in ParseTypeAliasDeclaration()
150 typeAliasDecl->SetRange({typeStart, Lexer()->GetToken().End()}); in ParseTypeAliasDeclaration()
165 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { in ParseOptionalFunctionParameter()
174 Lexer()->NextToken(); // eat '?' in ParseOptionalFunctionParameter()
177 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParseOptionalFunctionParameter()
178 Lexer()->NextToken(); // eat ':' in ParseOptionalFunctionParameter()
185 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in ParseOptionalFunctionParameter()
283 … return ArrowFunctionDescriptor {std::move(params), Lexer()->GetToken().Start(), arrowStatus}; in ConvertToArrowParameter()
335 switch (Lexer()->GetToken().Type()) { in ParsePatternElementToken()
336 case lexer::TokenType::PUNCTUATOR_PERIOD_PERIOD_PERIOD: { in ParsePatternElementToken()
344 case lexer::TokenType::LITERAL_IDENT: { in ParsePatternElementToken()
345 returnNode = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParsePatternElementToken()
346 returnNode->SetRange(Lexer()->GetToken().Loc()); in ParsePatternElementToken()
347 Lexer()->NextToken(); in ParsePatternElementToken()
349 … bool questionMark = Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK; in ParsePatternElementToken()
358 Lexer()->NextToken(); in ParsePatternElementToken()
361 if (!isOptional && Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParsePatternElementToken()
363 } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParsePatternElementToken()
364 Lexer()->NextToken(); // eat ':' in ParsePatternElementToken()
384 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in ParsePatternElement()
400 Lexer()->NextToken(); in ParsePatternElement()
403 Lexer()->GetToken().Type() == lexer::TokenType::KEYW_YIELD) { in ParsePatternElement()
410 …ir::AstNodeType::ASSIGNMENT_PATTERN, returnNode, rightNode, lexer::TokenType::PUNCTUATOR_SUBSTITUT… in ParsePatternElement()
419 Lexer()->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); in ParsePropertyDefinition()
423 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParsePropertyDefinition()
424 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_STRING) { in ParsePropertyDefinition()
428 key = AllocNode<ir::StringLiteral>(Lexer()->GetToken().String()); in ParsePropertyDefinition()
430 key = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParsePropertyDefinition()
433 key->SetRange(Lexer()->GetToken().Loc()); in ParsePropertyDefinition()
435 Lexer()->NextToken(); in ParsePropertyDefinition()
439 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParsePropertyDefinition()
440 Lexer()->NextToken(); in ParsePropertyDefinition()
455 switch (Lexer()->GetToken().Type()) { in CurrentIsBasicType()
456 case lexer::TokenType::LITERAL_STRING: in CurrentIsBasicType()
457 case lexer::TokenType::LITERAL_FALSE: in CurrentIsBasicType()
458 case lexer::TokenType::LITERAL_TRUE: in CurrentIsBasicType()
459 case lexer::TokenType::LITERAL_NULL: in CurrentIsBasicType()
460 case lexer::TokenType::KEYW_VOID: { in CurrentIsBasicType()
463 case lexer::TokenType::LITERAL_IDENT: { in CurrentIsBasicType()
464 switch (Lexer()->GetToken().KeywordType()) { in CurrentIsBasicType()
465 case lexer::TokenType::KEYW_I8: in CurrentIsBasicType()
466 case lexer::TokenType::KEYW_I16: in CurrentIsBasicType()
467 case lexer::TokenType::KEYW_I32: in CurrentIsBasicType()
468 case lexer::TokenType::KEYW_I64: in CurrentIsBasicType()
469 case lexer::TokenType::KEYW_ISIZE: in CurrentIsBasicType()
470 case lexer::TokenType::KEYW_U8: in CurrentIsBasicType()
471 case lexer::TokenType::KEYW_U16: in CurrentIsBasicType()
472 case lexer::TokenType::KEYW_U32: in CurrentIsBasicType()
473 case lexer::TokenType::KEYW_U64: in CurrentIsBasicType()
474 case lexer::TokenType::KEYW_USIZE: in CurrentIsBasicType()
475 case lexer::TokenType::KEYW_F32: in CurrentIsBasicType()
476 case lexer::TokenType::KEYW_F64: in CurrentIsBasicType()
477 case lexer::TokenType::KEYW_V128: in CurrentIsBasicType()
478 case lexer::TokenType::KEYW_FUNCREF: in CurrentIsBasicType()
479 case lexer::TokenType::KEYW_EXTERNREF: in CurrentIsBasicType()
480 case lexer::TokenType::KEYW_ANYREF: in CurrentIsBasicType()
481 case lexer::TokenType::KEYW_EQREF: in CurrentIsBasicType()
482 case lexer::TokenType::KEYW_I31REF: in CurrentIsBasicType()
483 case lexer::TokenType::KEYW_DATAREF: { in CurrentIsBasicType()
500 ir::TypeNode *ASParser::ParseFunctionType(lexer::SourcePosition startLoc) in ParseFunctionType()
504 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_ARROW) { in ParseFunctionType()
508 Lexer()->NextToken(); // eat '=>' in ParseFunctionType()
524 lexer::SourcePosition typeStart = Lexer()->GetToken().Start(); in ParseParenthesizedOrFunctionType()
525 const auto startPos = Lexer()->Save(); in ParseParenthesizedOrFunctionType()
526 ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); in ParseParenthesizedOrFunctionType()
527 Lexer()->NextToken(); // eat '(' in ParseParenthesizedOrFunctionType()
533 Lexer()->Rewind(startPos); in ParseParenthesizedOrFunctionType()
535 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseParenthesizedOrFunctionType()
546 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA || in ParseParenthesizedOrFunctionType()
547 Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK || in ParseParenthesizedOrFunctionType()
548 Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParseParenthesizedOrFunctionType()
549 Lexer()->Rewind(startPos); in ParseParenthesizedOrFunctionType()
553 … if (throwError && Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { in ParseParenthesizedOrFunctionType()
557 lexer::SourcePosition endLoc = Lexer()->GetToken().End(); in ParseParenthesizedOrFunctionType()
558 Lexer()->NextToken(); // eat ')' in ParseParenthesizedOrFunctionType()
560 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_ARROW) { in ParseParenthesizedOrFunctionType()
561 Lexer()->Rewind(startPos); in ParseParenthesizedOrFunctionType()
572 auto *typeName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseTypeAnnotationLiteralIdentHelper()
573 typeName->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationLiteralIdentHelper()
575 type->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationLiteralIdentHelper()
576 Lexer()->NextToken(); in ParseTypeAnnotationLiteralIdentHelper()
579 while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { in ParseTypeAnnotationLiteralIdentHelper()
580 Lexer()->NextToken(); in ParseTypeAnnotationLiteralIdentHelper()
582 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseTypeAnnotationLiteralIdentHelper()
586 typeName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseTypeAnnotationLiteralIdentHelper()
587 typeName->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationLiteralIdentHelper()
589 current->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationLiteralIdentHelper()
592 Lexer()->NextToken(); in ParseTypeAnnotationLiteralIdentHelper()
596 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParseTypeAnnotationLiteralIdentHelper()
611 switch (Lexer()->GetToken().Type()) { in ParseTypeAnnotationTokens()
612 case lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS: { in ParseTypeAnnotationTokens()
615 case lexer::TokenType::KEYW_VOID: { in ParseTypeAnnotationTokens()
619 case lexer::TokenType::KEYW_THIS: { in ParseTypeAnnotationTokens()
623 case lexer::TokenType::LITERAL_FALSE: in ParseTypeAnnotationTokens()
624 case lexer::TokenType::LITERAL_TRUE: { in ParseTypeAnnotationTokens()
628 case lexer::TokenType::LITERAL_NULL: { in ParseTypeAnnotationTokens()
632 case lexer::TokenType::LITERAL_STRING: { in ParseTypeAnnotationTokens()
636 case lexer::TokenType::LITERAL_IDENT: { in ParseTypeAnnotationTokens()
649 typeName->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationTokens()
651 type->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationTokens()
652 Lexer()->NextToken(); in ParseTypeAnnotationTokens()
658 while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { in ParseTypeAnnotationTokensBitwiseOr()
659 Lexer()->NextToken(); in ParseTypeAnnotationTokensBitwiseOr()
661 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_NULL) { in ParseTypeAnnotationTokensBitwiseOr()
679 type->SetEnd(Lexer()->GetToken().End()); in ParseTypeAnnotationTokensBitwiseOr()
680 Lexer()->NextToken(); in ParseTypeAnnotationTokensBitwiseOr()
687 while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET) { in ParseTypeAnnotationTokenLeftSquareBracket()
688 Lexer()->NextToken(); in ParseTypeAnnotationTokenLeftSquareBracket()
690 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { in ParseTypeAnnotationTokenLeftSquareBracket()
698 Lexer()->NextToken(); in ParseTypeAnnotationTokenLeftSquareBracket()
702 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { in ParseTypeAnnotationTokenLeftSquareBracket()
703 Lexer()->NextToken(); in ParseTypeAnnotationTokenLeftSquareBracket()
705 bool isLiteralNull = Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_NULL; in ParseTypeAnnotationTokenLeftSquareBracket()
716 const lexer::SourcePosition &startPos = type->Start(); in ParseTypeAnnotationTokenLeftSquareBracket()
720 typeName->SetRange(Lexer()->GetToken().Loc()); in ParseTypeAnnotationTokenLeftSquareBracket()
729 type->SetRange({startPos, Lexer()->GetToken().End()}); in ParseTypeAnnotationTokenLeftSquareBracket()
732 Lexer()->NextToken(); in ParseTypeAnnotationTokenLeftSquareBracket()
759 …[[maybe_unused]] ir::Expression **returnExpression, [[maybe_unused]] const lexer::SourcePosition &… in ParsePotentialArrowExpression()
764 bool ASParser::ParsePotentialNonNullExpression(ir::Expression **returnExpression, lexer::SourcePosi… in ParsePotentialNonNullExpression()
766 if (returnExpression == nullptr || Lexer()->GetToken().NewLine()) { in ParsePotentialNonNullExpression()
771 (*returnExpression)->SetRange({startLoc, Lexer()->GetToken().End()}); in ParsePotentialNonNullExpression()
772 Lexer()->NextToken(); in ParsePotentialNonNullExpression()
777 … const lexer::SourcePosition &startLoc, bool ignoreCallExpression) in ParsePotentialGenericFunctionCall()
779 if (Lexer()->Lookahead() == lexer::LEX_CHAR_LESS_THAN || in ParsePotentialGenericFunctionCall()
784 const auto savedPos = Lexer()->Save(); in ParsePotentialGenericFunctionCall()
786 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SHIFT) { in ParsePotentialGenericFunctionCall()
787 Lexer()->BackwardToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, 1); in ParsePotentialGenericFunctionCall()
794 Lexer()->Rewind(savedPos); in ParsePotentialGenericFunctionCall()
798 if (Lexer()->GetToken().Type() == lexer::TokenType::EOS) { in ParsePotentialGenericFunctionCall()
802 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { in ParsePotentialGenericFunctionCall()
812 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BACK_TICK) { in ParsePotentialGenericFunctionCall()
814 lexer::SourcePosition endLoc = propertyNode->End(); in ParsePotentialGenericFunctionCall()
821 Lexer()->Rewind(savedPos); in ParsePotentialGenericFunctionCall()
827 return Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS && in IsNamedFunctionExpression()
828 Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LESS_THAN; in IsNamedFunctionExpression()
833 if (Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_AS) { in ParsePotentialAsExpression()
838 Lexer()->NextToken(); in ParsePotentialAsExpression()
846 auto *identNode = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParsePrimaryExpressionIdent()
847 identNode->SetRange(Lexer()->GetToken().Loc()); in ParsePrimaryExpressionIdent()
849 Lexer()->NextToken(); in ParsePrimaryExpressionIdent()
860 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { in ValidateArrowFunctionRestParameter()
869 Lexer()->NextToken(); // eat extends keyword in ParseInterfaceExtendsClause()
871 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseInterfaceExtendsClause()
875 const lexer::SourcePosition &heritageStart = Lexer()->GetToken().Start(); in ParseInterfaceExtendsClause()
876 lexer::SourcePosition heritageEnd = Lexer()->GetToken().End(); in ParseInterfaceExtendsClause()
877 auto *extendsName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseInterfaceExtendsClause()
878 extendsName->SetRange(Lexer()->GetToken().Loc()); in ParseInterfaceExtendsClause()
880 extendsClause->SetRange(Lexer()->GetToken().Loc()); in ParseInterfaceExtendsClause()
881 Lexer()->NextToken(); in ParseInterfaceExtendsClause()
884 while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { in ParseInterfaceExtendsClause()
885 Lexer()->NextToken(); in ParseInterfaceExtendsClause()
887 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseInterfaceExtendsClause()
891 extendsName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseInterfaceExtendsClause()
892 extendsName->SetRange(Lexer()->GetToken().Loc()); in ParseInterfaceExtendsClause()
894 current->SetRange(Lexer()->GetToken().Loc()); in ParseInterfaceExtendsClause()
897 heritageEnd = Lexer()->GetToken().End(); in ParseInterfaceExtendsClause()
898 Lexer()->NextToken(); in ParseInterfaceExtendsClause()
901 if (Lexer()->Lookahead() == lexer::LEX_CHAR_LESS_THAN) { in ParseInterfaceExtendsClause()
902 Lexer()->ForwardToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, 1); in ParseInterfaceExtendsClause()
904 Lexer()->NextToken(); in ParseInterfaceExtendsClause()
907 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParseInterfaceExtendsClause()
910 heritageEnd = Lexer()->GetToken().End(); in ParseInterfaceExtendsClause()
915 if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_IMPLEMENTS) { in ParseInterfaceExtendsClause()
919 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { in ParseInterfaceExtendsClause()
931 ir::TSIndexSignature *ASParser::ParseIndexSignature(const lexer::SourcePosition &startLoc, bool isR… in ParseIndexSignature()
933 Lexer()->NextToken(); // eat '[' in ParseIndexSignature()
935 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseIndexSignature()
939 if (!Lexer()->GetToken().Ident().Is("key")) { in ParseIndexSignature()
943 auto *key = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseIndexSignature()
944 key->SetRange(Lexer()->GetToken().Loc()); in ParseIndexSignature()
946 Lexer()->NextToken(); // eat key in ParseIndexSignature()
948 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParseIndexSignature()
952 Lexer()->NextToken(); // eat ':' in ParseIndexSignature()
962 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { in ParseIndexSignature()
966 Lexer()->NextToken(); // eat ']' in ParseIndexSignature()
968 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParseIndexSignature()
972 Lexer()->NextToken(); // eat ':' in ParseIndexSignature()
981 indexSignature->SetRange({startLoc, Lexer()->GetToken().End()}); in ParseIndexSignature()
989 switch (Lexer()->GetToken().Type()) { in ParseInterfacePropertyKey()
990 case lexer::TokenType::LITERAL_IDENT: { in ParseInterfacePropertyKey()
991 const util::StringView &ident = Lexer()->GetToken().Ident(); in ParseInterfacePropertyKey()
993 key->SetRange(Lexer()->GetToken().Loc()); in ParseInterfacePropertyKey()
996 case lexer::TokenType::LITERAL_STRING: { in ParseInterfacePropertyKey()
997 const util::StringView &string = Lexer()->GetToken().String(); in ParseInterfacePropertyKey()
999 key->SetRange(Lexer()->GetToken().Loc()); in ParseInterfacePropertyKey()
1002 case lexer::TokenType::LITERAL_NUMBER: { in ParseInterfacePropertyKey()
1003 if ((Lexer()->GetToken().Flags() & lexer::TokenFlags::NUMBER_BIGINT) != 0) { in ParseInterfacePropertyKey()
1004 key = AllocNode<ir::BigIntLiteral>(Lexer()->GetToken().BigInt()); in ParseInterfacePropertyKey()
1006 key = AllocNode<ir::NumberLiteral>(Lexer()->GetToken().GetNumber()); in ParseInterfacePropertyKey()
1009 key->SetRange(Lexer()->GetToken().Loc()); in ParseInterfacePropertyKey()
1017 Lexer()->NextToken(); in ParseInterfacePropertyKey()
1021 ir::AstNode *ASParser::ParsePropertyOrMethodSignature(const lexer::SourcePosition &startLoc, bool i… in ParsePropertyOrMethodSignature()
1025 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { in ParsePropertyOrMethodSignature()
1029 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS || in ParsePropertyOrMethodSignature()
1030 Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParsePropertyOrMethodSignature()
1033 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParsePropertyOrMethodSignature()
1041 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParsePropertyOrMethodSignature()
1045 Lexer()->NextToken(); // eat ':' in ParsePropertyOrMethodSignature()
1052 methodSignature->SetRange({startLoc, Lexer()->GetToken().End()}); in ParsePropertyOrMethodSignature()
1056 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParsePropertyOrMethodSignature()
1060 Lexer()->NextToken(); // eat ':' in ParsePropertyOrMethodSignature()
1066 propertySignature->SetRange({startLoc, Lexer()->GetToken().End()}); in ParsePropertyOrMethodSignature()
1072 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_AT) { in ParseTypeLiteralOrInterfaceMember()
1076 char32_t nextCp = Lexer()->Lookahead(); in ParseTypeLiteralOrInterfaceMember()
1077 lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); in ParseTypeLiteralOrInterfaceMember()
1078 bool isReadonly = Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_READONLY && in ParseTypeLiteralOrInterfaceMember()
1079 nextCp != lexer::LEX_CHAR_LEFT_PAREN && nextCp != lexer::LEX_CHAR_COLON; in ParseTypeLiteralOrInterfaceMember()
1081 Lexer()->NextToken(); // eat 'readonly" in ParseTypeLiteralOrInterfaceMember()
1084 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET) { in ParseTypeLiteralOrInterfaceMember()
1095 while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { in ParseClassImplementClause()
1096 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseClassImplementClause()
1100 const lexer::SourcePosition &implementStart = Lexer()->GetToken().Start(); in ParseClassImplementClause()
1101 auto *implementsName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseClassImplementClause()
1102 implementsName->SetRange(Lexer()->GetToken().Loc()); in ParseClassImplementClause()
1104 implementsClause->SetRange(Lexer()->GetToken().Loc()); in ParseClassImplementClause()
1105 Lexer()->NextToken(); in ParseClassImplementClause()
1108 while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { in ParseClassImplementClause()
1109 Lexer()->NextToken(); in ParseClassImplementClause()
1111 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseClassImplementClause()
1115 implementsName = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseClassImplementClause()
1116 implementsName->SetRange(Lexer()->GetToken().Loc()); in ParseClassImplementClause()
1118 current->SetRange(Lexer()->GetToken().Loc()); in ParseClassImplementClause()
1121 Lexer()->NextToken(); in ParseClassImplementClause()
1125 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SHIFT) { in ParseClassImplementClause()
1126 Lexer()->BackwardToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, 1); in ParseClassImplementClause()
1129 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN || in ParseClassImplementClause()
1130 Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SHIFT) { in ParseClassImplementClause()
1136 impl->SetRange({implementStart, Lexer()->GetToken().End()}); in ParseClassImplementClause()
1139 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { in ParseClassImplementClause()
1140 Lexer()->NextToken(); in ParseClassImplementClause()
1143 ExpectToken(lexer::TokenType::PUNCTUATOR_LEFT_BRACE, false); in ParseClassImplementClause()
1155 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParseClassKeyAnnotation()
1156 Lexer()->NextToken(); // eat ':' in ParseClassKeyAnnotation()
1162 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS && in ParseClassKeyAnnotation()
1163 Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LESS_THAN) { in ParseClassKeyAnnotation()
1172 …if (typeAnnotation == nullptr && (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_… in ValidateClassMethodStart()
1173Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN)) { in ValidateClassMethodStart()
1245 bool ASParser::IsModifierKind(const lexer::Token &token) in IsModifierKind()
1248 case lexer::TokenType::KEYW_PUBLIC: in IsModifierKind()
1249 case lexer::TokenType::KEYW_PRIVATE: in IsModifierKind()
1250 case lexer::TokenType::KEYW_PROTECTED: in IsModifierKind()
1251 case lexer::TokenType::KEYW_STATIC: in IsModifierKind()
1252 case lexer::TokenType::KEYW_ASYNC: in IsModifierKind()
1253 case lexer::TokenType::KEYW_DECLARE: in IsModifierKind()
1254 case lexer::TokenType::KEYW_READONLY: in IsModifierKind()
1266 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_HASH_MARK) { in ConsumeClassPrivateIdentifier()
1273 Lexer()->NextToken(); // eat left square bracket in ParseComputedClassFieldOrIndexSignature()
1275 if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && in ParseComputedClassFieldOrIndexSignature()
1276 Lexer()->Lookahead() == lexer::LEX_CHAR_COLON) { in ParseComputedClassFieldOrIndexSignature()
1277 if (!Lexer()->GetToken().Ident().Is("key")) { in ParseComputedClassFieldOrIndexSignature()
1281 auto id = AllocNode<ir::Identifier>(Lexer()->GetToken().Ident(), Allocator()); in ParseComputedClassFieldOrIndexSignature()
1282 id->SetRange(Lexer()->GetToken().Loc()); in ParseComputedClassFieldOrIndexSignature()
1284 Lexer()->NextToken(); // eat param in ParseComputedClassFieldOrIndexSignature()
1286 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParseComputedClassFieldOrIndexSignature()
1290 Lexer()->NextToken(); // eat ':' in ParseComputedClassFieldOrIndexSignature()
1301 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { in ParseComputedClassFieldOrIndexSignature()
1305 Lexer()->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); in ParseComputedClassFieldOrIndexSignature()
1317 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { in ParseComputedClassFieldOrIndexSignature()
1324 std::tuple<bool, ir::BlockStatement *, lexer::SourcePosition, bool> ASParser::ParseFunctionBody( in ParseFunctionBody()
1333 lexer::SourcePosition endLoc = Lexer()->GetToken().End(); in ParseFunctionBody()
1335 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { in ParseFunctionBody()
1355 ir::Identifier *local = ParseNamedImport(&Lexer()->GetToken()); in ParseImportDefaultSpecifier()
1356 Lexer()->NextToken(); // eat local name in ParseImportDefaultSpecifier()
1365 ir::Expression *ASParser::ParseArrowFunctionRestParameter(lexer::SourcePosition start) in ParseArrowFunctionRestParameter()
1374 Lexer()->NextToken(); in ParseArrowFunctionRestParameter()
1376 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParseArrowFunctionRestParameter()
1380 Lexer()->NextToken(); // eat ':' in ParseArrowFunctionRestParameter()
1385 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_ARROW) { in ParseArrowFunctionRestParameter()
1392 ir::Expression *ASParser::ParseArrowFunctionNoParameter(lexer::SourcePosition start) in ParseArrowFunctionNoParameter()
1394 Lexer()->NextToken(); in ParseArrowFunctionNoParameter()
1396 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { in ParseArrowFunctionNoParameter()
1400 Lexer()->NextToken(); // eat ':' in ParseArrowFunctionNoParameter()
1405 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_ARROW) { in ParseArrowFunctionNoParameter()
1420 ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1421 lexer::SourcePosition start = Lexer()->GetToken().Start(); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1422 Lexer()->NextToken(); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1425 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD_PERIOD_PERIOD) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1429 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1436 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1441 expr->SetRange({start, Lexer()->GetToken().End()}); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1442 Lexer()->NextToken(); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1444 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_ARROW) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1448 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1449 auto savedPos = Lexer()->Save(); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1450 Lexer()->NextToken(); // eat ':' in ParseCoverParenthesizedExpressionAndArrowParameterList()
1455 Lexer()->Rewind(savedPos); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1459 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_ARROW) { in ParseCoverParenthesizedExpressionAndArrowParameterList()
1460 Lexer()->Rewind(savedPos); in ParseCoverParenthesizedExpressionAndArrowParameterList()
1472 lexer::SourcePosition startPos = Lexer()->GetToken().Start(); in ParsePrefixAssertionExpression()
1473 Lexer()->NextToken(); // eat < in ParsePrefixAssertionExpression()
1477 if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { in ParsePrefixAssertionExpression()
1481 Lexer()->NextToken(); // eat > in ParsePrefixAssertionExpression()
1486 node->SetRange({startPos, Lexer()->GetToken().End()}); in ParsePrefixAssertionExpression()
1492 lexer::SourcePosition constVarStar = Lexer()->GetToken().Start(); in ParseConstStatement()
1493 Lexer()->NextToken(); in ParseConstStatement()
1495 if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_ENUM) { in ParseConstStatement()
1512 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { in ParseVariableDeclaratorKey()
1518 const util::StringView &identStr = Lexer()->GetToken().Ident(); in ParseVariableDeclaratorKey()
1520 init->SetRange(Lexer()->GetToken().Loc()); in ParseVariableDeclaratorKey()
1521 Lexer()->NextToken(); in ParseVariableDeclaratorKey()
1523 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { in ParseVariableDeclaratorKey()
1524 Lexer()->NextToken(); // eat ':' in ParseVariableDeclaratorKey()
1528 Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in ParseVariableDeclaratorKey()
1545 ir::ExportDefaultDeclaration *ASParser::ParseExportDefaultDeclaration(const lexer::SourcePosition &… in ParseExportDefaultDeclaration()
1548 Lexer()->NextToken(); // eat `default` keyword or `=` in ParseExportDefaultDeclaration()
1553 switch (Lexer()->GetToken().Type()) { in ParseExportDefaultDeclaration()
1554 case lexer::TokenType::KEYW_FUNCTION: { in ParseExportDefaultDeclaration()
1558 case lexer::TokenType::KEYW_CLASS: { in ParseExportDefaultDeclaration()
1562 case lexer::TokenType::KEYW_INTERFACE: { in ParseExportDefaultDeclaration()
1566 case lexer::TokenType::KEYW_NAMESPACE: { in ParseExportDefaultDeclaration()
1567 Lexer()->NextToken(); // eat 'namespace' in ParseExportDefaultDeclaration()
1571 case lexer::TokenType::KEYW_ENUM: { in ParseExportDefaultDeclaration()
1575 case lexer::TokenType::KEYW_ASYNC: { in ParseExportDefaultDeclaration()
1576 if ((Lexer()->GetToken().Flags() & lexer::TokenFlags::HAS_ESCAPE) == 0) { in ParseExportDefaultDeclaration()
1577 Lexer()->NextToken(); // eat `async` in ParseExportDefaultDeclaration()
1591 lexer::SourcePosition endLoc = declNode->End(); in ParseExportDefaultDeclaration()
1603 …friend ir::ExportNamedDeclaration *ASParser::ParseNamedExportDeclaration(const lexer::SourcePositi…
1606 static ir::Statement *GetParsedDeclaration(ASParser *parser, lexer::TokenType type) in GetParsedDeclaration()
1609 if (parser->Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_ABSTRACT) { in GetParsedDeclaration()
1610 parser->Lexer()->NextToken(); // eat 'abstract' in GetParsedDeclaration()
1615 case lexer::TokenType::KEYW_VAR: { in GetParsedDeclaration()
1618 case lexer::TokenType::KEYW_CONST: { in GetParsedDeclaration()
1621 case lexer::TokenType::KEYW_LET: { in GetParsedDeclaration()
1624 case lexer::TokenType::KEYW_FUNCTION: { in GetParsedDeclaration()
1627 case lexer::TokenType::KEYW_CLASS: { in GetParsedDeclaration()
1630 case lexer::TokenType::KEYW_ENUM: { in GetParsedDeclaration()
1633 case lexer::TokenType::KEYW_INTERFACE: { in GetParsedDeclaration()
1636 case lexer::TokenType::KEYW_TYPE: { in GetParsedDeclaration()
1639 case lexer::TokenType::KEYW_GLOBAL: in GetParsedDeclaration()
1640 case lexer::TokenType::KEYW_MODULE: in GetParsedDeclaration()
1641 case lexer::TokenType::KEYW_NAMESPACE: { in GetParsedDeclaration()
1645 parser->ExpectToken(lexer::TokenType::KEYW_ASYNC); in GetParsedDeclaration()
1652 ir::ExportNamedDeclaration *ASParser::ParseNamedExportDeclaration(const lexer::SourcePosition &star… in ParseNamedExportDeclaration()
1654 if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { in ParseNamedExportDeclaration()
1659 … ParseNamedExportDeclarationHelper::GetParsedDeclaration(this, Lexer()->GetToken().KeywordType()); in ParseNamedExportDeclaration()
1676 if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { in ParseImportSpecifiers()
1681 if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { in ParseImportSpecifiers()
1683 } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { in ParseImportSpecifiers()
1692 char32_t nextChar = Lexer()->Lookahead(); in ParseImportDeclaration()
1693 if (nextChar == lexer::LEX_CHAR_LEFT_PAREN || nextChar == lexer::LEX_CHAR_DOT) { in ParseImportDeclaration()
1697 lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); in ParseImportDeclaration()
1698 Lexer()->NextToken(); // eat import in ParseImportDeclaration()
1704 if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_STRING) { in ParseImportDeclaration()
1711 lexer::SourcePosition endLoc = source->End(); in ParseImportDeclaration()
1720 void ASParser::ReportIllegalBreakError(const lexer::SourcePosition &pos) in ReportIllegalBreakError()