Skip to content

feat: add .xs file support and fix Perl call extraction#80

Open
potatogim wants to merge 2 commits intotirth8205:mainfrom
potatogim:main
Open

feat: add .xs file support and fix Perl call extraction#80
potatogim wants to merge 2 commits intotirth8205:mainfrom
potatogim:main

Conversation

@potatogim
Copy link
Copy Markdown

Summary

  • Map .xs (Perl XS) extension to the C parser — XS files are predominantly
    C code, so tree-sitter-c captures functions, structs, and #include directives
    correctly while gracefully ignoring XS-specific macros (MODULE, CODE:, etc.)
  • Fix two silent bugs in Perl call extraction that caused all method/built-in calls
    to be dropped from the call graph
  • Add TestXSParsing test class and strengthen TestPerlParsing assertions

Bug Fixes

$obj->method() calls were silently ignored

_get_call_name() assumed all languages use an identifier child for call
expressions. Perl's method_call_expression uses a method child instead,
so the function returned None for every OOP method call — no CALLS edges
were produced for arrow-operator calls.

Built-in calls (print, bless, die, warn) were not captured

tree-sitter-perl parses Perl built-ins as ambiguous_function_call_expression
nodes, which were missing from _CALL_TYPES["perl"]. These calls were
silently skipped during graph construction.

Changes

File Change
code_review_graph/parser.py Add .xs → c to EXTENSION_TO_LANGUAGE
code_review_graph/parser.py Add ambiguous_function_call_expression to _CALL_TYPES["perl"]
code_review_graph/parser.py Handle method_call_expression in _get_call_name()
tests/fixtures/sample.xs New XS fixture (struct + C functions + XS macros)
tests/fixtures/sample.pl Use $self->speak() to exercise method call path
tests/test_multilang.py Add TestXSParsing (6 tests); strengthen Perl call assertions

Test Plan

  • TestXSParsing — 6 new tests: language detection, struct, functions,
    includes, calls, contains
  • TestPerlParsing.test_finds_calls now asserts specific targets
    (speak via method call, bless via ambiguous call)
  • Full test suite: 508 passed, 5 skipped — no regressions

- Map .xs extension to C parser (Perl XS files contain C code)
- Add ambiguous_function_call_expression to _CALL_TYPES["perl"]
  to capture built-in calls like print, bless, die, warn
- Add Perl method_call_expression handling in _get_call_name()
  to extract method names from $obj->method() calls
- Add tests/fixtures/sample.xs with struct, C functions, and XS macros
- Add TestXSParsing class with 6 tests (language detection, structs,
  functions, includes, calls, contains)
- Update CLAUDE.md to mention XS in test description

Signed-off-by: Jihyeon Gim <potatogim@potatogim.net>
- Add explicit return None after method_call_expression loop in
  _get_call_name() to clarify intent when no method child is found
- Update sample.pl bark() to use $self->speak() (method_call_expression)
  so the new OOP call path is directly exercised by tests
- Strengthen TestPerlParsing.test_finds_calls: assert "speak" and "bless"
  are in call targets (covers method_call_expression and
  ambiguous_function_call_expression respectively)
- Strengthen TestXSParsing assertions: assert "_add" in call targets
  and >= 3 CONTAINS edges (Point, _add, compute_distance)

Signed-off-by: Jihyeon Gim <potatogim@potatogim.net>
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