csim 3.2.0__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {csim-3.2.0 → csim-3.3.0}/MANIFEST.in +8 -0
  2. {csim-3.2.0/csim.egg-info → csim-3.3.0}/PKG-INFO +46 -11
  3. {csim-3.2.0 → csim-3.3.0}/README.md +45 -10
  4. {csim-3.2.0 → csim-3.3.0}/csim/Visitors.py +45 -0
  5. csim-3.3.0/csim/c/CLexer.py +993 -0
  6. csim-3.3.0/csim/c/CLexer.tokens +270 -0
  7. csim-3.3.0/csim/c/CLexerBase.py +118 -0
  8. csim-3.3.0/csim/c/CParser.py +10663 -0
  9. csim-3.3.0/csim/c/CParser.tokens +270 -0
  10. csim-3.3.0/csim/c/CParserBase.py +668 -0
  11. csim-3.3.0/csim/c/CParserVisitor.py +598 -0
  12. csim-3.3.0/csim/c/ErrorListener.py +46 -0
  13. csim-3.3.0/csim/c/Symbol.py +20 -0
  14. csim-3.3.0/csim/c/SymbolTable.py +197 -0
  15. csim-3.3.0/csim/c/TypeClassification.py +14 -0
  16. csim-3.3.0/csim/c/utils.py +143 -0
  17. csim-3.3.0/csim/cpp_14/CPP14Lexer.tokens +264 -0
  18. csim-3.3.0/csim/cpp_14/CPP14Parser.tokens +264 -0
  19. csim-3.3.0/csim/java_20/Java20Lexer.tokens +242 -0
  20. csim-3.3.0/csim/java_20/Java20Parser.tokens +242 -0
  21. csim-3.3.0/csim/java_24/Java24Lexer.tokens +244 -0
  22. csim-3.3.0/csim/java_24/Java24Parser.tokens +244 -0
  23. csim-3.3.0/csim/kotlin/KotlinLexer.py +1643 -0
  24. csim-3.3.0/csim/kotlin/KotlinLexer.tokens +292 -0
  25. csim-3.3.0/csim/kotlin/KotlinParser.py +15470 -0
  26. csim-3.3.0/csim/kotlin/KotlinParser.tokens +292 -0
  27. csim-3.3.0/csim/kotlin/KotlinParserVisitor.py +768 -0
  28. csim-3.3.0/csim/kotlin/utils.py +187 -0
  29. {csim-3.2.0 → csim-3.3.0}/csim/language/parser.py +32 -0
  30. {csim-3.2.0 → csim-3.3.0}/csim/main.py +2 -2
  31. {csim-3.2.0 → csim-3.3.0}/csim/native/loader.py +75 -17
  32. csim-3.3.0/csim/native/src/c_bridge.cpp +95 -0
  33. csim-3.3.0/csim/native/src/kotlin_bridge.cpp +90 -0
  34. {csim-3.2.0 → csim-3.3.0}/csim/native/tree_builder.py +18 -8
  35. {csim-3.2.0 → csim-3.3.0}/csim/processing/tree_processing.py +6 -0
  36. csim-3.3.0/csim/python_3/Python3Lexer.tokens +185 -0
  37. csim-3.3.0/csim/python_3/Python3Parser.tokens +185 -0
  38. csim-3.3.0/csim/python_3/__init__.py +0 -0
  39. csim-3.3.0/csim/python_3_13/PythonLexer.tokens +187 -0
  40. csim-3.3.0/csim/python_3_13/PythonParser.tokens +187 -0
  41. csim-3.3.0/csim/python_3_13/__init__.py +0 -0
  42. {csim-3.2.0 → csim-3.3.0}/csim/utils.py +58 -0
  43. {csim-3.2.0 → csim-3.3.0/csim.egg-info}/PKG-INFO +46 -11
  44. {csim-3.2.0 → csim-3.3.0}/csim.egg-info/SOURCES.txt +45 -0
  45. csim-3.3.0/grammars/CLexer.g4 +752 -0
  46. csim-3.3.0/grammars/CLexerBase.cpp +157 -0
  47. csim-3.3.0/grammars/CLexerBase.h +64 -0
  48. csim-3.3.0/grammars/CParser.g4 +942 -0
  49. csim-3.3.0/grammars/CParserBase.cpp +570 -0
  50. csim-3.3.0/grammars/CParserBase.h +77 -0
  51. csim-3.3.0/grammars/KotlinLexer.g4 +517 -0
  52. csim-3.3.0/grammars/KotlinParser.g4 +840 -0
  53. csim-3.3.0/grammars/Symbol.h +76 -0
  54. csim-3.3.0/grammars/SymbolTable.cpp +209 -0
  55. csim-3.3.0/grammars/SymbolTable.h +38 -0
  56. csim-3.3.0/grammars/TypeClassification.h +15 -0
  57. csim-3.3.0/grammars/UnicodeClasses.g4 +1658 -0
  58. {csim-3.2.0 → csim-3.3.0}/scripts/build_native_parsers.sh +22 -2
  59. {csim-3.2.0 → csim-3.3.0}/setup.py +17 -4
  60. {csim-3.2.0 → csim-3.3.0}/test/test_native_parsers.py +120 -1
  61. {csim-3.2.0 → csim-3.3.0}/LICENSE +0 -0
  62. {csim-3.2.0 → csim-3.3.0}/csim/CodeSimilarity.py +0 -0
  63. {csim-3.2.0 → csim-3.3.0}/csim/DataStructures.py +0 -0
  64. {csim-3.2.0 → csim-3.3.0}/csim/__init__.py +0 -0
  65. {csim-3.2.0/csim/cpp_14 → csim-3.3.0/csim/c}/__init__.py +0 -0
  66. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/CPP14Lexer.py +0 -0
  67. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/CPP14Parser.py +0 -0
  68. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/CPP14ParserBase.py +0 -0
  69. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/CPP14ParserVisitor.py +0 -0
  70. {csim-3.2.0/csim/java_20 → csim-3.3.0/csim/cpp_14}/__init__.py +0 -0
  71. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/transformGrammar.py +0 -0
  72. {csim-3.2.0 → csim-3.3.0}/csim/cpp_14/utils.py +0 -0
  73. {csim-3.2.0 → csim-3.3.0}/csim/java_20/Java20Lexer.py +0 -0
  74. {csim-3.2.0 → csim-3.3.0}/csim/java_20/Java20Parser.py +0 -0
  75. {csim-3.2.0 → csim-3.3.0}/csim/java_20/Java20ParserVisitor.py +0 -0
  76. {csim-3.2.0/csim/java_24 → csim-3.3.0/csim/java_20}/__init__.py +0 -0
  77. {csim-3.2.0 → csim-3.3.0}/csim/java_20/utils.py +0 -0
  78. {csim-3.2.0 → csim-3.3.0}/csim/java_24/Java24Lexer.py +0 -0
  79. {csim-3.2.0 → csim-3.3.0}/csim/java_24/Java24LexerBase.py +0 -0
  80. {csim-3.2.0 → csim-3.3.0}/csim/java_24/Java24Parser.py +0 -0
  81. {csim-3.2.0 → csim-3.3.0}/csim/java_24/Java24ParserBase.py +0 -0
  82. {csim-3.2.0 → csim-3.3.0}/csim/java_24/Java24ParserVisitor.py +0 -0
  83. {csim-3.2.0/csim/language → csim-3.3.0/csim/java_24}/__init__.py +0 -0
  84. {csim-3.2.0 → csim-3.3.0}/csim/java_24/utils.py +0 -0
  85. {csim-3.2.0/csim/processing → csim-3.3.0/csim/kotlin}/__init__.py +0 -0
  86. {csim-3.2.0/csim/python_3 → csim-3.3.0/csim/language}/__init__.py +0 -0
  87. {csim-3.2.0 → csim-3.3.0}/csim/language/lexer.py +0 -0
  88. {csim-3.2.0 → csim-3.3.0}/csim/native/__init__.py +0 -0
  89. {csim-3.2.0 → csim-3.3.0}/csim/native/src/cpp_14_bridge.cpp +0 -0
  90. {csim-3.2.0 → csim-3.3.0}/csim/native/src/java_20_bridge.cpp +0 -0
  91. {csim-3.2.0 → csim-3.3.0}/csim/native/src/java_24_bridge.cpp +0 -0
  92. {csim-3.2.0 → csim-3.3.0}/csim/native/src/python_3_bridge.cpp +0 -0
  93. {csim-3.2.0/csim/python_3_13 → csim-3.3.0/csim/processing}/__init__.py +0 -0
  94. {csim-3.2.0 → csim-3.3.0}/csim/processing/distance_metrics.py +0 -0
  95. {csim-3.2.0 → csim-3.3.0}/csim/python_3/Python3Lexer.py +0 -0
  96. {csim-3.2.0 → csim-3.3.0}/csim/python_3/Python3LexerBase.py +0 -0
  97. {csim-3.2.0 → csim-3.3.0}/csim/python_3/Python3Parser.py +0 -0
  98. {csim-3.2.0 → csim-3.3.0}/csim/python_3/Python3ParserBase.py +0 -0
  99. {csim-3.2.0 → csim-3.3.0}/csim/python_3/Python3ParserVisitor.py +0 -0
  100. {csim-3.2.0 → csim-3.3.0}/csim/python_3/utils.py +0 -0
  101. {csim-3.2.0 → csim-3.3.0}/csim/python_3_13/PythonLexer.py +0 -0
  102. {csim-3.2.0 → csim-3.3.0}/csim/python_3_13/PythonLexerBase.py +0 -0
  103. {csim-3.2.0 → csim-3.3.0}/csim/python_3_13/PythonParser.py +0 -0
  104. {csim-3.2.0 → csim-3.3.0}/csim/python_3_13/PythonParserVisitor.py +0 -0
  105. {csim-3.2.0 → csim-3.3.0}/csim/python_3_13/utils.py +0 -0
  106. {csim-3.2.0 → csim-3.3.0}/csim.egg-info/dependency_links.txt +0 -0
  107. {csim-3.2.0 → csim-3.3.0}/csim.egg-info/entry_points.txt +0 -0
  108. {csim-3.2.0 → csim-3.3.0}/csim.egg-info/requires.txt +0 -0
  109. {csim-3.2.0 → csim-3.3.0}/csim.egg-info/top_level.txt +0 -0
  110. {csim-3.2.0 → csim-3.3.0}/grammars/CPP14Lexer.g4 +0 -0
  111. {csim-3.2.0 → csim-3.3.0}/grammars/CPP14Parser.g4 +0 -0
  112. {csim-3.2.0 → csim-3.3.0}/grammars/CPP14ParserBase.cpp +0 -0
  113. {csim-3.2.0 → csim-3.3.0}/grammars/CPP14ParserBase.h +0 -0
  114. {csim-3.2.0 → csim-3.3.0}/grammars/Java20Lexer.g4 +0 -0
  115. {csim-3.2.0 → csim-3.3.0}/grammars/Java20Parser.g4 +0 -0
  116. {csim-3.2.0 → csim-3.3.0}/grammars/Java24Lexer.g4 +0 -0
  117. {csim-3.2.0 → csim-3.3.0}/grammars/Java24Parser.g4 +0 -0
  118. {csim-3.2.0 → csim-3.3.0}/grammars/Java24ParserBase.cpp +0 -0
  119. {csim-3.2.0 → csim-3.3.0}/grammars/Java24ParserBase.h +0 -0
  120. {csim-3.2.0 → csim-3.3.0}/grammars/Python3Lexer.g4 +0 -0
  121. {csim-3.2.0 → csim-3.3.0}/grammars/Python3LexerBase.cpp +0 -0
  122. {csim-3.2.0 → csim-3.3.0}/grammars/Python3LexerBase.h +0 -0
  123. {csim-3.2.0 → csim-3.3.0}/grammars/Python3Parser.g4 +0 -0
  124. {csim-3.2.0 → csim-3.3.0}/grammars/Python3ParserBase.cpp +0 -0
  125. {csim-3.2.0 → csim-3.3.0}/grammars/Python3ParserBase.h +0 -0
  126. {csim-3.2.0 → csim-3.3.0}/grammars/PythonLexer.g4 +0 -0
  127. {csim-3.2.0 → csim-3.3.0}/grammars/PythonParser.g4 +0 -0
  128. {csim-3.2.0 → csim-3.3.0}/grammars/parser_gen_guide.md +0 -0
  129. {csim-3.2.0 → csim-3.3.0}/scripts/transform_grammar_for_cpp.py +0 -0
  130. {csim-3.2.0 → csim-3.3.0}/setup.cfg +0 -0
  131. {csim-3.2.0 → csim-3.3.0}/test/test_cli.py +0 -0
  132. {csim-3.2.0 → csim-3.3.0}/test/test_module.py +0 -0
@@ -7,6 +7,14 @@ include scripts/build_native_parsers.sh
7
7
  include scripts/transform_grammar_for_cpp.py
8
8
  include csim/native/src/*.cpp
9
9
 
10
+ # The C grammar's symbol-table implementation (typedef disambiguation) --
11
+ # doesn't match the *Base.cpp/*Base.h patterns above since it isn't a
12
+ # lexer/parser base class.
13
+ include grammars/SymbolTable.cpp
14
+ include grammars/SymbolTable.h
15
+ include grammars/Symbol.h
16
+ include grammars/TypeClassification.h
17
+
10
18
  include README.md
11
19
  include LICENSE
12
20
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csim
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: Code Similarity (csim) is a method designed to detect similarity between source codes
5
5
  Home-page: https://github.com/EdsonEddy/csim
6
6
  Author: Eddy Lecoña
@@ -52,7 +52,7 @@ Code Similarity (csim) provide a module designed to detect similarities between
52
52
  - **Parse Trees:** Represents the syntactic structure of source code, enabling detailed comparisons.
53
53
  - **Tree Edit Distance:** Measures the similarity between different code structures.
54
54
  - **Hash-Based Pruning:** Optimizes the comparison process by reducing tree size while preserving essential structure.
55
- - **Multi-Language Support:** Supports Python 3.13, Python 3 (universal grammar), Java 20, Java 24, and C++14 source code analysis.
55
+ - **Multi-Language Support:** Supports Python 3.13, Python 3 (universal grammar), Java 20, Java 24, C++14, Kotlin (experimental), and C (experimental) source code analysis.
56
56
 
57
57
  ## Technologies Used
58
58
 
@@ -98,7 +98,7 @@ pip install csim
98
98
 
99
99
  For detailed information about search strategies, see: [docs/STRATEGIES.md](docs/STRATEGIES.md)
100
100
 
101
- csim supports three main actions: **report** (for pairwise similarity analysis), **group** (for clustering similar files), and **tree**/**view** (for visualizing a file's normalized/pruned parse tree). The tool supports Python 3.13, Java 20, Java 24, and C++14 source code files.
101
+ csim supports three main actions: **report** (for pairwise similarity analysis), **group** (for clustering similar files), and **tree**/**view** (for visualizing a file's normalized/pruned parse tree). The tool supports Python 3.13, Python 3, Java 20, Java 24, C++14, Kotlin (experimental), and C (experimental) source code files.
102
102
 
103
103
  ### General Command Structure
104
104
  ```sh
@@ -121,7 +121,7 @@ file2.py is similar to file3.py with similarity index: 0.50
121
121
  ```
122
122
 
123
123
  **Options:**
124
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
124
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
125
125
  - `--talg, -ta`: Tree edit distance algorithm (default: `apted`). Options: `zss`, `apted`
126
126
 
127
127
  **Example with options:**
@@ -167,7 +167,7 @@ csim group --path /path/to/directory --threshold 0.8 --strategy exhaustive
167
167
 
168
168
  - `--threshold, -t`: Similarity threshold (0.0 to 1.0). **Required.**
169
169
  - `--strategy, -s`: Grouping strategy (default: `exhaustive`). Options: `exhaustive`
170
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
170
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
171
171
  - `--talg, -ta`: Tree edit distance algorithm (default: `apted`). Options: `zss`, `apted`
172
172
 
173
173
  **Complete example:**
@@ -204,7 +204,7 @@ Rule and token names are resolved for readability, `LOOP` marks nodes collapsed
204
204
 
205
205
  **Options:**
206
206
  - `--path, -p`: Path to a single source code file (**required**).
207
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
207
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
208
208
  - `--show-raw`: Also print the raw ANTLR parse tree before normalization/pruning, for side-by-side comparison.
209
209
 
210
210
  **Example with `--show-raw`:**
@@ -261,13 +261,48 @@ until this is resolved; `java_24` is available for parse-speed experimentation o
261
261
  csim report --path /path/to/cpp/files --lang cpp_14
262
262
  ```
263
263
 
264
+ **Kotlin (experimental):**
265
+ ```sh
266
+ csim report --path /path/to/kotlin/files --lang kotlin
267
+ ```
268
+
269
+ First-cut integration (grammars-v4/kotlin/kotlin) with a working native parser
270
+ (no C++ base class needed at all -- this grammar declares no `superClass`).
271
+ Unlike `java_24`/`python_3`, there is no real-world Kotlin corpus in this
272
+ project's benchmark set to tune or validate grouping precision against yet, so
273
+ the normalization rules (`csim/kotlin/utils.py`) follow the same *categories*
274
+ already validated for other languages (structural punctuation, identifier
275
+ text, import/package plumbing, body-wrapping content) but haven't been
276
+ corpus-measured for false-positive/false-negative rates. Treat `group`/`report`
277
+ results as a reasonable starting point, not a tuned config, until a real
278
+ corpus drives the next pass.
279
+
280
+ **C (experimental):**
281
+ ```sh
282
+ csim report --path /path/to/c/files --lang c
283
+ ```
284
+
285
+ First-cut integration (grammars-v4/c, ISO C23 + GNU/MSVC extensions), with a
286
+ working native parser backed by a real symbol-table implementation for
287
+ typedef disambiguation. Like Kotlin, there's no real-world C corpus in this
288
+ project's benchmark set to tune grouping precision against yet -- same
289
+ caveats apply, see `csim/c/utils.py`.
290
+
291
+ Runs with preprocessing disabled (`--nopp`) always: a real preprocessor can't
292
+ be assumed present in a production container, and judge submissions have no
293
+ consistent include paths anyway. `#include`/`#define`/etc. lines are
294
+ swallowed as hidden tokens rather than expanded, which means macro-dependent
295
+ code (token-pasting tricks, macros used for control flow) can fail to parse
296
+ or parse differently than a real compiler would see it -- real submissions
297
+ essentially never rely on that, but it's a known, real limitation.
298
+
264
299
  ### Native Parsers
265
300
 
266
- For `java_20`, `java_24`, `cpp_14`, and `python_3`, csim can use a compiled C++
267
- ANTLR parser instead of the pure-Python one, giving a large speedup with
268
- identical (or, for `java_24`, not-yet-identical -- see above) output.
269
- `python_3_13` always uses the pure-Python parser (no C++ target is available for
270
- that grammar).
301
+ For `java_20`, `java_24`, `cpp_14`, `python_3`, `kotlin`, and `c`, csim can
302
+ use a compiled C++ ANTLR parser instead of the pure-Python one, giving a
303
+ large speedup with identical (or, for `java_24`, not-yet-identical -- see
304
+ above) output. `python_3_13` always uses the pure-Python parser (no C++
305
+ target is available for that grammar).
271
306
 
272
307
  Check which backend is active for each language:
273
308
 
@@ -13,7 +13,7 @@ Code Similarity (csim) provide a module designed to detect similarities between
13
13
  - **Parse Trees:** Represents the syntactic structure of source code, enabling detailed comparisons.
14
14
  - **Tree Edit Distance:** Measures the similarity between different code structures.
15
15
  - **Hash-Based Pruning:** Optimizes the comparison process by reducing tree size while preserving essential structure.
16
- - **Multi-Language Support:** Supports Python 3.13, Python 3 (universal grammar), Java 20, Java 24, and C++14 source code analysis.
16
+ - **Multi-Language Support:** Supports Python 3.13, Python 3 (universal grammar), Java 20, Java 24, C++14, Kotlin (experimental), and C (experimental) source code analysis.
17
17
 
18
18
  ## Technologies Used
19
19
 
@@ -59,7 +59,7 @@ pip install csim
59
59
 
60
60
  For detailed information about search strategies, see: [docs/STRATEGIES.md](docs/STRATEGIES.md)
61
61
 
62
- csim supports three main actions: **report** (for pairwise similarity analysis), **group** (for clustering similar files), and **tree**/**view** (for visualizing a file's normalized/pruned parse tree). The tool supports Python 3.13, Java 20, Java 24, and C++14 source code files.
62
+ csim supports three main actions: **report** (for pairwise similarity analysis), **group** (for clustering similar files), and **tree**/**view** (for visualizing a file's normalized/pruned parse tree). The tool supports Python 3.13, Python 3, Java 20, Java 24, C++14, Kotlin (experimental), and C (experimental) source code files.
63
63
 
64
64
  ### General Command Structure
65
65
  ```sh
@@ -82,7 +82,7 @@ file2.py is similar to file3.py with similarity index: 0.50
82
82
  ```
83
83
 
84
84
  **Options:**
85
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
85
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
86
86
  - `--talg, -ta`: Tree edit distance algorithm (default: `apted`). Options: `zss`, `apted`
87
87
 
88
88
  **Example with options:**
@@ -128,7 +128,7 @@ csim group --path /path/to/directory --threshold 0.8 --strategy exhaustive
128
128
 
129
129
  - `--threshold, -t`: Similarity threshold (0.0 to 1.0). **Required.**
130
130
  - `--strategy, -s`: Grouping strategy (default: `exhaustive`). Options: `exhaustive`
131
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
131
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
132
132
  - `--talg, -ta`: Tree edit distance algorithm (default: `apted`). Options: `zss`, `apted`
133
133
 
134
134
  **Complete example:**
@@ -165,7 +165,7 @@ Rule and token names are resolved for readability, `LOOP` marks nodes collapsed
165
165
 
166
166
  **Options:**
167
167
  - `--path, -p`: Path to a single source code file (**required**).
168
- - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`
168
+ - `--lang, -l`: Programming language (default: `python_3_13`). Options: `python_3_13`, `python_3`, `java_20`, `java_24`, `cpp_14`, `kotlin`, `c`
169
169
  - `--show-raw`: Also print the raw ANTLR parse tree before normalization/pruning, for side-by-side comparison.
170
170
 
171
171
  **Example with `--show-raw`:**
@@ -222,13 +222,48 @@ until this is resolved; `java_24` is available for parse-speed experimentation o
222
222
  csim report --path /path/to/cpp/files --lang cpp_14
223
223
  ```
224
224
 
225
+ **Kotlin (experimental):**
226
+ ```sh
227
+ csim report --path /path/to/kotlin/files --lang kotlin
228
+ ```
229
+
230
+ First-cut integration (grammars-v4/kotlin/kotlin) with a working native parser
231
+ (no C++ base class needed at all -- this grammar declares no `superClass`).
232
+ Unlike `java_24`/`python_3`, there is no real-world Kotlin corpus in this
233
+ project's benchmark set to tune or validate grouping precision against yet, so
234
+ the normalization rules (`csim/kotlin/utils.py`) follow the same *categories*
235
+ already validated for other languages (structural punctuation, identifier
236
+ text, import/package plumbing, body-wrapping content) but haven't been
237
+ corpus-measured for false-positive/false-negative rates. Treat `group`/`report`
238
+ results as a reasonable starting point, not a tuned config, until a real
239
+ corpus drives the next pass.
240
+
241
+ **C (experimental):**
242
+ ```sh
243
+ csim report --path /path/to/c/files --lang c
244
+ ```
245
+
246
+ First-cut integration (grammars-v4/c, ISO C23 + GNU/MSVC extensions), with a
247
+ working native parser backed by a real symbol-table implementation for
248
+ typedef disambiguation. Like Kotlin, there's no real-world C corpus in this
249
+ project's benchmark set to tune grouping precision against yet -- same
250
+ caveats apply, see `csim/c/utils.py`.
251
+
252
+ Runs with preprocessing disabled (`--nopp`) always: a real preprocessor can't
253
+ be assumed present in a production container, and judge submissions have no
254
+ consistent include paths anyway. `#include`/`#define`/etc. lines are
255
+ swallowed as hidden tokens rather than expanded, which means macro-dependent
256
+ code (token-pasting tricks, macros used for control flow) can fail to parse
257
+ or parse differently than a real compiler would see it -- real submissions
258
+ essentially never rely on that, but it's a known, real limitation.
259
+
225
260
  ### Native Parsers
226
261
 
227
- For `java_20`, `java_24`, `cpp_14`, and `python_3`, csim can use a compiled C++
228
- ANTLR parser instead of the pure-Python one, giving a large speedup with
229
- identical (or, for `java_24`, not-yet-identical -- see above) output.
230
- `python_3_13` always uses the pure-Python parser (no C++ target is available for
231
- that grammar).
262
+ For `java_20`, `java_24`, `cpp_14`, `python_3`, `kotlin`, and `c`, csim can
263
+ use a compiled C++ ANTLR parser instead of the pure-Python one, giving a
264
+ large speedup with identical (or, for `java_24`, not-yet-identical -- see
265
+ above) output. `python_3_13` always uses the pure-Python parser (no C++
266
+ target is available for that grammar).
232
267
 
233
268
  Check which backend is active for each language:
234
269
 
@@ -3,6 +3,8 @@ from .java_20.Java20ParserVisitor import Java20ParserVisitor
3
3
  from .java_24.Java24ParserVisitor import Java24ParserVisitor
4
4
  from .cpp_14.CPP14ParserVisitor import CPP14ParserVisitor
5
5
  from .python_3.Python3ParserVisitor import Python3ParserVisitor
6
+ from .kotlin.KotlinParserVisitor import KotlinParserVisitor
7
+ from .c.CParserVisitor import CParserVisitor
6
8
  from antlr4 import TerminalNode
7
9
  from .java_20.utils import (
8
10
  COLLAPSED_RULE_INDICES as JAVA_20_COLLAPSED_RULES,
@@ -36,6 +38,12 @@ from .cpp_14.utils import (
36
38
  ASIGN_OP_NORMALIZED as CPP_14_ASSIGN_OP_NORMALIZED,
37
39
  RULE_ASSIGNMENT as CPP_14_RULE_ASSIGNMENT,
38
40
  )
41
+ from .kotlin.utils import (
42
+ COLLAPSED_RULE_INDICES as KOTLIN_COLLAPSED_RULES,
43
+ )
44
+ from .c.utils import (
45
+ COLLAPSED_RULE_INDICES as C_COLLAPSED_RULES,
46
+ )
39
47
 
40
48
 
41
49
  class Python_3_13_ParserVisitorExtended(PythonParserVisitor):
@@ -182,6 +190,43 @@ class CPP14ParserVisitorExtended(CPP14ParserVisitor):
182
190
  return self.visitChildren(node)
183
191
 
184
192
 
193
+ class KotlinParserVisitorExtended(KotlinParserVisitor):
194
+ def visit(self, tree):
195
+ """Override visit to exclude certain rules from being processed.
196
+ This helps in reducing noise in the parse tree by skipping over
197
+ less relevant constructs.
198
+
199
+ No visitAssignment-style override here: Kotlin's grammar has no
200
+ ANTLR labeled alternatives at all (unlike java_24/python_3), so
201
+ there's no relabel_node() hook needed either -- see
202
+ csim/kotlin/utils.py's module docstring.
203
+ """
204
+ if (
205
+ not isinstance(tree, TerminalNode)
206
+ and tree.getRuleIndex() in KOTLIN_COLLAPSED_RULES
207
+ ):
208
+ return {"label": tree.getRuleIndex(), "children": []}
209
+ return tree.accept(self)
210
+
211
+
212
+ class CParserVisitorExtended(CParserVisitor):
213
+ def visit(self, tree):
214
+ """Override visit to exclude certain rules from being processed.
215
+ This helps in reducing noise in the parse tree by skipping over
216
+ less relevant constructs.
217
+
218
+ No visitAssignment-style override here: no relabel_node() hook is
219
+ needed either -- see csim/c/utils.py's module docstring (this
220
+ grammar has no ANTLR labeled alternatives at all).
221
+ """
222
+ if (
223
+ not isinstance(tree, TerminalNode)
224
+ and tree.getRuleIndex() in C_COLLAPSED_RULES
225
+ ):
226
+ return {"label": tree.getRuleIndex(), "children": []}
227
+ return tree.accept(self)
228
+
229
+
185
230
  class Python3ParserVisitorExtended(Python3ParserVisitor):
186
231
  def visit(self, tree):
187
232
  """Override visit to exclude certain rules from being processed.