Skip to content

fix bare optional/star/plus quantifiers on rule references - #2765

Draft
datduyng wants to merge 4 commits into
mainfrom
domnguyen/fix-optional-rule-ref-match
Draft

fix bare optional/star/plus quantifiers on rule references#2765
datduyng wants to merge 4 commits into
mainfrom
domnguyen/fix-optional-rule-ref-match

Conversation

@datduyng

@datduyng datduyng commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Additive only: bare ?/*/+ now parse like grouped form; required refs, grouped (), and existing patterns unchanged.

We currently have many cases of "?" usage which represent optionality but are treated as literals.

<VideoPhrase> = <Polite>? <CreateVerb> <VideoTarget> <VideoContent>? | <VideoTarget> <FromFiles> | <NeedPhrase> <VideoTarget>;

<VideoPhrase> = <Polite>? <CreateVerb> <VideoTarget> <VideoContent>? | <VideoTarget> <FromFiles> | <NeedPhrase> <VideoTarget>;

https://github.com/search?q=repo%3Amicrosoft%2FTypeAgent+%22%3E%3F%22+path%3A**%2F*.agr&type=code

On main right now, we have below behavior. The PR fix this so that "?" is not treated as a literal

BARE grammar:

<Polite> = please | could you | can you | kindly;
<Start> = <Polite>? open outlook → "matched";

BARE Start expressions:

{
  "type": "ruleReference",
  "name": "Polite",
  "optional": false,
  "repeat": false
},
{
  "type": "string",
  "value": [
    "?",
    "open",
    "outlook"
  ]
}

datduyng and others added 2 commits July 30, 2026 13:57
- Parse <Name>?, <Name>*, <Name>+ as optional/repeat rule refs
  instead of treating "?" as a literal string part
- Propagate optional/repeat through the grammar compiler
  (including phrase-set wrappers)
- Emit bare quantifiers from the rule writer; update category docs
- Add regression tests covering parse, round-trip, and match

Metric (7-case bare-quantifier suite): baseline 3/7 (42.9%) →
treatment 7/7 (100%), +57.1 pp match accuracy
@datduyng
datduyng marked this pull request as draft July 30, 2026 23:43
@datduyng

Copy link
Copy Markdown
Contributor Author

Before

CleanShot 2026-07-30 at 16 47 15@2x

After

CleanShot 2026-07-30 at 16 48 25@2x

datduyng and others added 2 commits July 30, 2026 16:55
- Keep grouped (), required refs, and (the)? string groups unchanged
- Reject wrong tails when optional polite is skipped or taken
@datduyng
datduyng marked this pull request as ready for review July 31, 2026 00:04
@datduyng
datduyng requested a review from curtisman July 31, 2026 00:04
@datduyng
datduyng marked this pull request as draft July 31, 2026 00:52
@datduyng

Copy link
Copy Markdown
Contributor Author

Will work offline and review the design with @curtisman offline first - putting this in draft for now

@datduyng

Copy link
Copy Markdown
Contributor Author

Parked for design debate.

Immediate unblock (grammar-only, no language change): #2775

  • rewrites bare `?` → `( )?` so optionals match under current semantics
  • RFC one-pager for Design A (group-gated, status quo) vs Design B (reserved `?/*/+`, this PR's direction): `ts/packages/actionGrammar/docs/rfc-agr-quantifier-semantics.md`

Leaving this PR draft until Curtis picks A vs B.

bmerkle pushed a commit to bmerkle/TypeAgent that referenced this pull request Aug 1, 2026
- Rewrite all bare `<Name>?` sites in shipping/test `.agr` files to the
supported `(<Name>)?` form so optional rule refs actually match.
- Add a code-heavy one-pager RFC for Curtis on quantifier design: **A**
keep group-gated `?` (this PR) vs **B** reserved postfix `?/*/+`
(direction in microsoft#2765).

On main, `?` after a rule ref is a **literal** token. Quantifiers only
apply after `)`. Authors wrote `<Polite>?` meaning optional; those
patterns never matched.

---------

Co-authored-by: typeagent-bot <typeagent-bot[bot]@users.noreply.github.com>
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