commit 68b888a356e54feb23b333703f067d3479fd66a0 Author: ge Date: Fri Jul 11 19:18:01 2025 +0300 init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..01072ca --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.v] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9a98968 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +* text=auto eol=lf +*.bat eol=crlf + +*.v linguist-language=V +*.vv linguist-language=V +*.vsh linguist-language=V +v.mod linguist-language=V +.vdocignore linguist-language=ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88c0fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Binaries for programs and plugins +main +code +*.exe +*.exe~ +*.so +*.dylib +*.dll + +# Ignore binary output folders +bin/ + +# Ignore common editor/system specific metadata +.DS_Store +.idea/ +.vscode/ +*.iml + +# ENV +.env + +# vweb and database +*.db +*.js diff --git a/shell.v b/shell.v new file mode 100644 index 0000000..cbbac70 --- /dev/null +++ b/shell.v @@ -0,0 +1,46 @@ +module shell + +import strings.textscanner + +const safe_chars = '%+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz' + +// quote returns a shell-escaped version of string `s`. +pub fn quote(s string) string { + if s == '' { + return "''" + } + if s.is_pure_ascii() && s.contains_only(safe_chars) { + return s + } + return "'" + s.replace("'", '\'"\'"\'') + "'" +} + +// join joins `s` array members into a shell-escaped string. +pub fn join(s []string) string { + mut quoted_args := []string{} + for arg in s { + quoted_args << quote(arg) + } + return quoted_args.join(' ') +} + +// // join_all joins their arguments into a shell-escaped string. +// pub fn join_all(s ...string) string { +// return join(s) +// } + +// split splits the string `s` into array using shell-like syntax. +pub fn split(s string) []string { + return []string{} +} + +pub struct Lexer { +pub: + posix_mode bool = true + comment_chars string = '#' +pub mut: + tokens []string +} + +pub fn (mut x Lexer) process(s string) { +} diff --git a/shell_test.v b/shell_test.v new file mode 100644 index 0000000..feeecf7 --- /dev/null +++ b/shell_test.v @@ -0,0 +1,9 @@ +import shell + +fn test_quote() { + assert shell.quote("janna d'arc") == '\'janna d\'"\'"\'arc\'' +} + +fn test_join() { + assert shell.join(['sh', '-c', 'hostname -f']) == "sh -c 'hostname -f'" +} diff --git a/v.mod b/v.mod new file mode 100644 index 0000000..eb6fc2e --- /dev/null +++ b/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'shell' + description: 'Shell lexer' + version: '0.0.0' + license: 'MIT' + dependencies: [] +}