* [PATCH] support for "elif" in grub script
@ 2010-03-16 12:45 Deepak Vankadaru
2010-03-26 14:13 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 2+ messages in thread
From: Deepak Vankadaru @ 2010-03-16 12:45 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1.1: Type: text/plain, Size: 349 bytes --]
Hi
This is my patch submission after a while. I have submitted fixes for
grub_printf in the past, which is still pending on merge conflicts.
Attached patch contains changes on top of "for-loops" branch to support
"elif" construct in grub script. Please review and let me know if anything
else needs to be done to get this comitted.
Thanks
Deepak
[-- Attachment #1.2: Type: text/html, Size: 404 bytes --]
[-- Attachment #2: elif.diff --]
[-- Type: application/octet-stream, Size: 3484 bytes --]
=== modified file 'conf/tests.rmk'
--- conf/tests.rmk 2010-01-23 05:33:41 +0000
+++ conf/tests.rmk 2010-03-16 11:56:53 +0000
@@ -53,6 +53,9 @@
check_SCRIPTS += grub_script_for1
grub_script_for1_SOURCES = tests/grub_script_for1.in
+check_SCRIPTS += grub_script_if
+grub_script_if_SOURCES = tests/grub_script_if.in
+
# List of tests to execute on "make check"
# SCRIPTED_TESTS = example_scripted_test
# SCRIPTED_TESTS += example_grub_script_test
@@ -63,6 +66,7 @@
SCRIPTED_TESTS += grub_script_echo_keywords
SCRIPTED_TESTS += grub_script_vars1
SCRIPTED_TESTS += grub_script_for1
+SCRIPTED_TESTS += grub_script_if
# dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
=== modified file 'script/parser.y'
--- script/parser.y 2010-01-23 05:33:41 +0000
+++ script/parser.y 2010-03-16 12:16:55 +0000
@@ -76,7 +76,7 @@
%token <arg> GRUB_PARSER_TOKEN_WORD "word"
%type <arglist> word argument arguments0 arguments1
-%type <cmd> script_init script grubcmd ifcmd forcmd command
+%type <cmd> script_init script grubcmd ifclause ifcmd forcmd command
%type <cmd> commands1 menuentry statement
%pure-parser
@@ -226,18 +226,28 @@
}
;
-if: "if" { grub_script_lexer_ref (state->lexerstate); }
+ifcmd: "if"
+ {
+ grub_script_lexer_ref (state->lexerstate);
+ }
+ ifclause "fi"
+ {
+ $$ = $3;
+ grub_script_lexer_deref (state->lexerstate);
+ }
;
-ifcmd: if commands1 delimiters1 "then" commands1 delimiters1 "fi"
- {
- $$ = grub_script_create_cmdif (state, $2, $5, 0);
- grub_script_lexer_deref (state->lexerstate);
- }
- | if commands1 delimiters1 "then" commands1 delimiters1 "else" commands1 delimiters1 "fi"
- {
- $$ = grub_script_create_cmdif (state, $2, $5, $8);
- grub_script_lexer_deref (state->lexerstate);
- }
+ifclause: commands1 delimiters1 "then" commands1 delimiters1
+ {
+ $$ = grub_script_create_cmdif (state, $1, $4, 0);
+ }
+ | commands1 delimiters1 "then" commands1 delimiters1 "else" commands1 delimiters1
+ {
+ $$ = grub_script_create_cmdif (state, $1, $4, $7);
+ }
+ | commands1 delimiters1 "then" commands1 delimiters1 "elif" ifclause
+ {
+ $$ = grub_script_create_cmdif (state, $1, $4, $7);
+ }
;
forcmd: "for" "name"
=== added file 'tests/grub_script_if.in'
--- tests/grub_script_if.in 1970-01-01 00:00:00 +0000
+++ tests/grub_script_if.in 2010-03-16 12:17:49 +0000
@@ -0,0 +1,31 @@
+#! @builddir@/grub-shell-tester
+
+#basic if, execute
+if true; then echo yes; fi
+
+#basic if, no execution
+if false; then echo no; fi
+
+#if else, execute if path
+if true; then echo yes; else echo no; fi
+
+#if else, execute else path
+if false; then echo no; else echo yes; fi
+
+#if elif, execute elif
+if false; then echo no; elif true; then echo yes; fi
+
+#if elif else, execute else
+if false; then echo no; elif false; then echo no; else echo yes; fi
+
+#if elif(1) elif(2), execute elif(2)
+if false; then echo no; elif false; then echo no; elif true; then echo yes; fi
+
+#if elif(1) elif(2) else, execute else
+if false; then echo no; elif false; then echo no; elif false; then echo no; else echo yes; fi
+
+#if {if elif else}, execute elif
+if true; then if false; then echo no; elif true; then echo yes; else echo no; fi; fi
+
+#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi"
+if true; then if false; then echo no; elif true; then echo yes; fi; else echo no; fi
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] support for "elif" in grub script
2010-03-16 12:45 [PATCH] support for "elif" in grub script Deepak Vankadaru
@ 2010-03-26 14:13 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 0 replies; 2+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-03-26 14:13 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 988 bytes --]
Deepak Vankadaru wrote:
> Hi
>
> This is my patch submission after a while. I have submitted fixes for
> grub_printf in the past, which is still pending on merge conflicts.
>
grub_printf enhancements were considered unnecessary. grub_printf is
size-constrained and additional functionality is added to it only if
there is a good reason for it.
> Attached patch contains changes on top of "for-loops" branch to
> support "elif" construct in grub script. Please review and let me know
> if anything else needs to be done to get this comitted.
Looks good except absence of ChangeLog entry and that it doesn't apply
to current trunk. Can you fix those?
>
> Thanks
> Deepak
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-26 14:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-16 12:45 [PATCH] support for "elif" in grub script Deepak Vankadaru
2010-03-26 14:13 ` Vladimir 'φ-coder/phcoder' Serbinenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.