11//! Contains methods used to generate tables in `json_tables.nr`. These table generation methods shouldn't be used inside of actual circuits.
22use crate::enums::CaptureMode::STRING_CAPTURE ;
3- use crate::enums::Layer:: {ARRAY_LAYER , OBJECT_LAYER , SINGLE_VALUE_LAYER };
3+ use crate::enums::Layer:: {ARRAY_LAYER , OBJECT_LAYER };
44use crate::enums::Token:: {
55 BEGIN_ARRAY_TOKEN , BEGIN_OBJECT_TOKEN , END_ARRAY_TOKEN , END_OBJECT_TOKEN , KEY_SEPARATOR_TOKEN ,
66 KEY_TOKEN , LITERAL_TOKEN , NO_TOKEN , NUM_TOKENS , NUMERIC_TOKEN , STRING_TOKEN ,
@@ -60,32 +60,32 @@ unconstrained fn make_ascii_to_token_table() -> [Field; 1024] {
6060 result
6161}
6262
63- unconstrained fn make_token_validation_table () -> [Field ; NUM_TOKENS * NUM_TOKENS * 3 ] {
63+ unconstrained fn make_token_validation_table () -> [Field ; NUM_TOKENS * NUM_TOKENS * 2 ] {
6464 // index = layer type, current token and next token
6565 // output is layer type
66- // 11 tokens , 3 layers = 11 * 11 * 3 = 121 * 3 = 343
66+ // 11 tokens , 2 layers = 11 * 11 * 2 = 121 * 2 = 242
6767 // object contexts
68- let no_change = ValidationFlags { push_layer : 0 , push_layer_type_of_root : 0 , pop_layer : 0 };
69- let error_flags =
70- ValidationFlags { push_layer : 0x1000000 , push_layer_type_of_root : 0 , pop_layer : 0 } ;
68+ let no_change =
69+ ValidationFlags { push_layer : false , push_layer_type_of_root : false , pop_layer : false };
70+ let error_flags_field = 0x1000000 ;
7171 let begin_new_object_flags = ValidationFlags {
72- push_layer : 1 ,
73- push_layer_type_of_root : OBJECT_LAYER as Field ,
74- pop_layer : 0 ,
72+ push_layer : true ,
73+ push_layer_type_of_root : OBJECT_LAYER != 0 ,
74+ pop_layer : false ,
7575 };
7676 let begin_new_array_flags = ValidationFlags {
77- push_layer : 1 ,
78- push_layer_type_of_root : ARRAY_LAYER as Field ,
79- pop_layer : 0 ,
77+ push_layer : true ,
78+ push_layer_type_of_root : ARRAY_LAYER != 0 ,
79+ pop_layer : false ,
8080 };
8181 let end_object_or_array_flags : ValidationFlags =
82- ValidationFlags { push_layer : 0 , push_layer_type_of_root : 0 , pop_layer : 1 };
82+ ValidationFlags { push_layer : false , push_layer_type_of_root : false , pop_layer : true };
8383
8484 let token_ids : [u32 ; NUM_TOKENS ] = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
8585
86- let error_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|_ | error_flags . to_field () );
86+ let error_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|_ | error_flags_field );
8787 let object_layer_begin_object_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
88- let mut result = error_flags . to_field () ;
88+ let mut result = error_flags_field ;
8989 if (token == KEY_TOKEN ) {
9090 result = no_change .to_field ();
9191 }
@@ -98,13 +98,13 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
9898 let object_layer_key_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
9999 let mut result = no_change .to_field ();
100100 if (token != KEY_SEPARATOR_TOKEN ) {
101- result = error_flags . to_field () ;
101+ result = error_flags_field ;
102102 }
103103 result
104104 });
105105
106106 let object_layer_key_separator_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
107- let mut result = error_flags . to_field () ;
107+ let mut result = error_flags_field ;
108108 if (token == STRING_TOKEN ) | (token == LITERAL_TOKEN ) | (token == NUMERIC_TOKEN ) {
109109 result = no_change .to_field ();
110110 }
@@ -118,7 +118,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
118118 });
119119
120120 let object_layer_value_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
121- let mut result = error_flags . to_field () ;
121+ let mut result = error_flags_field ;
122122 if (token == VALUE_SEPARATOR_TOKEN ) {
123123 result = no_change .to_field ();
124124 }
@@ -129,7 +129,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
129129 });
130130
131131 let object_layer_end_object_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
132- let mut result = error_flags . to_field () ;
132+ let mut result = error_flags_field ;
133133 if (token == VALUE_SEPARATOR_TOKEN ) {
134134 result = no_change .to_field ();
135135 }
@@ -144,7 +144,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
144144 });
145145
146146 let object_layer_value_separator_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
147- let mut result = error_flags . to_field () ;
147+ let mut result = error_flags_field ;
148148 if (token == KEY_TOKEN ) {
149149 result = no_change .to_field ();
150150 }
@@ -153,11 +153,8 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
153153
154154 let mut object_layer_flags : [[Field ; NUM_TOKENS ]; NUM_TOKENS ] = [[0 ; NUM_TOKENS ]; NUM_TOKENS ];
155155 let mut array_layer_flags : [[Field ; NUM_TOKENS ]; NUM_TOKENS ] = [[0 ; NUM_TOKENS ]; NUM_TOKENS ];
156- let mut single_value_layer_flags : [[Field ; NUM_TOKENS ]; NUM_TOKENS ] =
157- [[0 ; NUM_TOKENS ]; NUM_TOKENS ];
158-
159156 let no_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
160- let mut result = error_flags . to_field () ;
157+ let mut result = error_flags_field ;
161158 if (token == NO_TOKEN ) {
162159 result = no_change .to_field ();
163160 }
@@ -177,7 +174,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
177174 object_layer_flags [KEY_TOKEN ] = object_layer_key_token_outcomes ;
178175
179176 let array_layer_begin_array_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token : u32 | {
180- let mut result = error_flags . to_field () ;
177+ let mut result = error_flags_field ;
181178 if (token == STRING_TOKEN ) | (token == LITERAL_TOKEN ) | (token == NUMERIC_TOKEN ) {
182179 result = no_change .to_field ();
183180 }
@@ -194,7 +191,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
194191 });
195192
196193 let array_layer_value_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
197- let mut result = error_flags . to_field () ;
194+ let mut result = error_flags_field ;
198195 if (token == VALUE_SEPARATOR_TOKEN ) {
199196 result = no_change .to_field ();
200197 }
@@ -205,7 +202,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
205202 });
206203
207204 let array_layer_value_separator_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
208- let mut result = error_flags . to_field () ;
205+ let mut result = error_flags_field ;
209206 if (token == STRING_TOKEN ) | (token == LITERAL_TOKEN ) | (token == NUMERIC_TOKEN ) {
210207 result = no_change .to_field ();
211208 }
@@ -219,7 +216,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
219216 });
220217
221218 let array_layer_value_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
222- let mut result = error_flags . to_field () ;
219+ let mut result = error_flags_field ;
223220 if (token == VALUE_SEPARATOR_TOKEN ) {
224221 result = no_change .to_field ();
225222 }
@@ -229,7 +226,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
229226 result
230227 });
231228 let array_layer_end_array_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
232- let mut result = error_flags . to_field () ;
229+ let mut result = error_flags_field ;
233230 if (token == VALUE_SEPARATOR_TOKEN ) {
234231 result = no_change .to_field ();
235232 }
@@ -243,7 +240,7 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
243240 result
244241 });
245242 let array_layer_end_object_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
246- let mut result = error_flags . to_field () ;
243+ let mut result = error_flags_field ;
247244 if (token == VALUE_SEPARATOR_TOKEN ) {
248245 result = no_change .to_field ();
249246 }
@@ -264,36 +261,13 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
264261 array_layer_flags [NUMERIC_TOKEN ] = array_layer_value_token_outcomes ;
265262 array_layer_flags [LITERAL_TOKEN ] = array_layer_value_token_outcomes ;
266263 array_layer_flags [KEY_TOKEN ] = error_token_outcomes ;
267-
268- let single_value_layer_value_token_outcomes : [Field ; NUM_TOKENS ] = token_ids .map (|token | {
269- let mut result = error_flags .to_field ();
270- // we have reached the end of json
271- if (token == NO_TOKEN ) {
272- result = no_change .to_field ();
273- }
274- result
275- });
276- single_value_layer_flags [NO_TOKEN ] = no_token_outcomes ;
277- single_value_layer_flags [BEGIN_OBJECT_TOKEN ] = error_token_outcomes ;
278- single_value_layer_flags [END_OBJECT_TOKEN ] = single_value_layer_value_token_outcomes ;
279- single_value_layer_flags [BEGIN_ARRAY_TOKEN ] = error_token_outcomes ;
280- single_value_layer_flags [END_ARRAY_TOKEN ] = single_value_layer_value_token_outcomes ;
281- single_value_layer_flags [KEY_SEPARATOR_TOKEN ] = object_layer_key_separator_token_outcomes ;
282- single_value_layer_flags [VALUE_SEPARATOR_TOKEN ] = error_token_outcomes ;
283- single_value_layer_flags [STRING_TOKEN ] = single_value_layer_value_token_outcomes ;
284- single_value_layer_flags [NUMERIC_TOKEN ] = single_value_layer_value_token_outcomes ;
285- single_value_layer_flags [LITERAL_TOKEN ] = single_value_layer_value_token_outcomes ;
286- single_value_layer_flags [KEY_TOKEN ] = no_token_outcomes ;
287-
288- let mut flattened_flags : [Field ; NUM_TOKENS * NUM_TOKENS * 3 ] =
289- [0 ; NUM_TOKENS * NUM_TOKENS * 3 ];
264+ let mut flattened_flags : [Field ; NUM_TOKENS * NUM_TOKENS * 2 ] =
265+ [0 ; NUM_TOKENS * NUM_TOKENS * 2 ];
290266 let NN = (NUM_TOKENS * NUM_TOKENS );
291267 for j in 0 ..NUM_TOKENS {
292268 for k in 0 ..NUM_TOKENS {
293269 flattened_flags [OBJECT_LAYER * NN + j * NUM_TOKENS + k ] = object_layer_flags [j ][k ];
294270 flattened_flags [ARRAY_LAYER * NN + j * NUM_TOKENS + k ] = array_layer_flags [j ][k ];
295- flattened_flags [SINGLE_VALUE_LAYER * NN + j * NUM_TOKENS + k ] =
296- single_value_layer_flags [j ][k ];
297271 }
298272 }
299273 flattened_flags
0 commit comments