Skip to content

Reconstruct negative literal in parser#5

Open
inmaldrerah wants to merge 2 commits intoCJPLUK:interfacesfrom
inmaldrerah:patch-reconstruct-negative-literal
Open

Reconstruct negative literal in parser#5
inmaldrerah wants to merge 2 commits intoCJPLUK:interfacesfrom
inmaldrerah:patch-reconstruct-negative-literal

Conversation

@inmaldrerah
Copy link
Copy Markdown

Before this PR, negative number literals are constructed as UnaryExpr(SUB, LitConstExpr(...)). However, the std.ast library does that differently:

import std.ast.*
import std.reflect.*

main() {
  println(quote(-1))
  println(ClassTypeInfo.of(parseExpr(quote(-1))))
  println((parseExpr(quote(-1)) as LitConstExpr).getOrThrow().literal.value)
}

prints:

- 1
std.ast.LitConstExpr
-1

which means std.ast directly constructs LitConstExpr with token -1 from tokens - and 1. This PR supports such reconstruction.

@inmaldrerah inmaldrerah marked this pull request as ready for review November 12, 2025 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant