Skip to content

modfile: support autolambda directive - #159

Merged
xushiwei merged 2 commits into
mainfrom
fennoai/issue-158-1786341075
Aug 10, 2026
Merged

modfile: support autolambda directive#159
xushiwei merged 2 commits into
mainfrom
fennoai/issue-158-1786341075

Conversation

@fennoai

@fennoai fennoai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Resolves #158.

What

Adds support for the autolambda directive in gox.mod and stores the parsed result in Project.AutoLambdas.

autolambda times(1), forEver(0), onKey(1)

Each name(n) entry maps a command's identifier to the number of non-lambda arguments that appear before the (implicit) trailing lambda.

Details

  • New autolambda case in parseVerb (modfile/rule.go), placed after the existing pack directive.
  • Must be declared after a project definition (consistent with class / import / pack).
  • Multiple entries may be declared in a single directive (comma-separated) or spread across multiple autolambda lines within the same project; all entries merge into Project.AutoLambdas.
  • Robust parsing over the gox.mod token stream (the tokenizer splits (, ) and , into separate tokens), with descriptive error messages for malformed entries.

Tests

Added to modfile/rule_test.go:

  • TestParseAutoLambda — single directive with multiple entries.
  • TestParseMultiAutoLambda — entries spread across multiple lines.
  • TestParseNoAutoLambda — absence leaves AutoLambdas nil.
  • TestParseAutoLambdaErr — error cases (before project, missing args, malformed name(n), invalid number, missing separators, trailing comma).

go test ./... and go vet ./modfile/ pass. go.mod / go.sum are unchanged.

Parse the `autolambda name(n), ...` directive in gox.mod and store the
results in Project.AutoLambdas (command => number of non-lambda arguments
before the trailing implicit lambda). Multiple entries may appear in one
directive or across multiple autolambda lines within a project.

Fixes #158
@fennoai fennoai Bot mentioned this pull request Aug 10, 2026
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.23%. Comparing base (b41b6c1) to head (5b58a95).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
+ Coverage   76.96%   81.23%   +4.26%     
==========================================
  Files          11       10       -1     
  Lines         890      906      +16     
==========================================
+ Hits          685      736      +51     
+ Misses        186      151      -35     
  Partials       19       19              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review: autolambda directive parser

The change is clean and well-structured: parseAutoLambdas is a pure, testable function, isIdent is the right choice over parseSymbol (autolambda names are lowercase method names), strconv.Atoi correctly rejects overflow and non-numeric input while the explicit nArgs < 0 check handles negatives, and the error paths are thoroughly tested. Build and the new tests pass locally.

Two concrete findings are left inline. Additional minor observations below.

Minor observations (non-blocking):

  • modfile/rule.go:95 — the AutoLambdas field comment ("number of parameters before auto lambda") is terse; expanding it to explain what the count controls would help future readers.
  • isIdent restricts command names to ASCII [A-Za-z_][A-Za-z0-9_]*, stricter than the underlying modfile tokenizer. Almost certainly intentional, but worth confirming XGo command names are never non-ASCII.
  • No test pins the duplicate-name semantics (same name within one directive or across two autolambda directives). Whatever behavior is chosen for the inline finding below, add a test to lock it in.

Comment thread modfile/rule.go Outdated
Comment thread modfile/rule.go Outdated
@xushiwei
xushiwei merged commit 234ec7e into main Aug 10, 2026
11 checks passed
@fennoai
fennoai Bot deleted the fennoai/issue-158-1786341075 branch August 10, 2026 06:57
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.

modfile: Auto Lambda

1 participant