1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Bashrs Parser Playbook - State Machine Definition
# Tests parser state transitions and invariants
#
# Usage: Used by parser_probar_testing.rs for validation
version: "1.0"
name: "Bashrs Parser State Machine"
description: "Verify correct parsing of bash constructs through state transitions"
machine:
id: "bash_parser"
initial: "idle"
states:
idle:
id: "idle"
description: "Parser ready to accept input"
invariants:
- description: "Parser is initialized"
condition: "parser.is_ready()"
- description: "No pending tokens"
condition: "parser.tokens.is_empty()"
tokenizing:
id: "tokenizing"
description: "Lexer breaking input into tokens"
on_entry:
- type: log
message: "Starting tokenization"
invariants:
- description: "Input buffer is set"
condition: "parser.input.len() > 0"
parsing:
id: "parsing"
description: "Building AST from tokens"
invariants:
- description: "Tokens available"
condition: "parser.tokens.len() > 0"
- description: "AST construction in progress"
condition: "parser.ast.is_some() || parser.current_node.is_some()"
ast_complete:
id: "ast_complete"
description: "AST successfully constructed"
final_state: true
invariants:
- description: "AST is complete"
condition: "parser.ast.is_some()"
- description: "No syntax errors"
condition: "parser.errors.is_empty()"
error:
id: "error"
description: "Parser encountered error"
final_state: true
invariants:
- description: "Error is recorded"
condition: "parser.errors.len() > 0"
transitions:
- id: "start_tokenize"
from: "idle"
to: "tokenizing"
event: "input_received"
description: "Begin tokenizing input"
actions:
- type: call
method: "parser.set_input(input)"
- id: "tokens_ready"
from: "tokenizing"
to: "parsing"
event: "tokenization_complete"
description: "Tokens ready for parsing"
guard: "tokens.len() > 0"
- id: "parse_complete"
from: "parsing"
to: "ast_complete"
event: "ast_built"
description: "AST construction successful"
guard: "errors.is_empty()"
- id: "tokenize_error"
from: "tokenizing"
to: "error"
event: "lex_error"
description: "Tokenization failed"
- id: "parse_error"
from: "parsing"
to: "error"
event: "syntax_error"
description: "Parsing failed"
forbidden:
- from: "idle"
to: "ast_complete"
reason: "Cannot complete AST without tokenizing and parsing"
- from: "idle"
to: "parsing"
reason: "Cannot parse without tokenizing first"
- from: "tokenizing"
to: "ast_complete"
reason: "Cannot complete AST without parsing"
# Parser Feature Coverage Requirements
coverage:
features:
variables:
- simple_assignment # x=5
- default_value # ${x:-default}
- assign_default # ${x:=default}
- alternate_value # ${x:+alt}
- error_value # ${x:?error}
- length # ${#x}
- substring # ${x:0:5}
- pattern_removal # ${x%pattern}
- array_access # ${arr[0]}
- indirect_reference # ${!ref}
command_substitution:
- dollar_parens # $(cmd)
- backtick # `cmd`
- nested # $($(inner))
- in_string # "$(cmd)"
- in_arithmetic # $(($(echo 1)))
conditionals:
- if_simple # if ...; then; fi
- if_else # if ...; then; else; fi
- if_elif # if ...; elif; fi
- if_nested # if ...; then if; fi; fi
- test_single_bracket # [ ... ]
- test_double_bracket # [[ ... ]]
- test_arithmetic # (( ... ))
- case_simple # case ... in ...) ;; esac
- case_multiple # case ... in a|b) ;; esac
- case_default # case ... in *) ;; esac
loops:
- for_simple # for i in ...; do; done
- for_c_style # for ((;;)); do; done
- for_brace_expansion # for i in {1..10}
- while_simple # while ...; do; done
- while_read # while read line
- until_simple # until ...; do; done
- select_simple # select opt in ...
- break_statement # break
- continue_statement # continue
functions:
- keyword_syntax # function name { }
- parens_syntax # name() { }
- with_body # multi-statement body
- local_variables # local var=value
- return_statement # return N
- recursive # self-calling
quoting:
- single_quote # 'string'
- double_quote # "string"
- escape_sequences # \"
- dollar_single # $'string'
- ansi_c # $'\x41'
- mixed # 'a'"b"
arithmetic:
- addition # +
- subtraction # -
- multiplication # *
- division # /
- modulo # %
- exponentiation # **
- parentheses # (...)
- assignment # =
- increment # ++/--
- comparison # < > <= >=
redirection:
- output # >
- append # >>
- input # <
- stderr # 2>
- both # &>
- heredoc # <<EOF
- herestring # <<<
- fd_duplication # 2>&1
pipeline:
- simple_pipe # |
- pipe_chain # | |
- and_list # &&
- or_list # ||
- subshell # (...)
- brace_group # { ...; }
- process_substitution # <(...) >(...)
thresholds:
minimum_coverage: 85
target_coverage: 95
# Performance Requirements
performance:
tokenize:
max_duration_ms: 10
max_memory_kb: 100
parse:
max_duration_ms: 50
max_memory_kb: 500
total:
max_duration_ms: 100
max_memory_kb: 1000
# Determinism Requirements
determinism:
enabled: true
iterations: 3
description: "Same input must produce identical AST"
assertions:
path:
must_visit:
- "idle"
- "tokenizing"
- "parsing"
- "ast_complete"
must_not_visit:
- "error" # For valid inputs
output:
- var: "ast"
not_empty: true
- var: "errors"
empty: true # For valid inputs