Skip to content

Commit

Permalink
AST: also store the column number in Idents (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlb authored Apr 17, 2024
1 parent bb7a4a1 commit 879ffa2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ open Options.Globals
[<RequireQualifiedAccess>]
type VarScope = Global | Local | Parameter

type Location = { line: int; col: int }

type Ident(name: string) =
let mutable newName = name

Expand All @@ -15,12 +17,10 @@ type Ident(name: string) =
// This prefix disables function inlining and variable inlining.
member this.DoNotInline = this.OldName.StartsWith("noinline_")

member val LineNb = -1 with get, set
member val Loc = {line = -1; col = -1} with get, set

static member WithLineNb(name, lineNb) =
let id = Ident(name)
id.LineNb <- lineNb
id
new(name, lineNb, colNb) as this = Ident(name) then
this.Loc <- {line = lineNb; col = colNb}

//member val isVarRead: bool = false with get, set
member val isVarWrite: bool = false with get, set
Expand Down
2 changes: 1 addition & 1 deletion src/parse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type private ParseImpl() =
let ident =
let nonDigit = asciiLetter <|> pchar '_'
let p = pipe3 getPosition nonDigit (manyChars (nonDigit <|> digit <?> "")) (
fun pos c s -> Ast.Ident.WithLineNb (c.ToString() + s, int pos.Line))
fun pos c s -> Ast.Ident(c.ToString() + s, int pos.Line, int pos.Column))
let p = p >>= (fun s -> if Builtin.keywords.Contains(s.Name) then fail "ident is a keyword" else preturn s)
(p .>> ws) <?> "identifier"

Expand Down

0 comments on commit 879ffa2

Please sign in to comment.