Emmet: parse incomplete more/climb abbreviations

This commit is contained in:
Alexander Zolotov
2014-05-06 19:44:58 +04:00
parent 3bc511469a
commit b6f41b4779
3 changed files with 26 additions and 31 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator;
import com.intellij.codeInsight.template.emmet.nodes.*;
import com.intellij.codeInsight.template.emmet.tokens.*;
import com.intellij.codeInsight.template.impl.TemplateImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -90,18 +89,15 @@ public abstract class EmmetParser {
if (sign == '^') {
return parseClimbUpOperation(mul);
}
if (mul == null) {
return null;
}
if (sign == '+') {
advance();
ZenCodingNode add2 = parseAddOrMore();
if (add2 == null) {
return null;
return mul;
}
return new AddOperationNode(mul, add2);
return new AddOperationNode(notNullNode(mul), add2);
}
else if (sign == '>') {
if (sign == '>') {
return parseMoreOperation(mul);
}
return null;
@@ -109,23 +105,28 @@ public abstract class EmmetParser {
protected ZenCodingNode parseClimbUpOperation(@Nullable ZenCodingNode leftPart) {
advance();
leftPart = leftPart != null ? leftPart : ZenEmptyNode.INSTANCE;
ZenCodingNode rigthPart = parseAddOrMore();
if (rigthPart == null) {
return null;
}
return new ClimbUpOperationNode(leftPart, rigthPart);
}
protected ZenCodingNode parseMoreOperation(@NotNull ZenCodingNode leftPart) {
advance();
leftPart = notNullNode(leftPart);
ZenCodingNode rightPart = parseAddOrMore();
if (rightPart == null) {
return null;
return leftPart;
}
return new ClimbUpOperationNode(leftPart, rightPart);
}
protected ZenCodingNode parseMoreOperation(@Nullable ZenCodingNode leftPart) {
advance();
leftPart = notNullNode(leftPart);
ZenCodingNode rightPart = parseAddOrMore();
if (rightPart == null) {
return leftPart;
}
return new MoreOperationNode(leftPart, rightPart);
}
private static ZenCodingNode notNullNode(ZenCodingNode node) {
return node != null ? node : ZenEmptyNode.INSTANCE;
}
protected int advance() {
return myIndex++;
}
@@ -207,11 +208,6 @@ public abstract class EmmetParser {
return new TemplateNode(templateToken);
}
@Nullable
protected String getDefaultTemplateKey() {
return null;
}
protected boolean setTemplate(final TemplateToken token, TemplateImpl template) {
if (template == null) {
template = myGenerator.createTemplateByKey(token.getKey());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ public class XmlEmmetParser extends EmmetParser {
private boolean hasTagContext = false;
private final Stack<String> tagLevel = new Stack<String>();
private static Map<String, String> parentChildTagMapping = new HashMap<String, String>() {{
private static final Map<String, String> parentChildTagMapping = new HashMap<String, String>() {{
put("p", "span");
put("ul", "li");
put("ol", "li");
@@ -159,7 +159,7 @@ public class XmlEmmetParser extends EmmetParser {
}
@Override
protected ZenCodingNode parseMoreOperation(@NotNull ZenCodingNode leftPart) {
protected ZenCodingNode parseMoreOperation(@Nullable ZenCodingNode leftPart) {
String parentTag = getParentTag(leftPart);
boolean hasParent = false;
if (!Strings.isNullOrEmpty(parentTag)) {
@@ -177,8 +177,7 @@ public class XmlEmmetParser extends EmmetParser {
}
@Nullable
@Override
protected String getDefaultTemplateKey() {
private String getDefaultTemplateKey() {
return ZenCodingUtil.isHtml(myCallback) ? suggestTagName() : null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ public class AddOperationNode extends ZenCodingNode {
private final ZenCodingNode myLeftOperand;
private final ZenCodingNode myRightOperand;
public AddOperationNode(ZenCodingNode leftOperand, ZenCodingNode rightOperand) {
public AddOperationNode(@NotNull ZenCodingNode leftOperand, @NotNull ZenCodingNode rightOperand) {
myLeftOperand = leftOperand;
myRightOperand = rightOperand;
}