Skip to content

Conversation

@c42f
Copy link
Member

@c42f c42f commented Dec 30, 2024

Most operators are semantically just normal identifiers after parsing so should get the Kind K"Identifier". For example, after this change a + b parses with K"Identifier" kind for the + token.

As an exception, standalone syntactic ops keep their kind - they can't really be used in a sane way as identifiers or interpolated into expressions in the normal way because they have their own syntactic forms. This also helps us in Expr conversion where they also have their own rules for coalescing with dots, when dotted.

Also introduce a new keyword operators_as_identifiers to the tokenize() API to accommodate some simple uses of this API to colour token strings by operator type, even when the operator is semantically in identifier-position.

Fix #474 as a follow-on from #456

CC @fredrikekre

Most operators are semantically just normal identifiers after parsing so
get the Kind `K"Identifier"`. For example, `a + b` parses with
`K"Identifier"` kind for the `+` token.

As an exception, standalone syntactic ops keep their kind - they can't
really be used in a sane way as identifiers or interpolated into
expressions in the normal way because they have their own syntactic
forms. This also helps us in `Expr` conversion where they also have
their own rules for coalescing with dots, when dotted.

Also introduce a new keyword `operators_as_identifiers` to the
`tokenize()` API to accommodate some simple uses of this API to colour
token strings by operator type, even when the operator is semantically
in identifier-position.
@c42f c42f merged commit 35dc3bc into main Dec 30, 2024
36 checks passed
@c42f c42f deleted the caf/operator-tokens-as-identifiers branch December 30, 2024 20:30
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…g/JuliaSyntax.jl#523)

Most operators are semantically just normal identifiers after parsing so
should get the Kind `K"Identifier"`. For example, after this change `a + b`
parses with `K"Identifier"` kind for the `+` token.

As an exception, standalone syntactic ops keep their kind - they can't
really be used in a sane way as identifiers or interpolated into
expressions in the normal way because they have their own syntactic
forms. This also helps us in `Expr` conversion where they also have
their own rules for coalescing with dots, when dotted.

Also introduce a new keyword `operators_as_identifiers` to the
`tokenize()` API to accommodate some simple uses of this API to colour
token strings by operator type, even when the operator is semantically
in identifier-position.
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.

Remap operator tokens to K"Identifier" during parsing

1 participant