Skip to content

Add support of locations in AST #524

Closed
@frolovdev

Description

@frolovdev

Proposal

I go through the sources of the parser and find out that there is no such thing as a location in AST

I have in mind something like this:

lexer layer

pub enum Token {
   EOF { loc: Option<Loc> },
   Word { value: Word, loc: Option<Loc> }
  // and so on
}

struct Loc {
   start: i32
   end: i32
   line: i32
   column: i32
}

parser layer

pub enum Expr {
   Identifier{ value: Ident, loc: Option<Loc> },
 }

struct Loc {
   start: i32
   end: i32
   startToken: Token,
   endToken: Token
}

Behind motivation
Much better error reporting

Proposal design highlights

Why Option<Loc>?

We can allow to run the CLI in different modes, with emitting and not emitting locations

Plan of migration

Doesn't cover it right now ( but I have in mind high-level plan of gradual migration). Just want to discuss the idea first of all


@alamb what do you think? I can drive this migration if we discuss details and make a decision about it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions