From aba439bc6a3b1bea3b5940b0a34eaa940f4d1258 Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:14:30 -0300 Subject: [PATCH 1/7] create file --- spice/analyzers/count_inline_comments.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spice/analyzers/count_inline_comments.py diff --git a/spice/analyzers/count_inline_comments.py b/spice/analyzers/count_inline_comments.py new file mode 100644 index 0000000..e69de29 From 40202ac09d951f3b9c1a2a37c7297283bec24c98 Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:11 -0300 Subject: [PATCH 2/7] count inline functions --- spice/analyzers/count_inline_comments.py | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spice/analyzers/count_inline_comments.py b/spice/analyzers/count_inline_comments.py index e69de29..381912b 100644 --- a/spice/analyzers/count_inline_comments.py +++ b/spice/analyzers/count_inline_comments.py @@ -0,0 +1,52 @@ +# this will count inline comments, which are lines that have both code and comments +# INLINE COMMENT LINE IS A LINE THAT HAS BOTH CODE AND A COMMENT +# so like: y = 5 #sets y to 5 IS AN INLINE COMMENT LINE!!!!!!!! +from utils.get_lexer import get_lexer_for_file +from lexers.token import TokenType +import os + +def count_inline_comments(file_path): + """Count lines that have both code and comments in a file. + + Args: + file_path (str): Path to the file to analyze + + Returns: + int: Number of lines that have both code and comments + """ + # Get the appropriate lexer for the file + Lexer = get_lexer_for_file(file_path) + + # Read the file content + with open(file_path, 'r', encoding='utf-8') as f: + code = f.read() + + # Initialize lexer with source code + lexer = Lexer(source_code=code) + + # Get all tokens + tokens = lexer.tokenize() + + # Group tokens by line number + tokens_by_line = {} + for token in tokens: + if token.line not in tokens_by_line: + tokens_by_line[token.line] = [] + tokens_by_line[token.line].append(token) + + # Count lines that have both code and comment tokens + inline_comment_count = 0 + for line_num, line_tokens in tokens_by_line.items(): + has_comment = False + has_code = False + + for token in line_tokens: + if token.type == TokenType.COMMENT: + has_comment = True + elif token.type not in [TokenType.NEWLINE, TokenType.COMMENT]: + has_code = True + + if has_comment and has_code: + inline_comment_count += 1 + + return inline_comment_count From 70b853dd9ac4d5738d9da0c293f64aba2ed64eaf Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:19 -0300 Subject: [PATCH 3/7] analyze inline functions --- cli/commands/analyze.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/commands/analyze.py b/cli/commands/analyze.py index 76f4e01..595afa9 100644 --- a/cli/commands/analyze.py +++ b/cli/commands/analyze.py @@ -17,6 +17,7 @@ def analyze_command(file, all, json_output, LANG_FILE): "line_count", "function_count", "comment_line_count", + "inline_comment_count", "indentation_level" ] @@ -25,6 +26,7 @@ def analyze_command(file, all, json_output, LANG_FILE): "line_count": messages.get("line_count_option", "Line Count"), "function_count": messages.get("function_count_option", "Function Count"), "comment_line_count": messages.get("comment_line_count_option", "Comment Line Count"), + "inline_comment_count": messages.get("inline_comment_count_option", "Inline Comment Count"), "indentation_level": messages.get("indentation_level_option", "Indentation Analysis") } From 4774107e63d859bc281f2db751436717339e3c78 Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:28 -0300 Subject: [PATCH 4/7] translations for inline comments --- cli/translations/en.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/translations/en.py b/cli/translations/en.py index 0e3973a..7c9885a 100644 --- a/cli/translations/en.py +++ b/cli/translations/en.py @@ -9,11 +9,13 @@ "line_count": "The file has {count} lines", "function_count": "The file has {count} functions", "comment_line_count": "The file has {count} comment lines", + "inline_comment_count": "The file has {count} inline comments", # keys for analyze command checkbox menu "select_stats": "Select stats to display:", "line_count_option": "Line Count", "function_count_option": "Function Count", "comment_line_count_option": "Comment Line Count", + "inline_comment_count_option": "Inline Comment Count", "no_stats_selected": "No stats selected. Analysis cancelled.", "confirm_and_analyze": "Confirm and analyze", "checkbox_hint": "(Use space to select, enter to confirm)", From b59c61b6e074655cc838738d6f5f61980e9a110c Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:33 -0300 Subject: [PATCH 5/7] translations for inline comments --- cli/translations/pt-br.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/translations/pt-br.py b/cli/translations/pt-br.py index abaff61..c5afdf9 100644 --- a/cli/translations/pt-br.py +++ b/cli/translations/pt-br.py @@ -9,11 +9,13 @@ "line_count": "O arquivo tem {count} linhas", "function_count": "O arquivo tem {count} funções", "comment_line_count": "O arquivo tem {count} linhas de comentário", + "inline_comment_count": "O arquivo tem {count} comentários inline", # chaves para o menu de seleção do comando analyze "select_stats": "Selecione as estatísticas para exibir:", "line_count_option": "Contagem de Linhas", "function_count_option": "Contagem de Funções", "comment_line_count_option": "Contagem de Linhas de Comentário", + "inline_comment_count_option": "Contagem de Comentários Inline", "no_stats_selected": "Nenhuma estatística selecionada. Análise cancelada.", "confirm_and_analyze": "Confirmar e analisar", "checkbox_hint": "(Use espaço para selecionar, enter para confirmar)" From cab9baffec87d8be73dbeca9e81fa1f8f890d986 Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:37 -0300 Subject: [PATCH 6/7] translations for inline comments --- cli/translations/fremen.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/translations/fremen.py b/cli/translations/fremen.py index 546903c..f7bb68b 100644 --- a/cli/translations/fremen.py +++ b/cli/translations/fremen.py @@ -1,7 +1,7 @@ messages = { # keys for the hello command "welcome": "🌶️ Salam, wanderer, and welcome to the sietch of [bold red]SpiceCode[/]! 🌶️", - "description": "🔥 The [yellow]Fedaykin CLI[/] that ignites your code with spice, as fierce as Arrakis’ dunes 🥵", + "description": "🔥 The [yellow]Fedaykin CLI[/] that ignites your code with spice, as fierce as Arrakis' dunes 🥵", # error messages "error": "خطأ:", # keys for the analyze command output @@ -9,11 +9,13 @@ "line_count": "The file spans {count} dunes", "function_count": "The file holds {count} sacred routines", "comment_line_count": "The file whispers {count} lines of hidden lore", + "inline_comment_count": "The file contains {count} passages of dual meaning", # keys for analyze command checkbox menu "select_stats": "Choose the omens to unveil:", "line_count_option": "Dune Count", "function_count_option": "Sacred Routines", "comment_line_count_option": "Whispered Lore", + "inline_comment_count_option": "Passages of Dual Meaning", "no_stats_selected": "No omens were heeded. The analysis fades into the sands.", "confirm_and_analyze": "Seal your fate and analyze", "checkbox_hint": "(Use space to mark, enter to proceed)" From dd4a0c711c36f15e41ef73c0220946d875314ecb Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 21:23:44 -0300 Subject: [PATCH 7/7] account for inline comments --- spice/analyze.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spice/analyze.py b/spice/analyze.py index 1ecb34a..ca40aa4 100644 --- a/spice/analyze.py +++ b/spice/analyze.py @@ -10,7 +10,8 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) -> Args: file_path (str): Path to the file to analyze selected_stats (list, optional): List of stats to compute. If None, compute all stats. - Valid stats are: "line_count", "function_count", "comment_line_count", "indentation_level" + Valid stats are: "line_count", "function_count", "comment_line_count", + "inline_comment_count", "indentation_level" Returns: dict: Dictionary containing the requested stats and file information @@ -34,7 +35,7 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) -> raise ValueError("File has no extension") # Define valid stats - valid_stats = ["line_count", "function_count", "comment_line_count", "indentation_level"] + valid_stats = ["line_count", "function_count", "comment_line_count", "inline_comment_count", "indentation_level"] # default to all stats if none specified if selected_stats is None: @@ -71,6 +72,14 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) -> lexer = LexerClass(source_code=code) # Pass source_code explicitly results["comment_line_count"] = count_comment_lines(file_path) + # inline comment count if requested + if "inline_comment_count" in selected_stats: + from spice.analyzers.count_inline_comments import count_inline_comments + from utils.get_lexer import get_lexer_for_file + LexerClass = get_lexer_for_file(file_path) + lexer = LexerClass(source_code=code) # Pass source_code explicitly + results["inline_comment_count"] = count_inline_comments(file_path) + # indentation analysis if requested if "indentation_level" in selected_stats: indentation_info = detect_indentation(code)