1 /* 2 * Copyright (C) 2014 Christian Heckendorf <heckendorfc@gmail.com> 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 %{ 18 #include <stdio.h> 19 #include "lex.h" 20 #include "build.h" 21 int yylex(); 22 int yyerror(); 23 24 commandline_t *fullcmd; 25 int charsub=0; 26 int wp_flag=0; 27 %} 28 29 %token TOK_TEXT TOK_QUOTE TOK_QUOTE_STR TOK_WHITESPACE TOK_COMMA 30 %token TOK_WORD 31 %token TOK_SEMICOLON TOK_OPAR TOK_CPAR 32 33 %union{ 34 int number; 35 char *word; 36 wordchain_t *wc; 37 wordlist_t *wl; 38 arglist_t *arg; 39 command_t *command; 40 commandline_t *commandline; 41 } 42 43 %type<word> word_piece TOK_TEXT TOK_QUOTE_STR TOK_QUOTE 44 %type<wc> text_word word 45 %type<command> cmd selector action actionlist 46 %type<commandline> cmdline 47 %type<arg> onearg arglist 48 49 %start cmdline 50 51 %% 52 53 word_piece: TOK_TEXT 54 { 55 wp_flag=WORD_DEFAULT; 56 $$=$1; 57 } 58 | TOK_QUOTE TOK_QUOTE_STR TOK_QUOTE 59 { 60 wp_flag=(*($1)=='"'?WORD_DQUOT:WORD_SQUOT); 61 $$=$2; 62 } 63 ; 64 65 text_word: TOK_TEXT 66 { $$ = make_word(NULL,$1,WORD_DEFAULT); } 67 68 word: word word_piece 69 { $$ = make_word($1,$2,wp_flag); } 70 | word_piece 71 { $$ = make_word(NULL,$1,wp_flag); } 72 ; 73 74 cmd: text_word TOK_OPAR 75 { $$ = make_command(make_word_list(NULL,$1)); } 76 77 onearg: word 78 { $$ = make_com_arg(make_word_list(NULL,$1),COM_ARG_LITERAL); } 79 | selector 80 { $$ = make_com_arg($1,COM_ARG_SELECTOR); } 81 ; 82 83 arglist: onearg 84 { $$ = $1; } 85 | arglist TOK_COMMA onearg 86 { $$ = append_com_arg($3,$1); } 87 ; 88 89 selector: cmd arglist TOK_CPAR 90 { $$ = com_set_args($1,$2,COM_SEL); } 91 92 action: cmd arglist TOK_CPAR 93 { $$ = com_set_args($1,$2,COM_ACT); } 94 | text_word 95 { $$ = make_command(make_word_list(NULL,$1)); $$->flags=COM_ACT; } 96 ; 97 98 actionlist: action 99 { $$ = $1; } 100 | actionlist action 101 { $$ = append_command($1,$2); } 102 | actionlist TOK_WHITESPACE action 103 { $$ = append_command($1,$3); } 104 ; 105 106 cmdline: selector actionlist 107 { fullcmd = make_commandline($1,$2); } 108