-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbol range, not line highlighting #1364
Labels
enhancement
New feature or request
Comments
chevrotrain parser is a bit longer (and should be much faster) (function animationParser() {
// ----------------- Lexer -----------------
const createToken = chevrotain.createToken;
const Lexer = chevrotain.Lexer;
const CstParser = chevrotain.CstParser;
const num = createToken({ name: "num", pattern: /\d+/ });
const dash = createToken({ name: "dash", pattern: /-/ });
const leftSquare = createToken({ name: "leftSquare", pattern: /\[/ });
const rightSquare = createToken({ name: "rightSquare", pattern: /\]/ });
const comma = createToken({ name: "comma", pattern: /,/ });
const pipe = createToken({ name: "pipe", pattern: /\|/ });
let allTokens = [
num,
dash,
leftSquare,
rightSquare,
comma,
pipe
];
let AnimationLexer = new Lexer(allTokens);
class AnimationParse extends CstParser {
constructor() {
super(allTokens);
const $ = this;
$.RULE("range", () => {
$.CONSUME1(num)
$.CONSUME(dash)
$.CONSUME2(num)
});
$.RULE("charRanges", () => {
$.CONSUME(leftSquare)
$.AT_LEAST_ONE_SEP({
SEP: comma,
DEF: () => {
$.SUBRULE($.range);
},
});
$.CONSUME(rightSquare)
})
$.RULE("wordRange", () => {
$.CONSUME(num)
$.SUBRULE($.charRanges)
});
$.RULE("item", () => {
$.OR([
{ ALT: () => $.SUBRULE($.wordRange) },
{ ALT: () => $.SUBRULE($.range) },
{ ALT: () => $.CONSUME(num) },
]);
});
$.RULE("items", () => {
$.AT_LEAST_ONE_SEP({
SEP: comma,
DEF: () => {
$.SUBRULE($.item)
},
});
});
$.RULE("steps", () => {
$.AT_LEAST_ONE_SEP({
SEP: pipe,
DEF: () => $.SUBRULE($.items)
});
});
this.performSelfAnalysis();
}
}
return {
lexer: AnimationLexer,
parser: AnimationParse,
defaultRule: "steps"
}
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Sometimes I find myself in a situation when I need to highlight only a part of a line, not the whole line, for example:
I have fenced the interesting parts with
■
sign.Describe the solution you'd like
I think that the current syntax on step-by-step code animation can be extended to support it in a backwards-compatible way, by introducing additional syntax like
Parser for expressions like this still will be relatively simple, for example peggyjs grammar will go like this:
It parses correctly even more complex expressions like
Describe alternatives you've considered
You have answered why it doesn't make sense to implement it with
glow
in your comment #1358 (comment)The text was updated successfully, but these errors were encountered: