Skip to content

[csharp/v8-spec] Continued improvements in the C# grammar.#4832

Draft
kaby76 wants to merge 17 commits into
antlr:masterfrom
kaby76:g4-v8-continue-april-27
Draft

[csharp/v8-spec] Continued improvements in the C# grammar.#4832
kaby76 wants to merge 17 commits into
antlr:masterfrom
kaby76:g4-v8-continue-april-27

Conversation

@kaby76

@kaby76 kaby76 commented May 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

kaby76 and others added 17 commits April 4, 2026 07:04
…toring.

Three rules — null_coalescing_expression, expression, and range_expression —
had alternatives sharing a long common prefix (unary_expression or
conditional_or_expression), forcing ANTLR4's SLL simulation to scan up to 30
tokens before resolving the decision. Left-factor each rule so the shared
prefix is consumed unconditionally and only a single token of lookahead is
needed for the optional suffix. Add design docs explaining the problem and
fix for each rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… (decision 31)

Extend IsConstantPatternAhead() to return false when LT(1) is '(' and a
comma appears at parenthesis depth 1 — indicating a tuple-positional pattern
such as ("rock", "scissors") or (0, 0), which cannot be a compile-time
constant.  Add IsPositionalPatternAhead() as its complement and gate the
positional_pattern alternative in the grammar with it, making alts 2 and 4
mutually exclusive.  Add design/pattern_positional.md documenting the
ambiguity and the fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… to all targets

Apply the same tuple-comma check and IsPositionalPatternAhead complement to all
remaining language targets: Antlr4ng, Cpp (header + impl), Dart, Go, Java,
JavaScript, Python3, and TypeScript.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ional_expression, doc cleanup

- All targets: fix IsConstantPatternAhead() to detect type-headed positional
  patterns like Point(0,0) where LT(1) is an identifier, not '('.
  C#/Java/Python3/Cpp use speculative type_() parse; Antlr4ng/TS/JS/Go/Dart
  use LT(1)==identifier && LT(2)=='(' heuristic.
- CSharpParser.g4: rewrite conditional_expression to use explicit '?'
  optional instead of the empty-alt form.
- design/primary_expression_mlr.md: fix stray backslashes in code blocks
  (change '\' to '//' to match commenting style).
- design/pattern_positional.md: correct last table row — alt 2 is false
  (speculative type_() + '(' suppresses it), alt 4 is true.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… before left-factoring

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ax-k 16→14

Left-factor field/method/property/indexer declarations in
class_member_declaration, struct_member_declaration, and
interface_member_declaration into a shared typed_member_declaration
rule. Consuming the common attributes/modifiers/type_ prefix once
forces immediate SLL→LL fallback for the ambiguous identifier-led
alternatives, dropping max-k from 16 to 14 and parse time ~3×.

Also add IsPrimaryConstraintAhead() / IsSecondaryConstraintAhead()
predicates and fix BeginVariableDeclaration() to fall back to the
parent context (typed_member_declaration) when the current context
has no children yet. Both fixes applied to all nine target ports:
CSharp, Java, Python3, Go, TypeScript, Antlr4ng, JavaScript, Cpp, Dart.

Add design/typed_member_declaration.md documenting the root cause,
failed sub-rule grouping approach, and the left-factoring solution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kaby76

kaby76 commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

The ECMA 334 Committee is currently working on the spec. Waiting for it to stabilize.

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