Root namespace in types and expressions
This commit is contained in:
@@ -95,6 +95,7 @@ atomicExpression
|
||||
: jump
|
||||
: loop
|
||||
: SimpleName
|
||||
: "namespace" // foo the root namespace
|
||||
;
|
||||
|
||||
literalConstant
|
||||
|
||||
@@ -14,7 +14,7 @@ type
|
||||
;
|
||||
|
||||
userType
|
||||
: simpleUserType{"."}
|
||||
: ("namespace" ".")? simpleUserType{"."}
|
||||
;
|
||||
|
||||
simpleUserType
|
||||
|
||||
@@ -101,6 +101,7 @@ public interface JetNodeTypes {
|
||||
JetNodeType PATTERN = new JetNodeType("PATTERN");
|
||||
JetNodeType TUPLE_PATTERN = new JetNodeType("TUPLE_PATTERN");
|
||||
JetNodeType OBJECT_LITERAL = new JetNodeType("OBJECT_LITERAL");
|
||||
JetNodeType ROOT_NAMESPACE = new JetNodeType("ROOT_NAMESPACE");
|
||||
|
||||
IElementType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME");
|
||||
}
|
||||
|
||||
@@ -269,17 +269,19 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
* : functionLiteral
|
||||
* : declaration
|
||||
* : SimpleName
|
||||
* : "namespace" // foo the root namespace
|
||||
* ;
|
||||
*/
|
||||
private void parseAtomicExpression() {
|
||||
|
||||
// TODO: namespace.a.b.C
|
||||
// System.out.println("atom at " + myBuilder.getTokenText());
|
||||
|
||||
|
||||
if (at(LPAR)) {
|
||||
parseParenthesizedExpressionOrTuple();
|
||||
}
|
||||
else if (at(NAMESPACE_KEYWORD)) {
|
||||
parseOneTokenExpression(ROOT_NAMESPACE);
|
||||
}
|
||||
else if (at(THIS_KEYWORD)) {
|
||||
parseThisExpression();
|
||||
}
|
||||
@@ -438,7 +440,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
private void parsePattern() {
|
||||
PsiBuilder.Marker pattern = mark();
|
||||
|
||||
if (at(IDENTIFIER)) {
|
||||
if (at(IDENTIFIER) || at(NAMESPACE_KEYWORD)) {
|
||||
myJetParsing.parseUserType();
|
||||
if (at(LPAR)) {
|
||||
parseTuplePattern();
|
||||
|
||||
@@ -1210,7 +1210,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
parseAttributeList();
|
||||
|
||||
if (at(IDENTIFIER)) {
|
||||
if (at(IDENTIFIER) || at(NAMESPACE_KEYWORD)) {
|
||||
parseUserType();
|
||||
}
|
||||
else if (at(LBRACE)) {
|
||||
@@ -1229,10 +1229,14 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
/*
|
||||
* userType
|
||||
* : simpleUserType{"."}
|
||||
* : ("namespace" ".")? simpleUserType{"."}
|
||||
* ;
|
||||
*/
|
||||
public void parseUserType() {
|
||||
if (at(NAMESPACE_KEYWORD)) {
|
||||
advance(); // NAMESPACE_KEYWORD
|
||||
expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER));
|
||||
}
|
||||
while (true) {
|
||||
parseSimpleUserType();
|
||||
if (!at(DOT)) break;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace foo.bar;
|
||||
|
||||
class X
|
||||
|
||||
namespace foo.bar {
|
||||
fun foo() {
|
||||
namespace.foo.bar.X
|
||||
new namespace.foo.bar.X()
|
||||
e match {
|
||||
case namespace.foo.bar.X(x) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
JetFile: RootNamespace.jet
|
||||
NAMESPACE
|
||||
PsiElement(namespace)('namespace')
|
||||
PsiWhiteSpace(' ')
|
||||
NAMESPACE_NAME
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(SEMICOLON)(';')
|
||||
PsiWhiteSpace('\n\n')
|
||||
CLASS
|
||||
PsiElement(class)('class')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('X')
|
||||
PsiWhiteSpace('\n\n')
|
||||
TYPE_PARAMETER_LIST
|
||||
<empty list>
|
||||
NAMESPACE
|
||||
PsiElement(namespace)('namespace')
|
||||
PsiWhiteSpace(' ')
|
||||
NAMESPACE_NAME
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
NAMESPACE_BODY
|
||||
FUN
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
TYPE_PARAMETER_LIST
|
||||
<empty list>
|
||||
VALUE_PARAMETER_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
ROOT_NAMESPACE
|
||||
PsiElement(namespace)('namespace')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('X')
|
||||
PsiWhiteSpace('\n ')
|
||||
NEW
|
||||
PsiElement(new)('new')
|
||||
PsiWhiteSpace(' ')
|
||||
TYPE_REFERENCE
|
||||
PsiElement(namespace)('namespace')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('X')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
BINARY_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('e')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(match)('match')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
MATCH_ENTRY
|
||||
PsiElement(case)('case')
|
||||
PsiWhiteSpace(' ')
|
||||
PATTERN
|
||||
PsiElement(namespace)('namespace')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('X')
|
||||
TUPLE_PATTERN
|
||||
PsiElement(LPAR)('(')
|
||||
PATTERN
|
||||
USER_TYPE
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
FUNCTION_LITERAL
|
||||
PsiElement(LBRACE)('{')
|
||||
BODY
|
||||
<empty list>
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
Reference in New Issue
Block a user