File tree Expand file tree Collapse file tree 3 files changed +26
-5
lines changed
src/code-quality/tokenizer Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -2,20 +2,23 @@ import { CodeTokens } from './CodeTokens';
2
2
import { PythonIdentifiers } from './identifiers/PythonIdentifiers' ;
3
3
import { CommonLangIdentifiers } from './identifiers/CommonLangIdentifiers' ;
4
4
import { GolangIdentifiers } from './identifiers/GolangIdentifiers' ;
5
+ import { CppIdentifiers } from './identifiers/CppIdentifiers' ;
5
6
6
7
export class CodeTokenizer {
7
8
private pyIdentifiers = new PythonIdentifiers ( ) ;
8
9
9
10
private golangIdentifiers = new GolangIdentifiers ( ) ;
10
11
12
+ private cppIdentifiers = new CppIdentifiers ( ) ;
13
+
11
14
public tokenize ( code : string , language : string ) : CodeTokens [ ] {
12
15
switch ( language ) {
13
16
case 'python' :
14
17
return this . tokenizeCode ( code , this . pyIdentifiers ) ;
15
18
case 'go' :
16
19
return this . tokenizeCode ( code , this . golangIdentifiers ) ;
17
20
case 'cpp' :
18
- return [ ] ;
21
+ return this . tokenizeCode ( code , this . cppIdentifiers ) ;
19
22
default :
20
23
return [ ] ;
21
24
}
@@ -32,10 +35,7 @@ export class CodeTokenizer {
32
35
const trimmedLine = line . trim ( ) ;
33
36
34
37
if ( trimmedLine !== '' && trimmedLine !== '}' )
35
- if (
36
- trimmedLine . startsWith ( languageIdentifier . functionIdentifier ( ) ) &&
37
- trimmedLine . endsWith ( languageIdentifier . endLoopAndCondIdentifier ( ) )
38
- ) {
38
+ if ( languageIdentifier . isFunction ( trimmedLine ) ) {
39
39
// Function detection
40
40
tokenizedCode . push ( CodeTokens . FUNC ) ;
41
41
const numberOfParams =
Original file line number Diff line number Diff line change @@ -30,4 +30,11 @@ export class CommonLangIdentifiers {
30
30
endLoopAndCondIdentifier ( ) : string {
31
31
return '{' ;
32
32
}
33
+
34
+ isFunction ( line : string ) : boolean {
35
+ return (
36
+ line . startsWith ( this . functionIdentifier ( ) ) &&
37
+ line . endsWith ( this . endLoopAndCondIdentifier ( ) )
38
+ ) ;
39
+ }
33
40
}
Original file line number Diff line number Diff line change
1
+ import { CommonLangIdentifiers } from './CommonLangIdentifiers' ;
2
+
3
+ export class CppIdentifiers extends CommonLangIdentifiers {
4
+ isFunction ( line : string ) : boolean {
5
+ return (
6
+ ( line . startsWith ( 'void' ) ||
7
+ line . startsWith ( 'char' ) ||
8
+ line . startsWith ( 'int' ) ||
9
+ line . startsWith ( 'float' ) ||
10
+ line . startsWith ( 'double' ) ) &&
11
+ line . endsWith ( '{' )
12
+ ) ;
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments