Uses 1485K of libraries. Click here for Pure Java version (5279L/29K).
// I think tokens should not cross lines, it messes about // RSyntaxTextArea's hyperlink finding. please include class RSyntaxTextArea. import org.fife.ui.rsyntaxtextarea.TokenMakerBase; sclass HashRefTokenMaker extends TokenMakerBase { delegate Token to org.fife.ui.rsyntaxtextarea. /** * Returns a list of tokens representing the given text. * * @param text The text to break into tokens. * @param startTokenType The token with which to start tokenizing. * @param startOffset The offset at which the line of tokens begins. * @return A linked list of tokens representing <code>text</code>. */ @Override public Token getTokenList(Segment text, int startTokenType, final int startOffset) { resetTokenList(); char[] array = text.array; int offset = text.offset; int count = text.count; int end = offset + count; int newStartOffset = startOffset - offset; S src = str(array, offset, count); LS tok = hashRefTok(src); int ofs = offset; for i, t over tok: { if (empty(t)) continue; bool isHyperlink = odd(i); // split at line breaks, spaces and punctuation to allow // word wrapping (does it work?) for (part : singlePredTok(c -> isSpaceEtc(c), t)) { if (nempty(part)) { var tokenType = isHyperlink ? Token.VARIABLE : startsWithSpaceEtc(part) ? Token.WHITESPACE : Token.IDENTIFIER; int l = l(part); addToken(array, ofs, ofs+l-1, tokenType, ofs+newStartOffset, isHyperlink); ofs += l; } } } addNullToken(); // Return the first token in our linked list. ret firstToken; } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034700 |
Snippet name: | HashRefTokenMaker - for auto-completion [dev.] |
Eternal ID of this version: | #1034700/14 |
Text MD5: | 9872009dfa08aad7598c07307acd7cf9 |
Transpilation MD5: | 049903486f6a0b3139e5c1c60b286987 |
Author: | stefan |
Category: | javax / tokenizing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-06 18:48:26 |
Source code size: | 1742 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 168 / 312 |
Version history: | 13 change(s) |
Referenced in: | [show references] |