To add support for a new programming language, you must implement a language reader that follows the Lizard architecture. This involves creating a reader class, defining condition categories for cyclomatic complexity calculation, implementing token generation, and defining a state machine for parsing.
Core Components:
- Reader Class: Inherits from
CodeReader. It defines file extensions (ext), command line names (language_names), and condition categories. - Condition Categories: Four specific sets of keywords/operators that increment Cyclomatic Complexity (CCN).
- Token Generation: Customizing how the language's tokens are identified.
- State Machine: A
CodeStateMachine to handle the structural parsing (e.g., identifying function boundaries).
Integration Steps:
- Create a new file in
lizard_languages/ (e.g., mylang.py). - Register the reader in
lizard_languages/__init__.py. - Add tests in
test/test_languages/testMyLang.py. - Run tests using:
nix develop -c python -m pytest test/test_languages/testMyLang.py.
from .code_reader import CodeReader, CodeStateMachine
from .clike import CCppCommentsMixin
class MyLanguageReader(CodeReader, CCppCommentsMixin):
ext = ['mylang']
language_names = ['mylanguage', 'mylang']
_control_flow_keywords = {'if', 'for', 'while', 'catch'}
_logical_operators = {'&&', '||'}
_case_keywords = {'case'}
_ternary_operators = {'?'}
def __init__(self, context):
super(MyLanguageReader, self).__init__(context)
self.parallel_states = [MyLanguageStates(context)]