From 7e21afd7106e204aeb5fea5be1c0cc3aef2ccad3 Mon Sep 17 00:00:00 2001 From: Julian Valentin Date: Sun, 18 Apr 2021 11:01:28 +0200 Subject: [PATCH] Shorten RestructuredtextAnnotatedTextBuilder --- .../RestructuredtextAnnotatedTextBuilder.java | 60 +++++-------------- 1 file changed, 15 insertions(+), 45 deletions(-) diff --git a/ltexls/src/main/java/org/bsplines/ltexls/parsing/restructuredtext/RestructuredtextAnnotatedTextBuilder.java b/ltexls/src/main/java/org/bsplines/ltexls/parsing/restructuredtext/RestructuredtextAnnotatedTextBuilder.java index 4b57fe9..3386884 100644 --- a/ltexls/src/main/java/org/bsplines/ltexls/parsing/restructuredtext/RestructuredtextAnnotatedTextBuilder.java +++ b/ltexls/src/main/java/org/bsplines/ltexls/parsing/restructuredtext/RestructuredtextAnnotatedTextBuilder.java @@ -188,30 +188,36 @@ public CodeAnnotatedTextBuilder addCode(String code) { if (isStartOfLine) { @Nullable Matcher matcher; + boolean blockFound = true; - if (matchExplicitBlock()) { - continue; + if ((matcher = matchFromPosition(footnotePattern)) != null) { + this.blockType = BlockType.FOOTNOTE; + addMarkup(matcher.group()); + } else if ((matcher = matchFromPosition(directivePattern)) != null) { + this.blockType = BlockType.DIRECTIVE; + addMarkup(matcher.group()); + } else if ((matcher = matchFromPosition(commentPattern)) != null) { + this.blockType = BlockType.COMMENT; + addMarkup(matcher.group()); } else if ((matcher = matchFromPosition(gridTableStartPattern)) != null) { this.blockType = BlockType.GRID_TABLE; addMarkup(matcher.group()); - continue; } else if ((matcher = matchFromPosition(simpleTableStartPattern)) != null) { this.blockType = BlockType.SIMPLE_TABLE; addMarkup(matcher.group()); - continue; } else if ((matcher = matchFromPosition(sectionTitleAdronmentPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchFromPosition(lineBlockPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchFromPosition(bulletListPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchFromPosition(enumeratedListPattern)) != null) { addMarkup(matcher.group()); - continue; + } else { + blockFound = false; } + + if (blockFound) continue; } if ((this.blockType == BlockType.COMMENT) || (this.blockType == BlockType.GRID_TABLE) @@ -224,60 +230,44 @@ public CodeAnnotatedTextBuilder addCode(String code) { if ((matcher = matchInlineStartFromPosition(strongEmphasisPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchInlineEndFromPosition(strongEmphasisPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchInlineStartFromPosition(emphasisPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchInlineEndFromPosition(emphasisPattern)) != null) { addMarkup(matcher.group()); - continue; } else if ((matcher = matchInlineStartFromPosition(inlineLiteralPattern)) != null) { addMarkup(matcher.group(), generateDummy()); this.inIgnoredMarkup = true; - continue; } else if ((matcher = matchInlineEndFromPosition(inlineLiteralPattern)) != null) { addMarkup(matcher.group()); this.inIgnoredMarkup = false; - continue; } else if ((matcher = matchInlineStartFromPosition(interpretedTextStartPattern)) != null) { addMarkup(matcher.group(), generateDummy()); this.inIgnoredMarkup = true; - continue; } else if ((matcher = matchInlineEndFromPosition(interpretedTextEndPattern)) != null) { addMarkup(matcher.group()); this.inIgnoredMarkup = false; - continue; } else if ( (matcher = matchInlineStartFromPosition(inlineInternalTargetStartPattern)) != null) { addMarkup(matcher.group(), generateDummy()); this.inIgnoredMarkup = true; - continue; } else if ((matcher = matchInlineEndFromPosition(inlineInternalTargetEndPattern)) != null) { addMarkup(matcher.group()); this.inIgnoredMarkup = false; - continue; } else if ((matcher = matchInlineStartFromPosition(footnoteReferenceStartPattern)) != null) { addMarkup(matcher.group(), generateDummy()); this.inIgnoredMarkup = true; - continue; } else if ((matcher = matchInlineEndFromPosition(footnoteReferenceEndPattern)) != null) { addMarkup(matcher.group()); this.inIgnoredMarkup = false; - continue; } else if ((matcher = matchInlineStartFromPosition(hyperlinkReferenceStartPattern)) != null) { addMarkup(matcher.group(), generateDummy()); this.inIgnoredMarkup = true; - continue; } else if ((matcher = matchInlineEndFromPosition(hyperlinkReferenceEndPattern)) != null) { addMarkup(matcher.group()); this.inIgnoredMarkup = false; - continue; - } - - if (this.inIgnoredMarkup) { + } else if (this.inIgnoredMarkup) { addMarkup(this.curString); } else { addText(this.curString); @@ -357,26 +347,6 @@ public CodeAnnotatedTextBuilder addCode(String code) { this.pos + matcher.group().length()) != null) ? matcher : null); } - private boolean matchExplicitBlock() { - @Nullable Matcher matcher; - - if ((matcher = matchFromPosition(footnotePattern)) != null) { - this.blockType = BlockType.FOOTNOTE; - addMarkup(matcher.group()); - return true; - } else if ((matcher = matchFromPosition(directivePattern)) != null) { - this.blockType = BlockType.DIRECTIVE; - addMarkup(matcher.group()); - return true; - } else if ((matcher = matchFromPosition(commentPattern)) != null) { - this.blockType = BlockType.COMMENT; - addMarkup(matcher.group()); - return true; - } - - return false; - } - private boolean isExplicitBlockType() { return ((this.blockType == BlockType.FOOTNOTE) || (this.blockType == BlockType.DIRECTIVE)