feat: Lark parser POC for IOS ACL grammar (closes #374)#375
feat: Lark parser POC for IOS ACL grammar (closes #374)#375
Conversation
Release PreviewNext Version: Changelog PreviewBug Fixes
FeaturesThis version will be automatically released when this PR is merged to main. Reminder: Use conventional commits:
|
| # --- Logging --- | ||
|
|
||
| def ios_log(self, items): | ||
| return "log" |
There was a problem hiding this comment.
ios_log discards log-input token value silently
Medium Severity
The ios_log method hardcodes returning "log" regardless of whether the matched token was "log" or "log-input". The grammar's IOS_LOG terminal matches both, but the transformer discards the distinction. This silently downgrades log-input (which records the input interface) to plain log, causing data loss on round-trip parsing. The actual token value from items[0] is not consulted.
- Fix icomment handler to push Comment to global Comments list during transformation (not deferred to start), matching SimpleParse behavior - Add TODO noting log/log-input distinction is a pre-existing limitation in handle_ios_match, not introduced by the Lark port
Term.__init__() rebinds the module-level Comments list in support.py. Importing Comments by name creates a local binding that goes stale after Term drains it. Access via acl_support.Comments instead.
- _ios_line and icomment rules used _WS (space/tab/newline) where the original SimpleParse grammar uses ts (space/tab only). This caused ambiguity with the NEWLINE token in the start rule. - Removed unused imports: Tree, v_args, Discard, ports, icmp_types, icmp_codes, tcp_flag_specials, make_inverse_mask, strip_comments, exceptions.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Empty 'remark' lines (remark followed by newline with no body text) would fail to parse. The original grammar uses zero-or-more for remark_body. Match icomment's pattern of making the body optional.


Summary
Proof-of-concept evaluating Lark as a replacement for SimpleParse, which is broken on Python 3.12+ (C extension build failures).
Closes #374
Performance Comparison
All tests on Apple Silicon, Python 3.11, Lark 1.3.1 (Earley parser).
Key Findings
_TSvs_WS), which is a fundamental LALR(1) limitationEstimated Effort for Full Port
Files
ios_acl.lark— Complete Lark grammar (148 lines)ios_transformer.py— Lark Transformer producing Trigger ACL objects (200 lines)test_parse.py— 18 test cases covering all IOS ACL featuresbenchmark.py— Performance comparison scriptRESULTS.md— Detailed findings and analysisThis is a proof-of-concept — not production-ready. Files are in
poc-lark/intentionally. The purpose is to validate the approach before investing in a full port.Note
Low Risk
Changes are additive and isolated to
poc-lark/with no integration into production parsing paths; main risk is future adoption of the new grammar/transformer without broader test coverage.Overview
Adds a self-contained
poc-lark/proof-of-concept that ports Trigger’s IOS ACL SimpleParse grammar to a Lark (Earley) grammar and transformer, producing the sameACL/Termobjects via existinghandle_ios_match/handle_ios_acllogic.Includes a small test runner (
test_parse.py) covering 18 IOS ACL cases, a benchmark script comparing SimpleParse vs Lark performance (and demonstrating LALR incompatibility), and a writeup (RESULTS.md) documenting correctness/perf findings and the recommendation to use Earley.Written by Cursor Bugbot for commit 500cc63. This will update automatically on new commits. Configure here.