mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-12 22:42:23 +00:00
python: expose language_by_filename()
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
parent
ee7a0f1139
commit
cff9c07009
@ -26,15 +26,29 @@ def language_by_extension(filename: str) -> str:
|
||||
return lang
|
||||
|
||||
|
||||
def language_by_filename(filename: str) -> str:
|
||||
fName = py_str_to_go(filename)
|
||||
guess = lib.GetLanguageByFilename(fName)
|
||||
lang = go_str_to_py(guess.r0)
|
||||
return lang
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
|
||||
def main():
|
||||
files = ["Parse.hs", "some.cpp", "and.go", "type.h"]
|
||||
files = ["Parse.hs", "some.cpp", "and.go", "type.h", ".bashrc"]
|
||||
|
||||
print("strategy: extension")
|
||||
for filename in files:
|
||||
lang = language_by_extension(filename)
|
||||
print("file: {:10s} language: '{}'".format(filename, lang))
|
||||
|
||||
print("\nstrategy: filename")
|
||||
for filename in files:
|
||||
lang = language_by_filename(filename)
|
||||
print("file: {:10s} language: '{}'".format(filename, lang))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -15,6 +15,14 @@ struct GetLanguageByExtension_return {
|
||||
};
|
||||
|
||||
extern struct GetLanguageByExtension_return GetLanguageByExtension(GoString p0);
|
||||
|
||||
/* Return type for GetLanguageByFilename */
|
||||
struct GetLanguageByFilename_return {
|
||||
GoString r0; /* language */
|
||||
GoUint8 r1; /* safe */
|
||||
};
|
||||
|
||||
extern struct GetLanguageByFilename_return GetLanguageByFilename(GoString p0);
|
||||
""")
|
||||
|
||||
# set_source() gives the name of the python extension module to
|
||||
|
Loading…
Reference in New Issue
Block a user