Questionable syntax highlighting #11

Closed
opened 2025-12-23 20:27:36 +01:00 by shitpoet · 1 comment
shitpoet commented 2025-12-23 20:27:36 +01:00 (Migrated from github.com)

In some cases, the start of a line is highlighted as a type before it's obvious that it's a type.

EXAMPLE 1

In the example below a person starts a statement "System...", but it's eagerly highlighted as a type (green).
At the same time, "System" is not highlighted as a type after System.out.println("hello") (black).

import java.util.*;

public class Main {
    public static void main(String[] args) {
        System
        System.out.println("hello");
        System
    }
}

EXAMPLE 2

import java.util.Scanner;
public class GuessEverestHeight
{    
    public static void main(String[] args)
    {
        System.out.println("aaa");
        System.out.println("bbb");
        System

        someMethod();
    }
}
In some cases, the start of a line is highlighted as a type before it's obvious that it's a type. **EXAMPLE 1** In the example below a person starts a statement "System...", but it's eagerly highlighted as a type (green). At the same time, "System" is not highlighted as a type after `System.out.println("hello")` (black). <img src='https://sshots.shitpoet.cc/2025-12-23--231646--316777375.png'> ```java import java.util.*; public class Main { public static void main(String[] args) { System System.out.println("hello"); System } } ``` **EXAMPLE 2** <img src='https://sshots.shitpoet.cc/2025-12-23--232624--383627120.png'> ```java import java.util.Scanner; public class GuessEverestHeight { public static void main(String[] args) { System.out.println("aaa"); System.out.println("bbb"); System someMethod(); } } ```
marijnh commented 2025-12-23 22:51:54 +01:00 (Migrated from github.com)

Well, two identifiers that follow each other do unambiguously indicate a declaration in Java, with the first one being the type and the second the name. It's only at .out that this parse becomes invalid. I don't think it's worth adding special rules to the grammar to avoid specific parses of unfinished code.

Well, two identifiers that follow each other do unambiguously indicate a declaration in Java, with the first one being the type and the second the name. It's only at `.out` that this parse becomes invalid. I don't think it's worth adding special rules to the grammar to avoid specific parses of unfinished code.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/java#11
No description provided.