Aaronontheweb / Aaronontheweb/ShellSyntaxTree

Support structured control flow (loops) in Bash and PowerShell grammars

未关闭
#71 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
C#
星标
15
派生
0
平均合并
9 分钟
30 天内合并 PR
7

描述

Problem

SPEC.md section 4 states v0.1 does not support control-flow keywords. for, while, do, done, then, fi, case, and esac set IsUnparseable = true.

The grammar is flat:

command := clause (compound_op clause)*

This is load-bearing for real consumers. NetClaw's shell approval gate walks parsed clauses to decide authorization. Commands that hit IsUnparseable fail closed to an approval prompt.

Why it matters

LLM agents emit loops and heredocs constantly. A production corpus of 45 approval-prompted shell commands showed 8 (18%) were for loops, heredocs, or process substitution. All tripped IsUnparseable.

Loops are static constructs. for f in *.txt; do rm "$f"; done does not hide a path behind $(). The approval risk is the body clause (rm). The existing clause model already evaluates that.

Request

Support structured control flow in both grammars:

  • Bash: for / while / until / if / case with do / done / then / else / fi / esac
  • PowerShell: foreach / for / while / do / if / switch

Design intent: parse the loop header and expose body clauses as child clauses in the AST. The loop keyword adds no authorization scope. Consumers (approval gates) can walk body clauses with the same logic they use for && chains.

Priority

Corpus-based order for Bash: for loops first, then heredocs, then while / if. Also consider arithmetic expansion $(( ... )), which the same spec line excludes.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 SPEC.md 的第 4 节以及 Bash 和 PowerShell 现有的扁平命令/子句语法开始。跟踪 IsUnparseable 的设置方式以及 AST 如何公开子句,然后验证列出的结构化构造会生成 approval-gate 消费者可以遍历的子 body 子句,且不会触发 IsUnparseable。

由索引模型根据 Issue 内容生成。

评估

技术栈
bash, csharp, powershell
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。