Blame SOURCES/augeas-1.1.0-shellvars-case-semicolons.patch

c537d4
From 0cce971fabef13af3a9592ef93a505378f73338a Mon Sep 17 00:00:00 2001
c537d4
From: Dominic Cleal <dcleal@redhat.com>
c537d4
Date: Wed, 29 Jan 2014 22:57:02 +0000
c537d4
Subject: [PATCH 5/5] Shellvars: handle case statements with same-line ;;
c537d4
 tokens
c537d4
c537d4
Fixes RHBZ#1033799
c537d4
c537d4
(cherry picked from commit a1b9831d14f22f81cf7dc840160c08cc14234ee9)
c537d4
c537d4
Conflicts:
c537d4
	NEWS
c537d4
	lenses/shellvars.aug
c537d4
---
c537d4
 lenses/shellvars.aug            | 65 +++++++++++++++++++++++++----------------
c537d4
 lenses/sysconfig.aug            |  6 ++--
c537d4
 lenses/tests/test_shellvars.aug | 11 +++++++
c537d4
 3 files changed, 54 insertions(+), 28 deletions(-)
c537d4
c537d4
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
c537d4
index 4111ee6..eff933a 100644
c537d4
--- a/lenses/shellvars.aug
c537d4
+++ b/lenses/shellvars.aug
c537d4
@@ -59,40 +59,37 @@ module Shellvars =
c537d4
             | bquot | dbquot | dollar_assign | empty_array)
c537d4
 
c537d4
   let export = [ key "export" . Util.del_ws_spc ]
c537d4
-  let kv = [ Util.indent . export? . key key_re
c537d4
-           . eq . (simple_value | array) . comment_or_eol ]
c537d4
+  let kv = Util.indent . export? . key key_re
c537d4
+           . eq . (simple_value | array)
c537d4
 
c537d4
   let var_action (name:string) =
c537d4
-    Util.indent . del name name . Util.del_ws_spc .
c537d4
-      [ label ("@" . name) . counter "var_action"
c537d4
-        . Build.opt_list [ seq "var_action" . store (key_re | matching_re) ] Util.del_ws_spc
c537d4
-        . comment_or_eol ]
c537d4
+    Util.indent . del name name . Util.del_ws_spc
c537d4
+    . label ("@" . name) . counter "var_action"
c537d4
+    . Build.opt_list [ seq "var_action" . store (key_re | matching_re) ] Util.del_ws_spc
c537d4
 
c537d4
   let unset = var_action "unset"
c537d4
   let bare_export = var_action "export"
c537d4
 
c537d4
   let source =
c537d4
-    [ Util.indent
c537d4
-      . del /\.|source/ "." . label ".source"
c537d4
-      . Util.del_ws_spc . store /[^;=# \t\n]+/ . comment_or_eol ]
c537d4
+    Util.indent
c537d4
+    . del /\.|source/ "." . label ".source"
c537d4
+    . Util.del_ws_spc . store /[^;=# \t\n]+/
c537d4
 
c537d4
   let shell_builtin_cmds = "ulimit" | "shift" | "exit"
c537d4
 
c537d4
   let builtin =
c537d4
-    [ Util.indent . label "@builtin"
c537d4
-      . store shell_builtin_cmds
c537d4
-      . (Util.del_ws_spc
c537d4
-      . [ label "args" . sto_to_semicol ])?
c537d4
-      . comment_or_eol ]
c537d4
+    Util.indent . label "@builtin"
c537d4
+    . store shell_builtin_cmds
c537d4
+    . (Util.del_ws_spc
c537d4
+    . [ label "args" . sto_to_semicol ])?
c537d4
 
c537d4
   let keyword (kw:string) = Util.indent . Util.del_str kw
c537d4
   let keyword_label (kw:string) (lbl:string) = keyword kw . label lbl
c537d4
 
c537d4
   let return =
c537d4
-    [ Util.indent . label "@return"
c537d4
-      . Util.del_str "return"
c537d4
-      . ( Util.del_ws_spc . store Rx.integer )?
c537d4
-      . comment_or_eol ]
c537d4
+    Util.indent . label "@return"
c537d4
+    . Util.del_str "return"
c537d4
+    . ( Util.del_ws_spc . store Rx.integer )?
c537d4
 
c537d4
 
c537d4
 (************************************************************************
c537d4
@@ -128,11 +125,11 @@ module Shellvars =
c537d4
   let loop_select (entry:lens) =
c537d4
     generic_cond "select" "@select" "do" entry+ "done"
c537d4
 
c537d4
-  let case (entry:lens) =
c537d4
+  let case (entry:lens) (entry_noeol:lens) =
c537d4
     let case_entry = [ label "@case_entry"
c537d4
                        . Util.indent . store /[^ \t\n\)]+/
c537d4
                        . Util.del_str ")" . eol
c537d4
-                       . entry*
c537d4
+                       . ( entry+ | entry_noeol )?
c537d4
                        . Util.indent . Util.del_str ";;" . eol ] in
c537d4
       [ keyword_label "case" "@case" . Sep.space
c537d4
         . store (char+ | ("\"" . char+ . "\""))
c537d4
@@ -149,20 +146,38 @@ module Shellvars =
c537d4
       . entry+
c537d4
       . Util.indent . Util.del_str "}" . eol ]
c537d4
 
c537d4
+  let entry_eol =
c537d4
+    let entry_eol_item (item:lens) =
c537d4
+      [ item . comment_or_eol ] in
c537d4
+      entry_eol_item source
c537d4
+        | entry_eol_item kv
c537d4
+        | entry_eol_item unset
c537d4
+        | entry_eol_item bare_export
c537d4
+        | entry_eol_item builtin
c537d4
+        | entry_eol_item return
c537d4
+
c537d4
+  let entry_noeol =
c537d4
+    let entry_item (item:lens) = [ item ] in
c537d4
+      entry_item source
c537d4
+        | entry_item kv
c537d4
+        | entry_item unset
c537d4
+        | entry_item bare_export
c537d4
+        | entry_item builtin
c537d4
+        | entry_item return
c537d4
+
c537d4
   let rec rec_entry =
c537d4
-    let entry = comment | source | kv
c537d4
-              | unset | bare_export | builtin | return | rec_entry in
c537d4
+    let entry = comment | entry_eol | rec_entry in
c537d4
         cond_if entry
c537d4
       | loop_for entry
c537d4
       | loop_select entry
c537d4
       | loop_while entry
c537d4
       | loop_until entry
c537d4
-      | case entry
c537d4
+      | case entry entry_noeol
c537d4
       | function entry
c537d4
 
c537d4
-  let lns_norec = empty* . (comment | source | kv | unset | bare_export | builtin | return) *
c537d4
+  let lns_norec = empty* . (comment | entry_eol) *
c537d4
 
c537d4
-  let lns = empty* . (comment | source | kv | unset | bare_export | builtin | return | rec_entry) *
c537d4
+  let lns = empty* . (comment | entry_eol | rec_entry) *
c537d4
 
c537d4
   let sc_incl (n:string) = (incl ("/etc/sysconfig/" . n))
c537d4
   let sc_excl (n:string) = (excl ("/etc/sysconfig/" . n))
c537d4
diff --git a/lenses/sysconfig.aug b/lenses/sysconfig.aug
c537d4
index ee83af1..8c505b3 100644
c537d4
--- a/lenses/sysconfig.aug
c537d4
+++ b/lenses/sysconfig.aug
c537d4
@@ -55,10 +55,10 @@ module Sysconfig =
c537d4
 
c537d4
   let var_action = Shellvars.var_action
c537d4
 
c537d4
-  let unset = var_action "unset"
c537d4
-  let bare_export = var_action "export"
c537d4
+  let unset = [ var_action "unset" . comment_or_eol ]
c537d4
+  let bare_export = [ var_action "export" . comment_or_eol ]
c537d4
 
c537d4
-  let source = Shellvars.source
c537d4
+  let source = [ Shellvars.source . comment_or_eol ]
c537d4
 
c537d4
   let lns = empty* . (comment | source | assign | unset | bare_export)*
c537d4
 
c537d4
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
c537d4
index 79a5a4e..18fd361 100644
c537d4
--- a/lenses/tests/test_shellvars.aug
c537d4
+++ b/lenses/tests/test_shellvars.aug
c537d4
@@ -446,6 +446,17 @@ esac\n" =
c537d4
       { "1" = "TestVar1" }
c537d4
       { "2" = "TestVar2" } }
c537d4
 
c537d4
+  (* Support ;; on same line as a case statement entry, RHBZ#1033799 *)
c537d4
+  test lns get "case $ARG in
c537d4
+        0) TestVar=\"test0\" ;;
c537d4
+        1) TestVar=\"test1\" ;;
c537d4
+esac\n" =
c537d4
+    { "@case" = "$ARG"
c537d4
+      { "@case_entry" = "0"
c537d4
+        { "TestVar" = "\"test0\"" } }
c537d4
+      { "@case_entry" = "1"
c537d4
+        { "TestVar" = "\"test1\"" } } }
c537d4
+
c537d4
 (* Local Variables: *)
c537d4
 (* mode: caml       *)
c537d4
 (* End:             *)
c537d4
-- 
c537d4
1.8.5.3
c537d4