Skip to content

Simplify magic_py_parse#540

Merged
antocuni merged 6 commits into
mainfrom
improve-magic-parse
Jun 2, 2026
Merged

Simplify magic_py_parse#540
antocuni merged 6 commits into
mainfrom
improve-magic-parse

Conversation

@antocuni

@antocuni antocuni commented Jun 1, 2026

Copy link
Copy Markdown
Member

Greatly simplify magic_py_parse. The ultimate goal is to be able to re-use the python parser also with this spy-specific syntax:

var x = 1
const y = 2

The old way detected var x, replaced with a single x and kept a side table with info about whether this particular NAME was by chance a var/const, and the location info.

The new approach is much simpler: the code above becomes:

var·x = 1
const·y = 2

The · is "U+00B7 MIDDLE DOT", and Python considers it a valid char for an identifier. This means that var·x is seen as a single identifier, so the python parser parses it correctly, and then the SPy parser detect this special name.

As usual, special care is needed to ensure that the source location of the rewritten file are kept the same as in the original. E.g.:

    var x: i32 = 100
    var    y     : i32 = 200

becomes:

    var·x: i32 = 100
    var····y     : i32 = 200

antocuni added 6 commits June 2, 2026 00:10
…x' and keep track of the 'varlocs' in a side table, replace it with 'var·x' (with the unicode MIDDLE DOT), which will be easy to detect later by the spy parser
@antocuni antocuni changed the title Improve magic_py_parse Simplify magic_py_parse Jun 1, 2026
@antocuni

antocuni commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@kanin-kearpimy this PR should make it much easier to implement spy fmt.
For reader: see also #496 (and this comment and #457 .

/cc @JeffersGlass as he reviewed #496 .

@antocuni antocuni merged commit 67dbc9b into main Jun 2, 2026
5 checks passed
@antocuni antocuni deleted the improve-magic-parse branch June 2, 2026 16:13
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