factor/basis/io/launcher/unix/parser/parser.factor

18 lines
588 B
Factor
Raw Normal View History

2008-03-03 17:45:18 -05:00
! Copyright (C) 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
2009-04-18 22:53:22 -04:00
USING: peg peg.ebnf arrays sequences strings kernel ;
IN: io.launcher.unix.parser
2008-03-03 17:45:18 -05:00
! Our command line parser. Supported syntax:
! foo bar baz -- simple tokens
! foo\ bar -- escaping the space
! "foo bar" -- quotation
2009-04-18 22:53:22 -04:00
EBNF: tokenize-command
space = " "
escaped-char = "\" .:ch => [[ ch ]]
quoted = '"' (escaped-char | [^"])*:a '"' => [[ a ]]
unquoted = (escaped-char | [^ "])+
argument = (quoted | unquoted) => [[ >string ]]
command = space* (argument:a space* => [[ a ]])+:c !(.) => [[ c ]]
;EBNF