1 /* -------------------------------------------------------
3 ------------------------------------------------------- */
14 %start_symbol complete_command
16 %token_type {struct token *}
17 %extra_argument { struct parser_state *pstate }
23 complete_command ::= list separator.
24 complete_command ::= list.
26 list ::= list separator_op and_or.
30 and_or ::= and_or AND_IF linebreak pipeline.
31 and_or ::= and_or OR_IF linebreak pipeline.
33 pipeline ::= pipe_sequence.
34 pipeline ::= Bang pipe_sequence.
36 pipe_sequence ::= command.
37 pipe_sequence ::= pipe_sequence Pipe linebreak command.
39 command ::= simple_command.
40 command ::= compound_command.
41 command ::= compound_command redirect_list.
42 command ::= function_definition.
44 compound_command ::= brace_group.
45 compound_command ::= subshell.
46 compound_command ::= for_clause.
47 compound_command ::= case_clause.
48 compound_command ::= if_clause.
49 compound_command ::= while_clause.
50 compound_command ::= until_clause.
52 subshell ::= Lparen compound_list Rparen.
54 compound_list ::= term. [NEWLINE]
55 compound_list ::= newline_list term. [NEWLINE]
56 compound_list ::= term separator.
57 compound_list ::= newline_list term separator.
59 term ::= term separator and_or.
62 for_clause ::= For name linebreak do_group.
63 for_clause ::= For name linebreak in sequential_sep do_group.
64 for_clause ::= For name linebreak in wordlist sequential_sep do_group.
66 name ::= NAME /* Apply rule 5 */.
68 in ::= In /* Apply rule 6 */.
69 /* TODO start looking for pattern = Esac here */
71 wordlist ::= wordlist WORD.
78 case_clause ::= case_start case_list Esac.
79 case_clause ::= case_start Esac. { pstate->incase = 0; }
81 /* added to simplify */
82 case_start ::= Case WORD linebreak in linebreak.
84 case_list ::= case_list case_item.
85 case_list ::= case_item.
93 case_item ::= case_item_ns .
94 //case_item ::= case_item_ns DSEMI linebreak.
96 case_item_ns ::= pattern Rparen linebreak. [DSEMI]
97 case_item_ns ::= pattern Rparen linebreak DSEMI linebreak.
99 case_item_ns ::= pattern Rparen compound_list linebreak. [DSEMI]
100 case_item_ns ::= pattern Rparen compound_list linebreak DSEMI linebreak.
101 //case_item_ns ::= Lparen pattern Rparen linebreak. [DSEMI]
102 //case_item_ns ::= Lparen pattern Rparen compound_list linebreak. [DSEMI]
104 //case_item_end ::= linebreak.
105 //case_item_end ::= linebreak DSEMI linebreak.
107 /* rule four implicitly done via %fallback */
108 pattern ::= WORD . /* Apply rule 4 */
109 pattern ::= pattern Pipe WORD . /* Do not apply rule 4 */
112 case_clause ::= case_start case_list_ns Esac.
114 case_list_ns ::= case_list case_item_ns.
115 case_list_ns ::= case_item_ns.
119 if_clause ::= If compound_list Then compound_list else_part Fi.
120 if_clause ::= If compound_list Then compound_list Fi.
122 else_part ::= Elif compound_list Then compound_list.
123 else_part ::= Elif compound_list Then compound_list else_part.
124 else_part ::= Else compound_list.
126 while_clause ::= While compound_list do_group.
128 until_clause ::= Until compound_list do_group.
130 //function_definition ::= fname Lparen Rparen linebreak function_body.
131 function_definition ::= WORD Lparen Rparen linebreak function_body.
133 function_body ::= compound_command /* Apply rule 9 */.
134 function_body ::= compound_command redirect_list /* Apply rule 9 */.
136 /* we would need two tokens of look-ahead to prove this should be a name
139 //fname ::= NAME /* Apply rule 8 */.
142 brace_group ::= Lbrace compound_list Rbrace.
144 do_group ::= Do compound_list Done /* Apply rule 6 */.
146 simple_command ::= cmd_prefix cmd_word cmd_suffix.
147 simple_command ::= cmd_prefix cmd_word.
148 simple_command ::= cmd_prefix.
149 simple_command ::= cmd_name cmd_suffix.
150 simple_command ::= cmd_name.
152 cmd_name ::= WORD /* Apply rule 7a */.
154 cmd_word ::= WORD /* Apply rule 7b */.
156 cmd_prefix ::= io_redirect.
157 cmd_prefix ::= cmd_prefix io_redirect.
158 cmd_prefix ::= ASSIGNMENT_WORD.
159 cmd_prefix ::= cmd_prefix ASSIGNMENT_WORD.
161 cmd_suffix ::= io_redirect.
162 cmd_suffix ::= cmd_suffix io_redirect.
164 cmd_suffix ::= cmd_suffix WORD.
166 redirect_list ::= io_redirect.
167 redirect_list ::= redirect_list io_redirect.
169 io_redirect ::= io_file.
170 io_redirect ::= IO_NUMBER io_file.
171 io_redirect ::= io_here.
172 io_redirect ::= IO_NUMBER io_here.
174 io_file ::= Lessthan filename.
175 io_file ::= LESSAND filename.
176 io_file ::= Greaterthan filename.
177 io_file ::= GREATAND filename.
178 io_file ::= DGREAT filename.
179 io_file ::= LESSGREAT filename.
180 io_file ::= CLOBBER filename.
182 filename ::= WORD /* Apply rule 2 */.
184 io_here ::= DLESS here_end.
185 io_here ::= DLESSDASH here_end.
187 here_end ::= WORD /* Apply rule 3 */.
189 newline_list ::= newline_list NEWLINE.
190 newline_list ::= NEWLINE. { pstate->linebreak = 1; }
192 linebreak ::= newline_list. [NEWLINE]
193 linebreak ::= /* empty */. [NEWLINE]
195 separator_op ::= Ampersand.
196 separator_op ::= Semicolon.
198 separator ::= separator_op linebreak. [NEWLINE]
199 separator ::= newline_list. [NEWLINE]
201 sequential_sep ::= Semicolon linebreak.
202 sequential_sep ::= newline_list.