()
| 1781 | // '{' [dictorsetmaker] '}' | |
| 1782 | // NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False' | '__debug__') |
| 1783 | private _parseAtom(): ExpressionNode { |
| 1784 | let nextToken = this._peekToken(); |
| 1785 | |
| 1786 | if (nextToken.type === TokenType.Ellipsis) { |
| 1787 | return new EllipsisNode(this._getNextToken()); |
| 1788 | } |
| 1789 | |
| 1790 | if (nextToken.type === TokenType.Number) { |
| 1791 | return new NumberNode(this._getNextToken() as NumberToken); |
| 1792 | } |
| 1793 | |
| 1794 | if (nextToken.type === TokenType.Identifier) { |
| 1795 | return new NameNode(this._getNextToken() as IdentifierToken); |
| 1796 | } |
| 1797 | |
| 1798 | if (nextToken.type === TokenType.String) { |
| 1799 | let stringTokenList: StringToken[] = []; |
| 1800 | |
| 1801 | while (this._peekTokenType() === TokenType.String) { |
| 1802 | stringTokenList.push(this._getNextToken() as StringToken); |
| 1803 | } |
| 1804 | |
| 1805 | return new StringNode(stringTokenList); |
| 1806 | } |
| 1807 | |
| 1808 | if (nextToken.type === TokenType.OpenParenthesis) { |
| 1809 | return this._parseTupleAtom(); |
| 1810 | } else if (nextToken.type === TokenType.OpenBracket) { |
| 1811 | return this._parseListAtom(); |
| 1812 | } else if (nextToken.type === TokenType.OpenCurlyBrace) { |
| 1813 | return this._parseDictionaryOrSetAtom(); |
| 1814 | } |
| 1815 | |
| 1816 | if (nextToken.type === TokenType.Keyword) { |
| 1817 | let keywordToken = nextToken as KeywordToken; |
| 1818 | if (keywordToken.keywordType === KeywordType.False || |
| 1819 | keywordToken.keywordType === KeywordType.True || |
| 1820 | keywordToken.keywordType === KeywordType.Debug || |
| 1821 | keywordToken.keywordType === KeywordType.None) { |
| 1822 | return new ConstantNode(this._getNextToken() as KeywordToken); |
| 1823 | } |
| 1824 | |
| 1825 | // Make an identifier out of the keyword. |
| 1826 | let keywordAsIdentifier = this._getTokenIfIdentifier(); |
| 1827 | if (keywordAsIdentifier) { |
| 1828 | return new NameNode(keywordAsIdentifier); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | return this._handleExpressionParseError('Expected expression'); |
| 1833 | } |
| 1834 | |
| 1835 | // Allocates a dummy "error expression" and consumes the remainder |
| 1836 | // of the tokens on the line for error recovery. |
no test coverage detected