Skip to content

Commit

Permalink
parse tag names with dot (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed May 7, 2018
1 parent fc42111 commit 8b206c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/reason/lang/reason/RmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private void parseLt(PsiBuilder builder, ParserState state) {
if (state.isInScopeExpression()) {
state.addStart(tagScope);
}

state.dontMove = advance(builder);

builder.remapCurrentToken(m_types.TAG_NAME);
Expand All @@ -356,8 +357,11 @@ private void parseLtSlash(PsiBuilder builder, ParserState state) {
// A closing tag
builder.remapCurrentToken(m_types.TAG_LT);
state.add(markCompleteScope(builder, closeTag, m_types.TAG_CLOSE, groupExpression, m_types.TAG_LT));

state.dontMove = advance(builder);

builder.remapCurrentToken(m_types.TAG_NAME);
state.dontMove = wrapWith(nextTokenType == m_types.UIDENT ? m_types.UPPER_SYMBOL : m_types.LOWER_SYMBOL, builder);
}
}

Expand Down Expand Up @@ -537,7 +541,7 @@ private void parseUIdent(PsiBuilder builder, ParserState state) {
state.setComplete();
} else if (state.isResolution(module)) {
state.setResolution(moduleNamed);
} else if (state.isResolution(startTag) && state.previousTokenType == m_types.DOT) {
} else if ((state.isResolution(startTag) || state.isResolution(closeTag)) && state.previousTokenType == m_types.DOT) {
// a namespaced custom component
builder.remapCurrentToken(m_types.TAG_NAME);
} else if (state.isResolution(typeNamedEqVariant) && state.previousTokenType == m_types.PIPE) {
Expand Down
23 changes: 22 additions & 1 deletion tests/com/reason/reason/JsxParsingTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.reason.reason;

import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.reason.BaseParsingTestCase;
import com.reason.lang.core.psi.PsiLet;
import com.reason.lang.core.psi.PsiTagClose;
import com.reason.lang.core.psi.PsiTagStart;
import com.reason.lang.reason.RmlParserDefinition;
import com.reason.lang.reason.RmlTypes;

public class JsxParsingTest extends BaseParsingTestCase {
public JsxParsingTest() {
Expand All @@ -13,9 +16,27 @@ public JsxParsingTest() {

public void testOptionAsTag() {
// option here is not a ReasonML keyword
PsiLet let = first(parseCode("let _ = <option className/>", true).getLetExpressions());
PsiLet let = first(parseCode("let _ = <option className/>").getLetExpressions());

PsiTagStart jsx = first(PsiTreeUtil.findChildrenOfType(let, PsiTagStart.class));
assertNotNull(jsx);
}

public void testTagNameWithDot() {
// option here is not a ReasonML keyword
PsiLet let = first(parseCode("let _ = <Container.Test></Container.Test>").getLetExpressions());

PsiTagStart tagStart = first(PsiTreeUtil.findChildrenOfType(let, PsiTagStart.class));
PsiElement nextSibling = tagStart.getFirstChild().getNextSibling();
assertEquals(RmlTypes.INSTANCE.TAG_NAME, nextSibling.getFirstChild().getNode().getElementType());
nextSibling = nextSibling.getNextSibling().getNextSibling();
assertEquals(RmlTypes.INSTANCE.TAG_NAME, nextSibling.getFirstChild().getNode().getElementType());

PsiTagClose tagClose = first(PsiTreeUtil.findChildrenOfType(let, PsiTagClose.class));
nextSibling = tagClose.getFirstChild().getNextSibling();
assertEquals(RmlTypes.INSTANCE.TAG_NAME, nextSibling.getFirstChild().getNode().getElementType());
nextSibling = nextSibling.getNextSibling().getNextSibling();
assertEquals(RmlTypes.INSTANCE.TAG_NAME, nextSibling.getFirstChild().getNode().getElementType());
}

}

0 comments on commit 8b206c9

Please sign in to comment.