-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_lexer.py
More file actions
25 lines (18 loc) · 672 Bytes
/
get_lexer.py
File metadata and controls
25 lines (18 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
# this will read the file extension and return the correct lexer
def get_lexer_for_file(file_path):
_, ext = os.path.splitext(file_path)
if ext == ".rb":
from lexers.ruby.rubylexer import RubyLexer
return RubyLexer
elif ext == ".py":
from lexers.python.pythonlexer import PythonLexer
return PythonLexer
elif ext == ".js":
from lexers.javascript.javascriptlexer import JavaScriptLexer
return JavaScriptLexer
elif ext == ".go":
from lexers.golang.golexer import GoLexer
return GoLexer
else:
raise ValueError(f"Unsupported file extension: {ext}")