Skip to content

Commit

Permalink
WIP v1.1: Add fix for irregular ?! and .=
Browse files Browse the repository at this point in the history
  • Loading branch information
ashelkovnykov committed Jun 14, 2022
1 parent 55c9935 commit 109c96f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ entire Hoon compiler in `.bnf` format. For that reason, some syntax errors may s

With that in mind, due to tokenization issues, the following **correct** Hoon language features are currently marked as
incorrect by the plugin:
- Some uses of irregular wutzap (`?!`) (e.g. `!=(1 2)` interpreted as poorly-formed zaptis expression instead of
`?! .= 1 2`)
- Some uses of irregular tisgal (`=<`) (e.g. `result:~(arm core arg)` interpreted as poorly-formed colsig expression
instead of `=< result %~ arm core arg`)
- Some uses of irregular colhep (`:-`) (e.g. `-^+` interpreted as poorly-formed ketlus expression instead of `:- - +`)
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/ashelkov/hoon/plugin/HoonAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;

import com.ashelkov.hoon.plugin.psi.HoonComplexPath;
import com.ashelkov.hoon.plugin.psi.HoonIrregularNotEqExpression;

public class HoonAnnotator implements Annotator {

Expand All @@ -17,10 +20,19 @@ private void annotateComplexPath(@NotNull final PsiElement element, @NotNull Ann
.create();
}

private void annotateNotEq(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(TextRange.create(element.getTextRange().getStartOffset(), element.getTextRange().getStartOffset() + 2))
.textAttributes(DefaultLanguageHighlighterColors.IDENTIFIER)
.create();
}

@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof HoonComplexPath) {
annotateComplexPath(element, holder);
} else if (element instanceof HoonIrregularNotEqExpression) {
annotateNotEq(element, holder);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/grammar/Hoon.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* _ https://github.com/JetBrains/Grammar-Kit/blob/master/grammars/Grammar.bnf
*
* Known issues:
* - Tokenization errors for irregular wutzap (?!) (e.g. '!=(1 2)' interpreted as poorly-formed zaptis expression
* instead of '?! .= 1 2')
* - Tokenization errors for irregular tisgal (=<) (e.g. 'result:~(arm core arg)' interpreted as poorly-formed colsig
* expression instead of '=< result %~ arm core arg')
* - Tokenization errors for irregular colhep (:-) (e.g. '-^+' interpreted as poorly-formed ketlus expression instead
Expand Down Expand Up @@ -843,7 +841,8 @@ irregular_hoon_expression ::= irregular_tang_expression |
irregular_list_expression |
irregular_cask_expression |
irregular_rune_expression |
irregular_unit_expression
irregular_unit_expression |
irregular_not_eq_expression
{extends=wide_expression}

// Need kettis (^=) to have top priority for cases where assigning multiple faces at once
Expand Down Expand Up @@ -899,6 +898,7 @@ irregular_list_expression ::= <<bracketed <<list_one_or_more wide_expression ACE
irregular_tape_expression ::= GAL <<list_one_or_more wide_expression ACE>> GAR {extends=irregular_hoon_expression}
irregular_tang_expression ::= GAR <<list_one_or_more wide_expression ACE>> GAL {extends=irregular_hoon_expression}
irregular_unit_expression ::= TIC wide_expression {extends=irregular_hoon_expression}
irregular_not_eq_expression ::= ZAPTIS <<paranthesized { wide_expression ACE wide_expression }>>

//
// Specless expressions
Expand All @@ -917,7 +917,8 @@ specless_irregular_expression ::= irregular_tang_expression |
irregular_list_expression |
irregular_cask_expression |
specless_irregular_rune_expression |
irregular_unit_expression
irregular_unit_expression |
irregular_not_eq_expression
{extends=specless_expression}
private specless_irregular_rune_expression ::= irregular_dotlus_expression |
irregular_dottis_expression |
Expand Down

0 comments on commit 109c96f

Please sign in to comment.