Skip to content

feat: Lark parser POC for IOS ACL grammar (closes #374)#375

Draft
jathanism wants to merge 6 commits intomainfrom
issue-374-lark-poc
Draft

feat: Lark parser POC for IOS ACL grammar (closes #374)#375
jathanism wants to merge 6 commits intomainfrom
issue-374-lark-poc

Conversation

@jathanism
Copy link
Copy Markdown
Member

@jathanism jathanism commented Feb 18, 2026

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).

ACL Type SimpleParse Lark (Earley) Ratio Notes
Simple (53 chars) 5.85 ms 0.83 ms 0.14x Lark 7x faster
Multi-line (185 chars, 4 terms) 5.88 ms 2.92 ms 0.50x Lark 2x faster
Complex (215 chars, 5 terms) 11.09 ms 14.49 ms 1.3x Lark ~30% slower

Key Findings

  • LALR does not work — the grammar requires context-sensitive whitespace handling (_TS vs _WS), which is a fundamental LALR(1) limitation
  • Earley parser is fast enough — sub-millisecond for typical ACLs, comparable or faster than SimpleParse for most inputs
  • 18/18 test cases pass — identical ACL objects produced (same names, formats, terms, actions, matches, modifiers)
  • Direct grammar translation — SimpleParse EBNF → Lark EBNF was mostly mechanical
  • Lark Transformer is cleaner than SimpleParse DispatchProcessor

Estimated Effort for Full Port

  • IOS: 1-2 days (this POC covers ~95%)
  • JunOS: 3-5 days (more complex nested grammar)
  • Integration & testing: 2-3 days
  • Total: ~1-2 weeks

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 features
  • benchmark.py — Performance comparison script
  • RESULTS.md — Detailed findings and analysis

⚠️ Status

This 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 same ACL/Term objects via existing handle_ios_match/handle_ios_acl logic.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 18, 2026

Release Preview

Next Version: 2.3.0

Changelog Preview

Bug Fixes

  • Address Bugbot findings in Lark POC transformer
    (d2a703f)

  • Make remark body optional to match SimpleParse grammar
    (500cc63)

  • Remove unused _WS terminal and %declare COMMENT
    (e280ff3)

  • Use _TS not _WS in ios_line/icomment rules, remove unused imports
    (5e09b11)

  • Use module-level Comments reference to avoid stale binding
    (912e5c8)

Features

  • Add Lark parser POC for IOS ACL grammar (#374,
    8371388)

This version will be automatically released when this PR is merged to main.

Reminder: Use conventional commits:

  • fix: → Patch release (2.0.0 → 2.0.1)
  • feat: → Minor release (2.0.0 → 2.1.0)
  • feat!: or BREAKING CHANGE: → Major release (2.0.0 → 3.0.0)

# --- Logging ---

def ios_log(self, items):
return "log"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 in Cursor Fix in Web

- 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.
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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.
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.

Replace SimpleParse to unblock Python 3.12+

1 participant