Skip to content
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

Lexer: add offset getter #1688

Merged
merged 1 commit into from
Feb 25, 2025
Merged

Conversation

aduermael
Copy link
Contributor

Added a getter for the Lexer's private offset to track its cursor position in the buffer.
This helps me index tokens by buffer address in a project where I'm rendering Luau code with Dear ImGui.
Would love this merged so I can use official Luau releases again!

@@ -187,6 +187,11 @@ class Lexer
static bool fixupQuotedString(std::string& data);
static void fixupMultilineString(std::string& data);

int getOffset() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int getOffset() const
unsigned int getOffset() const

The type of offset is unsigned int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right sorry, fixed it!

@aduermael aduermael force-pushed the lexer-add-offset-getter branch from d9415df to 5cfaf41 Compare February 25, 2025 00:12
@aatxe
Copy link
Collaborator

aatxe commented Feb 25, 2025

Thanks for the contribution!

@aduermael
Copy link
Contributor Author

@aatxe Thanks for the approval! I'll hopefully contribute more in the future, now that we're done adopting Luau, replacing Lua 5.3 in our project. 🙂

@aatxe aatxe merged commit 6a21dba into luau-lang:master Feb 25, 2025
7 checks passed
@gdevillele gdevillele deleted the lexer-add-offset-getter branch February 27, 2025 21:18
aatxe added a commit that referenced this pull request Feb 28, 2025
Hey folks, another week means another Luau release! This one features a
number of bug fixes in the New Type Solver including improvements to
user-defined type functions and a bunch of work to untangle some of the
outstanding issues we've been seeing with constraint solving not
completing in real world use. We're also continuing to make progress on
crashes and other problems that affect the stability of fragment
autocomplete, as we work towards delivering consistent, low-latency
autocomplete for any editor environment.

## New Type Solver

- Fix a bug in user-defined type functions where `print` would
incorrectly insert `\1` a number of times.
- Fix a bug where attempting to refine an optional generic with a type
test will cause a false positive type error (fixes #1666)
- Fix a bug where the `refine` type family would not skip over
`*no-refine*` discriminants (partial resolution for #1424)
- Fix a constraint solving bug where recursive function calls would
consistently produce cyclic constraints leading to incomplete or
inaccurate type inference.
- Implement `readparent` and `writeparent` for class types in
user-defined type functions, replacing the incorrectly included `parent`
method.
- Add initial groundwork (under a debug flag) for eager free type
generalization, moving us towards further improvements to constraint
solving incomplete errors.

## Fragment Autocomplete

- Ease up some assertions to improve stability of mixed-mode use of the
two type solvers (i.e. using Fragment Autocomplete on a type graph
originally produced by the old type solver)
- Resolve a bug with type compatibility checks causing internal compiler
errors in autocomplete.

## Lexer and Parser

- Improve the accuracy of the roundtrippable AST parsing mode by
correctly placing closing parentheses on type groupings.
- Add a getter for `offset` in the Lexer by @aduermael in #1688
- Add a second entry point to the parser to parse an expression,
`parseExpr`

## Internal Contributors

Co-authored-by: Andy Friesen <[email protected]>
Co-authored-by: Ariel Weiss <[email protected]>
Co-authored-by: Aviral Goel <[email protected]>
Co-authored-by: Hunter Goldstein <[email protected]>
Co-authored-by: James McNellis <[email protected]>
Co-authored-by: Talha Pathan <[email protected]>
Co-authored-by: Vighnesh Vijay <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>

---------

Co-authored-by: Hunter Goldstein <[email protected]>
Co-authored-by: Varun Saini <[email protected]>
Co-authored-by: Alexander Youngblood <[email protected]>
Co-authored-by: Menarul Alam <[email protected]>
Co-authored-by: Aviral Goel <[email protected]>
Co-authored-by: Vighnesh <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants