-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1005: Aya quality fake literate r=ice1000 a=ice1000 Fix #1004 bors r+ Co-authored-by: ice1000 <ice1000kotlin@foxmail.com>
- Loading branch information
Showing
26 changed files
with
690 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
cli-impl/src/main/java/org/aya/cli/literate/FlclFaithfulPrettier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.cli.literate; | ||
|
||
import org.aya.pretty.doc.Doc; | ||
import org.aya.util.prettier.PrettierOptions; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record FlclFaithfulPrettier(@Override @NotNull PrettierOptions options) | ||
implements FaithfulPrettier { | ||
public @NotNull Doc highlight(@NotNull FlclToken.File file) { | ||
var highlights = file.tokens().map(FlclToken::toInfo).sorted(); | ||
FaithfulPrettier.checkHighlights(highlights); | ||
return doHighlight(file.sourceCode(), file.startIndex(), highlights); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
cli-impl/src/main/java/org/aya/cli/literate/FlclToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.cli.literate; | ||
|
||
import kala.collection.immutable.ImmutableSeq; | ||
import kala.text.StringSlice; | ||
import org.aya.pretty.doc.Link; | ||
import org.aya.util.error.SourcePos; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record FlclToken( | ||
@NotNull SourcePos range, | ||
@NotNull Type type | ||
) { | ||
public static final @NotNull Link EMPTY_LINK = Link.page(""); | ||
|
||
public record File( | ||
@NotNull ImmutableSeq<FlclToken> tokens, | ||
@NotNull StringSlice sourceCode, | ||
int startIndex | ||
) {} | ||
|
||
public enum Type { | ||
Keyword, Fn, Data, Number, Local, Comment, Symbol | ||
} | ||
|
||
public @NotNull HighlightInfo toInfo() { | ||
return switch (type) { | ||
case Keyword -> new HighlightInfo.Lit(range, HighlightInfo.LitKind.Keyword); | ||
case Number -> new HighlightInfo.Lit(range, HighlightInfo.LitKind.Int); | ||
case Comment -> new HighlightInfo.Lit(range, HighlightInfo.LitKind.Comment); | ||
case Symbol -> new HighlightInfo.Lit(range, HighlightInfo.LitKind.SpecialSymbol); | ||
case Fn -> createRef(HighlightInfo.DefKind.Fn); | ||
case Data -> createRef(HighlightInfo.DefKind.Data); | ||
case Local -> createRef(HighlightInfo.DefKind.LocalVar); | ||
}; | ||
} | ||
|
||
private @NotNull HighlightInfo.Ref createRef(HighlightInfo.@NotNull DefKind kind) { | ||
return new HighlightInfo.Ref(range, EMPTY_LINK, kind, null); | ||
} | ||
} |
Oops, something went wrong.