https://github.com/ruricolist/cl-shlex
Simple lexical analyzer for shell-like syntaxes
https://github.com/ruricolist/cl-shlex
Last synced: 2 months ago
JSON representation
Simple lexical analyzer for shell-like syntaxes
- Host: GitHub
- URL: https://github.com/ruricolist/cl-shlex
- Owner: ruricolist
- License: mit
- Created: 2019-07-25T01:23:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-01T22:06:27.000Z (about 5 years ago)
- Last Synced: 2024-05-19T05:36:40.101Z (almost 2 years ago)
- Language: Common Lisp
- Homepage:
- Size: 18.6 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-cl - cl-shlex - simple lexical analyzer for shell-like syntaxes. [MIT][200]. (Online editors ## / Third-party APIs)
README
A lexer for syntaxes that use shell-like rules for quoting and commenting. It is a port of the `shlex` module from Python’s standard library.
The point of entry is `split`:
(shlex:split "a 'b c' \"d e\" \"f ' g\"")
=> '("a" "b c" "d e" "f ' g")
For a parse that is closer to a shell, you can pass the `:punctuation-chars` keyword:
;; Not what you want.
(shlex:split "a && b; c && d || e; f >'abc'; (def \"ghi\")")
=> '("a" "&&" "b;" "c" "&&" "d" "||" "e;" "f" ">abc;" "(def" "ghi)")
(shlex:split "a && b; c && d || e; f >'abc'; (def \"ghi\")" :punctuation-chars t)
=> ("a" "&&" "b" ";" "c" "&&" "d" "||" "e" ";" "f" ">" "abc" ";" "(" "def" "ghi" ")")
If you would rather iterate over each token in turn, you can use `shlex:map-tokens` or `shlex:do-tokens` instead.
;; Print each token in STRING.
(shlex:map-tokens #'print string :punctuation-chars t)
;; Do the same thing with a macro.
(shlex:do-tokens (token (string :punctuation-chars t))
(print token))