From 906d8b89a99de2c7b27cb1a8db8af118e39f8e19 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Mon, 13 Jul 2015 14:43:09 +0300 Subject: [PATCH 11/19] Shellvars: pattern nodes in case entries Breaking change: case entry values are now in a @pattern subnode. --- lenses/shellvars.aug | 10 +++++---- lenses/tests/test_shellvars.aug | 48 +++++++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug index f681fcd..ed9cc9c 100644 --- a/lenses/shellvars.aug +++ b/lenses/shellvars.aug @@ -34,12 +34,12 @@ module Shellvars = let xchgs = Build.xchgs let semicol = del /;?/ "" - let char = /[^`;()'"\n\\# \t]#*|\\\\(.|\n)/ + let char = /[^`;()'"|\n\\# \t]#*|\\\\(.|\n)/ let dquot = let char = /[^"\\]|\\\\./ | Rx.cl in "\"" . char* . "\"" (* " Emacs, relax *) let squot = /'[^']*'/ - let bquot = /`[^`\n]*`/ + let bquot = /`[^`\n]+`/ (* dbquot don't take spaces or semi-colons *) let dbquot = /``[^` \t\n;]+``/ let dollar_assign = /\$\([^\(\)#\n]*\)/ @@ -148,8 +148,10 @@ module Shellvars = generic_cond "select" "@select" "do" entry+ "done" let case (entry:lens) (entry_noeol:lens) = - let case_entry = [ label "@case_entry" - . Util.indent . sto_to_semicol + let pattern = [ label "@pattern" . sto_to_semicol . Sep.opt_space ] + in let case_entry = [ label "@case_entry" + . Util.indent . pattern + . (Util.del_str "|" . Sep.opt_space . pattern)* . Util.del_str ")" . eol . entry* . entry_noeol? . Util.indent . Util.del_str ";;" . eol ] in diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug index 26aec25..d07918d 100644 --- a/lenses/tests/test_shellvars.aug +++ b/lenses/tests/test_shellvars.aug @@ -261,11 +261,14 @@ done\n" = ;; esac\n" = { "@case" = "$f" - { "@case_entry" = "/tmp/file1" + { "@case_entry" + { "@pattern" = "/tmp/file1" } { ".source" = "/tmp/file1" } } - { "@case_entry" = "/tmp/file2" + { "@case_entry" + { "@pattern" = "/tmp/file2" } { ".source" = "/tmp/file2" } } - { "@case_entry" = "*" + { "@case_entry" + { "@pattern" = "*" } { "@unset" { "1" = "f" } } } } @@ -308,7 +311,8 @@ esac\n" = esac\n" = { "@case" = "$f" - { "@case_entry" = "a" + { "@case_entry" + { "@pattern" = "a" } { "B" = "C" } } } @@ -325,9 +329,11 @@ esac\n" = ;; esac\n" = { "@case" = "$f" - { "@case_entry" = "a" + { "@case_entry" + { "@pattern" = "a" } { "B" = "C" } } - { "@case_entry" = "b" + { "@case_entry" + { "@pattern" = "b" } { "A" = "D" } } } @@ -348,11 +354,13 @@ unset f esac\n" = { "@case" = "${INTERFACE}" { "#comment" = "comment before" } - { "@case_entry" = "eth0" + { "@case_entry" + { "@pattern" = "eth0" } { "#comment" = "comment in" } { "OPTIONS" = "()" } } { "#comment" = "comment before 2" } - { "@case_entry" = "*" + { "@case_entry" + { "@pattern" = "*" } { "#comment" = "comment in 2" } { "@unset" { "1" = "f" } } } @@ -364,7 +372,7 @@ esac\n" = ;; esac\n" = { "@case" = "$a" - { "@case_entry" = "*" } } + { "@case_entry" { "@pattern" = "*" } } } (* case variables can be surrounded by double quotes *) test Shellvars.lns get "case \"${options}\" in @@ -373,7 +381,8 @@ esac\n" = ;; esac\n" = { "@case" = "\"${options}\"" - { "@case_entry" = "*debug*" + { "@case_entry" + { "@pattern" = "*debug*" } { "@builtin" = "shift" } } } (* Double quoted values can have newlines *) @@ -473,9 +482,11 @@ test2\"\n" = 1) TestVar=\"test1\" ;; esac\n" = { "@case" = "$ARG" - { "@case_entry" = "0" + { "@case_entry" + { "@pattern" = "0" } { "TestVar" = "\"test0\"" } } - { "@case_entry" = "1" + { "@case_entry" + { "@pattern" = "1" } { "TestVar" = "\"test1\"" } } } (* case: support ;; on the same line with multiple commands *) @@ -486,11 +497,13 @@ esac\n" = Bar=3; Baz=4;; esac\n" = { "@case" = "$ARG" - { "@case_entry" = "0" + { "@case_entry" + { "@pattern" = "0" } { "Foo" = "0" } { "Bar" = "1" } } - { "@case_entry" = "1" + { "@case_entry" + { "@pattern" = "1" } { "Foo" = "2" } { "Bar" = "3" } { "Baz" = "4" } @@ -572,10 +585,13 @@ fi\n" = ;; esac\n" = { "@case" = "$ARG" - { "@case_entry" = "\"foo bar\"" + { "@case_entry" + { "@pattern" = "\"foo bar\"" } { "Foo" = "0" } } - { "@case_entry" = "baz | quux" + { "@case_entry" + { "@pattern" = "baz" } + { "@pattern" = "quux" } { "Foo" = "1" } } } -- 2.5.0