Skip to content

feat(parsers): add Swift and Objective-C language support#17

Merged
tob-scott-a merged 1 commit into
mainfrom
swift-objc-parsers
Apr 23, 2026
Merged

feat(parsers): add Swift and Objective-C language support#17
tob-scott-a merged 1 commit into
mainfrom
swift-objc-parsers

Conversation

@tob-scott-a

Copy link
Copy Markdown
Collaborator

Two new parsers using tree-sitter-language-pack's swift and objc grammars, which are already installed as transitive dependencies so this lands with no new direct deps.

Swift (.swift):

  • top-level functions, classes, structs, enums, protocols, extensions
  • methods (with parent class/struct/protocol as container)
  • parameter and return-type capture via user_type / type_identifier
  • import declarations captured as graph.dependencies
  • cyclomatic complexity from if/guard/for/while/switch/do/catch
  • @main entrypoint detection

Known gap: Swift throw statements use control_transfer_statement,
which collides with return/break/continue. Capturing throws requires a
Swift-specific walk that filters by throw_keyword — deferred with a
test that locks in non-crash behavior for now.

Objective-C (.m, .mm, .h):

  • top-level C functions (covers main, helper functions)
  • @interface / @implementation classes
  • method signatures from @interface and bodies from @implementation (implementation replaces any earlier stub)
  • selector-based method naming — login:password: preserves both keywords so overloads with different argument labels don't collide
  • #import / #include captured as dependencies
  • UIApplicationDelegate lifecycle selectors flagged as untrusted external API (deep-link handlers, launch callbacks)

Cross-language plumbing:

  • extract_call_name gains a fallback path for grammars that don't label the callable (Swift emits call_expression with an unlabelled first child).
  • _CALL_NAME_TYPES adds simple_identifier and navigation_expression for Swift callables.

Two new parsers using tree-sitter-language-pack's swift and objc
grammars, which are already installed as transitive dependencies so
this lands with no new direct deps.

Swift (.swift):
  - top-level functions, classes, structs, enums, protocols, extensions
  - methods (with parent class/struct/protocol as container)
  - parameter and return-type capture via `user_type` / `type_identifier`
  - import declarations captured as graph.dependencies
  - cyclomatic complexity from if/guard/for/while/switch/do/catch
  - @main entrypoint detection

  Known gap: Swift `throw` statements use `control_transfer_statement`,
  which collides with return/break/continue. Capturing throws requires a
  Swift-specific walk that filters by `throw_keyword` — deferred with a
  test that locks in non-crash behavior for now.

Objective-C (.m, .mm, .h):
  - top-level C functions (covers main, helper functions)
  - @interface / @implementation classes
  - method signatures from @interface and bodies from @implementation
    (implementation replaces any earlier stub)
  - selector-based method naming — `login:password:` preserves both
    keywords so overloads with different argument labels don't collide
  - #import / #include captured as dependencies
  - UIApplicationDelegate lifecycle selectors flagged as untrusted
    external API (deep-link handlers, launch callbacks)

Cross-language plumbing:
  - extract_call_name gains a fallback path for grammars that don't
    label the callable (Swift emits call_expression with an unlabelled
    first child).
  - _CALL_NAME_TYPES adds simple_identifier and navigation_expression
    for Swift callables.

19 new tests (Swift parser, ObjC parser, entrypoint detection for
both). README's supported-languages and framework-coverage tables get
the new rows; the README regression test already caught an earlier
pass where I forgot to add them.

Follow-up languages on the roadmap: Kotlin and Dart/Flutter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tob-scott-a
tob-scott-a merged commit 5ea4cc4 into main Apr 23, 2026
13 checks passed
@tob-scott-a
tob-scott-a deleted the swift-objc-parsers branch April 23, 2026 14:28
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