Skip to content

Is it possible to use this for indentation sensitive languages? #8

Answered by Eliah-Lakhin
haikyuu asked this question in Q&A
Discussion options

You must be logged in to vote

@haikyuu I see. The workaround I suggested above would look as follows:

First, in the lexical grammar of your language, you can introduce special tokens: "LineStart", "Indent", and "Dedent".

#[derive(Token)]
enum MyLangToken {
    #[rule('\n' & ' '*)] // The beginning whitespaces of the line.
    LineStart,

    #[rule("SECRET_INDENT")]
    Indent,

    #[rule("SECRET_DEDENT")]
    Dedent,

    // The rest of the lexis.
}

The "SECRET_INDENT"/"SECRET_DEDENT" words should be special words (maybe some unique Unicode characters) that typically never appear in the end-user's source code.

Next, you introduce an intermediary function that preprocesses raw edits by replacing line-beginning whites…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Eliah-Lakhin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4 on June 22, 2024 17:24.