Skip to content

display-v2: lexer #22216

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

display-v2: lexer #22216

wants to merge 12 commits into from

Conversation

amnn
Copy link
Contributor

@amnn amnn commented May 23, 2025

Description

Implementing a lexer that tokenizes everything needed for the Display v2 grammar.

Test plan

New unit tests:

sui$ cargo nextest run -p sui-display

Stack


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

amnn added 12 commits May 23, 2025 12:54
## Description

Remove support for showing Display fields from `IndexerReader` and
`sui-indexer`'s JSON-RPC implementation. This implementation is not in
use, and the removal is intended to simplify future work on Display.

## Test plan

```
sui$ cargo nextest run \
  -p sui-indexer       \
  -p sui-graphql-rpc   \
  -p sui-graphql-e2e-tests
```
## Description

Switch the implementation of `Display` in legacy GraphQL from a copy of
the fullnode implementation to the `sui-display` implementation.

This is a trial run for making the same change to fullnodes.

## Test plan

E2E tests:

```
sui$ cargo nextest run -p sui-graphql-e2e-tests
```

Changes affect output order, (entries are now ordered by key name), and
wording for errors.
## Description

Use the `sui-display` crate to implement Display v1 handling on
fullnodes. This change brings all code responsible for rendering Display
strings inline to using the same implementation, which is better tested
and has better support for enforcing limits etc.

## Test plan

Manually tested that fullnode Display support continue to work after
this change. `sui-display` has already been tested against all existing
Display strings on mainnet to check that they parse successfully or if
they produce an error, it's for an expected reason.
## Description

Starting work on Display v2, with the lexer for the base grammar (the
grammar supporting the same feature set as Display v1). The only
difference is that curlies are escaped by doubling them up, instead of
using the `\` character.

## Test plan

New unit tests:

```
sui$ cargo nextest run -p sui-display
```
## Description

Tokenize syntax for indexing into things (both the single and double
bracket variants), and alternates. This is enough syntax to implement
data structure and dynamic field accesses which may fail.

## Test plan

New unit tests:

```
sui$ cargo nextest run -p sui-display
```
## Description

Lexing decimal and hexadecimal numbers with optional underscore
separators.

## Test plan

New unit tests:

```
sui$ cargo nextest run -p sui-display
```
## Description

Lexing tokens for types and vector literals (fully-qualified struct
types and type parameters).

## Test plan

```
sui$ cargo nextest run -p sui-display
```
## Description

Parentheses are used in the representation of positional structs and
variants.

## Test plan

New unit tests

```
sui$ cargo nextest run -p sui-display
```
## Description
'@' will be used to indicate that a number should be interpreted as an
address literal.

## Test plan

New unit tests:

```
sui$ cargo nextest run -p sui-display
```
## Description

Tokenize colons, making it possible to lex all parts of a struct literal
with field names.

## Test plan

```
sui$ cargo nextest run -p sui-display
```
## Description

Tokenize `#` which separates an enum variant's optional name and its
index.

## Test plan

```
sui$ cargo nextest run -p sui-display
```
## Description

Tokenize strings, byte-strings and hex-strings.

## Test plan

New unit tests:

```
sui$ cargo nextest run -p sui-display
```
@amnn amnn requested review from damirka, Bridgerz, manolisliolios, a team and Copilot May 23, 2025 12:02
@amnn amnn self-assigned this May 23, 2025
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) May 23, 2025 0:03am
sui-kiosk ⬜️ Ignored (Inspect) May 23, 2025 0:03am

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a new lexer for the Display v2 grammar and updates module exports to support the new implementation.

  • Added a new lexer module in the v2 directory.
  • Clarified comment language in the v1 lexer regarding escape sequence tokenization.
  • Updated the library module to expose the new v2 module.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/sui-display/src/v2/mod.rs Introduces the new lexer module for Display v2.
crates/sui-display/src/v1/lexer.rs Updates comment to clarify tokenization of escapes.
crates/sui-display/src/lib.rs Exposes the new v2 module.

@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 23, 2025 12:03 — with GitHub Actions Inactive
Unexpected,

/// Whitespace around expressions.
Whitespace,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Treating whitespace as an explicit token because there are some forms that are whitespace sensitive:

  • Double square brackets.
  • String literals with prefixes.
  • Numeric literals with suffixes.

Base automatically changed from amnn/sui-display to main May 27, 2025 17:19
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