Skip to content

Commit

Permalink
Reworked parsing of definition lists (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Sep 22, 2023
1 parent dec1f71 commit 0c767d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document provides a high-level view of the changes introduced by release.
=== 0.39.9

- Fix IntelliJ 2023.3 EAP compatibility (#1439)
- Reworked parsing of definition lists (#1432)

=== 0.39.8

Expand Down
58 changes: 43 additions & 15 deletions src/main/java/org/asciidoc/intellij/parser/AsciiDocParserImpl.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.asciidoc.intellij.parser;

import com.intellij.lang.PsiBuilder;
import com.intellij.lang.impl.PsiBuilderImpl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -115,6 +114,8 @@
public class AsciiDocParserImpl {
private static final com.intellij.openapi.diagnostic.Logger LOG =
com.intellij.openapi.diagnostic.Logger.getInstance(AsciiDocParserImpl.class);
public static final String DEL_START_OF_PARAGRAPH = "start_of_paragraph";
public static final String DEL_NONE = "nodel";

private static class SectionMarker {
@SuppressWarnings("checkstyle:visibilitymodifier")
Expand Down Expand Up @@ -285,12 +286,15 @@ public void parse() {
continue;
}

if (at(DESCRIPTION)) {
markPreBlock();
} else if (myBlockMarker.isEmpty() || (myPreBlockMarker != null && myBuilder.rawLookup(((PsiBuilderImpl.ProductionMarker) myPreBlockMarker).getStartIndex() - myBuilder.rawTokenIndex()) != DESCRIPTION)) {
if (myBlockMarker.isEmpty()) {
startBlockNoDelimiter();
}

if (newLines > 0) {
startNewLine();
}
newLines = 0;

if (at(URL_START) || at(URL_LINK) || at(URL_EMAIL) || at(URL_PREFIX)) {
parseUrl();
} else if (at(INLINEIDSTART)) {
Expand Down Expand Up @@ -319,7 +323,11 @@ public void parse() {

private void closeBlockMarker(PsiBuilder.Marker myPreBlockId) {
BlockMarker currentBlock = myBlockMarker.pop();
currentBlock.marker.doneBefore(currentBlock.type, myPreBlockId);
if (currentBlock.delimiter.equals(DEL_START_OF_PARAGRAPH)) {
currentBlock.marker.drop();
} else {
currentBlock.marker.doneBefore(currentBlock.type, myPreBlockId);
}
}


Expand Down Expand Up @@ -779,8 +787,12 @@ private void closeBlocks() {
}

private void closeBlockMarker() {
BlockMarker currentBLock = myBlockMarker.pop();
currentBLock.marker.done(currentBLock.type);
BlockMarker currentBlock = myBlockMarker.pop();
if (currentBlock.delimiter.equals(DEL_START_OF_PARAGRAPH)) {
currentBlock.marker.drop();
} else {
currentBlock.marker.done(currentBlock.type);
}
}

private void parseBlock() {
Expand Down Expand Up @@ -839,11 +851,29 @@ private void startBlockNoDelimiter() {
} else {
myBlockStartMarker = beginBlock();
}
myBlockMarker.push(new BlockMarker("nodel", myBlockStartMarker, AsciiDocElementTypes.BLOCK));
myBlockMarker.push(new BlockMarker(DEL_NONE, myBlockStartMarker, AsciiDocElementTypes.BLOCK));
}

private void startNewLine() {
if (!myBlockMarker.isEmpty() && myBlockMarker.peek().delimiter.equals(DEL_START_OF_PARAGRAPH)) {
return;
}
PsiBuilder.Marker myBlockStartMarker;
if (myPreBlockMarker != null) {
myBlockStartMarker = myPreBlockMarker;
myPreBlockMarker = null;
} else {
myBlockStartMarker = beginBlock();
}
myBlockMarker.push(new BlockMarker(DEL_START_OF_PARAGRAPH, myBlockStartMarker, AsciiDocElementTypes.BLOCK));
}

private void endBlockNoDelimiter() {
if (!myBlockMarker.isEmpty() && myBlockMarker.peek().delimiter.equals("nodel")) {
if (!myBlockMarker.isEmpty() && myBlockMarker.peek().delimiter.equals(DEL_START_OF_PARAGRAPH)) {
dropPreBlock();
closeBlockMarker();
}
if (!myBlockMarker.isEmpty() && myBlockMarker.peek().delimiter.equals(DEL_NONE)) {
dropPreBlock();
closeBlockMarker();
}
Expand All @@ -859,13 +889,11 @@ private void startEnumerationDelimiter() {
} else if (at(DESCRIPTION_END)) {
type = DESCRIPTION_ITEM;
sign = myBuilder.getTokenText();
if (!myBlockMarker.isEmpty()) {
while (!myBlockMarker.isEmpty() && (myBlockMarker.peek().delimiter.equals(DEL_NONE) || myBlockMarker.peek().delimiter.equals(DEL_START_OF_PARAGRAPH))) {
BlockMarker marker = myBlockMarker.peek();
if (marker.delimiter.equals("nodel")) {
dropPreBlock();
myPreBlockMarker = marker.marker;
myBlockMarker.pop();
}
dropPreBlock();
myPreBlockMarker = marker.marker;
myBlockMarker.pop();
}
if (myPreBlockMarker == null) {
return;
Expand Down

0 comments on commit 0c767d3

Please sign in to comment.