Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
kashbrti committed Oct 31, 2024
1 parent aefae3b commit 1f6276b
Show file tree
Hide file tree
Showing 14 changed files with 6,028 additions and 3,570 deletions.
595 changes: 364 additions & 231 deletions src/_string_tools/slice_packed_field.nr

Large diffs are not rendered by default.

372 changes: 169 additions & 203 deletions src/_table_generation/make_tables.nr

Large diffs are not rendered by default.

5,302 changes: 2,716 additions & 2,586 deletions src/_table_generation/make_tables_subtables.nr

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/get_array.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::json_entry::JSONEntry;
use crate::json::JSON;
use crate::_comparison_tools::lt::lt_field_16_bit;
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::END_ARRAY_TOKEN;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};
use crate::getters::JSONValue;
use crate::json::JSON;
use crate::json_entry::JSONEntry;

/**
* @brief getter methods for extracting array types out of a JSON struct
Expand Down
6 changes: 3 additions & 3 deletions src/get_literal.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::json_entry::JSONEntry;
use crate::json::JSON;
use crate::_comparison_tools::lt::lt_field_16_bit;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::LITERAL_TOKEN;
use crate::getters::JSONValue;
use crate::json::JSON;
use crate::json_entry::JSONEntry;

global MAX_LITERAL_LENGTH_AS_STRING = 5;
global LITERAL_OFFSET_SHIFT: [Field; 6] =
Expand Down
8 changes: 4 additions & 4 deletions src/get_number.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::json_entry::JSONEntry;
use crate::json::JSON;
use crate::_comparison_tools::lt::lt_field_16_bit;
use crate::json_tables::ASCII_TO_NUMBER;
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::NUMERIC_TOKEN;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};
use crate::getters::JSONValue;
use crate::json::JSON;
use crate::json_entry::JSONEntry;
use crate::json_tables::ASCII_TO_NUMBER;

global U64_LENGTH_AS_BASE10_STRING = 20;
global NUMBER_OFFSET_SHIFT: [Field; 21] = [
Expand Down
62 changes: 43 additions & 19 deletions src/get_object.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::json_entry::JSONEntry;
use crate::json::JSON;
use crate::_comparison_tools::lt::lt_field_16_bit;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::END_OBJECT_TOKEN;
use crate::getters::JSONValue;
use crate::json::JSON;
use crate::json_entry::JSONEntry;

/**
* @brief getter methods for extracting object types out of a JSON struct
**/
impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32> JSON<NumBytes,NumPackedFields, MaxNumTokens, MaxNumValues, MaxKeyFields> {
impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32> JSON<NumBytes, NumPackedFields, MaxNumTokens, MaxNumValues, MaxKeyFields> {

/**
* @brief if the root JSON is an object, extract a child object given by `key`
Expand All @@ -20,7 +20,8 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
let (exists, key_index) = self.key_exists_impl(key);
let entry: JSONEntry = self.json_entries_packed[key_index].into();
assert(
(entry.entry_type - END_OBJECT_TOKEN) * exists as Field == 0, "get_object: entry exists but is not an object!"
(entry.entry_type - END_OBJECT_TOKEN) * exists as Field == 0,
"get_object: entry exists but is not an object!",
);

let mut r = self;
Expand All @@ -39,7 +40,10 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index(key);
let entry: JSONEntry = self.json_entries_packed[key_index].into();
assert(entry.entry_type == END_OBJECT_TOKEN, "get_object: entry exists but is not an object!");
assert(
entry.entry_type == END_OBJECT_TOKEN,
"get_object: entry exists but is not an object!",
);

let mut r = self;
r.layer_type_of_root = entry.parent_index;
Expand All @@ -58,7 +62,8 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
let (exists, key_index) = self.key_exists_impl_var(key);
let entry: JSONEntry = self.json_entries_packed[key_index].into();
assert(
(entry.entry_type - END_OBJECT_TOKEN) * exists as Field == 0, "get_object: entry exists but is not an object!"
(entry.entry_type - END_OBJECT_TOKEN) * exists as Field == 0,
"get_object: entry exists but is not an object!",
);

let mut r = self;
Expand All @@ -76,7 +81,10 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index_var(key);
let entry: JSONEntry = self.json_entries_packed[key_index].into();
assert(entry.entry_type == END_OBJECT_TOKEN, "get_object: entry exists but is not an object!");
assert(
entry.entry_type == END_OBJECT_TOKEN,
"get_object: entry exists but is not an object!",
);

let mut r = self;
r.layer_type_of_root = entry.parent_index;
Expand All @@ -91,17 +99,22 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
* @description returns an Option<JSON> where, if the object exists, the JSON object will have the requested object as its root value
**/
fn get_object_from_array(self, array_index: Field) -> Option<Self> {
assert(self.layer_type_of_root == ARRAY_LAYER, "can only acceess array elements from array");
assert(
self.layer_type_of_root == ARRAY_LAYER,
"can only acceess array elements from array",
);

let parent_entry : JSONEntry = self.json_entries_packed[self.root_index_in_transcript].into();
let parent_entry: JSONEntry =
self.json_entries_packed[self.root_index_in_transcript].into();

let valid = lt_field_16_bit(array_index, parent_entry.num_children);
let entry_index = (parent_entry.child_pointer + array_index) * valid as Field;

let entry : JSONEntry = self.json_entries_packed[entry_index].into();
let entry: JSONEntry = self.json_entries_packed[entry_index].into();

assert(
(entry.entry_type - END_OBJECT_TOKEN) * valid as Field == 0, "get_object_from_array: entry exists but is not an object!"
(entry.entry_type - END_OBJECT_TOKEN) * valid as Field == 0,
"get_object_from_array: entry exists but is not an object!",
);

let mut r = self;
Expand All @@ -118,17 +131,22 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
* @description will revert if the object does not exist
**/
fn get_object_from_array_unchecked(self, array_index: Field) -> Self {
assert(self.layer_type_of_root == ARRAY_LAYER, "can only acceess array elements from array");
assert(
self.layer_type_of_root == ARRAY_LAYER,
"can only acceess array elements from array",
);

let parent_entry : JSONEntry = self.json_entries_packed[self.root_index_in_transcript].into();
let parent_entry: JSONEntry =
self.json_entries_packed[self.root_index_in_transcript].into();

let valid = lt_field_16_bit(array_index, parent_entry.num_children);
assert(valid, "array overflow");
let entry_index = (parent_entry.child_pointer + array_index);

let entry : JSONEntry = self.json_entries_packed[entry_index].into();
let entry: JSONEntry = self.json_entries_packed[entry_index].into();
assert(
entry.entry_type == END_OBJECT_TOKEN, "get_object_from_array_unchecked: entry exists but is not an object!"
entry.entry_type == END_OBJECT_TOKEN,
"get_object_from_array_unchecked: entry exists but is not an object!",
);

let mut r = self;
Expand Down Expand Up @@ -162,13 +180,19 @@ fn test_object() {
let not_real = B.get_object("bartholomew tony Harrison IV".as_bytes());
assert(not_real.is_some() == false);

let C = B.get_object_unchecked_var(BoundedVec { storage: "bartholomew tony Harrison III".as_bytes(), len: 29 });
let C = B.get_object_unchecked_var(
BoundedVec { storage: "bartholomew tony Harrison III".as_bytes(), len: 29 },
);
assert(JSONEntry::from(C.json_entries_packed[C.root_index_in_transcript]).num_children == 1);

let C = B.get_object_var(BoundedVec { storage: "bartholomew tony Harrison III".as_bytes(), len: 28 });
let C = B.get_object_var(
BoundedVec { storage: "bartholomew tony Harrison III".as_bytes(), len: 28 },
);
assert(C.is_some() == false);

let C = B.get_object_var(BoundedVec { storage: "bartholomew tony Harrison IIIekurfgaeoiurh".as_bytes(), len: 29 });
let C = B.get_object_var(
BoundedVec { storage: "bartholomew tony Harrison IIIekurfgaeoiurh".as_bytes(), len: 29 },
);
assert(C.is_some() == true);

let second = first.get_object_from_array_unchecked(4);
Expand Down
12 changes: 6 additions & 6 deletions src/get_string.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::json_entry::JSONEntry;
use crate::json::JSON;
use crate::getters::JSONValue;
use crate::_comparison_tools::lt::lt_field_16_bit;
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::STRING_TOKEN;
use crate::getters::JSONValue;
use crate::json::JSON;
use crate::json_entry::JSONEntry;
use crate::json_tables::{
ESCAPE_SEQUENCE_START_CHARS, ESCAPE_SEQUENCE_END_CHARS, ESCAPE_SEQUENCE_REPLACEMENT,
ESCAPE_SEQUENCE_END_CHARS, ESCAPE_SEQUENCE_REPLACEMENT, ESCAPE_SEQUENCE_START_CHARS,
};
use crate::enums::Token::STRING_TOKEN;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};

unconstrained fn to_u8(f: Field) -> u8 {
f as u8
Expand Down
16 changes: 8 additions & 8 deletions src/getters.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::transcript_entry::TranscriptEntry;
use crate::json_entry::JSONEntry;
use crate::_comparison_tools::lt::{assert_gt_240_bit, assert_lt_240_bit, lt_field_16_bit};
use crate::_string_tools::slice_packed_field::slice_fields;
use crate::_string_tools::string_chopper::StringChopper;
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
use crate::enums::Token::{LITERAL_TOKEN, NUMERIC_TOKEN, STRING_TOKEN};
use crate::json::JSON;
use crate::_comparison_tools::lt::{lt_field_16_bit, assert_lt_240_bit, assert_gt_240_bit};
use crate::enums::Token::{NUMERIC_TOKEN, LITERAL_TOKEN, STRING_TOKEN};
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER};
use crate::json::JSONValue;
use crate::json_entry::JSONEntry;
use crate::keyhash::ByteHasher;
use crate::keymap::KeyIndexData;
use crate::_string_tools::string_chopper::StringChopper;
use crate::_string_tools::slice_packed_field::slice_fields;
use crate::json::JSONValue;
use crate::transcript_entry::TranscriptEntry;
/**
* @brief records data used to reason about whether a key exists in a json blob
**/
Expand Down
14 changes: 7 additions & 7 deletions src/json.nr
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use crate::_comparison_tools::bounds_checker;
use crate::_comparison_tools::bounds_checker::get_validity_flags;
use crate::enums::Layer::{OBJECT_LAYER, ARRAY_LAYER, SINGLE_VALUE_LAYER};
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER, SINGLE_VALUE_LAYER};
use crate::enums::ScanMode::{GRAMMAR_SCAN, LITERAL_SCAN, NUMERIC_SCAN, STRING_SCAN};
use crate::enums::Token::{
BEGIN_OBJECT_TOKEN, END_OBJECT_TOKEN, BEGIN_ARRAY_TOKEN, END_ARRAY_TOKEN, KEY_SEPARATOR_TOKEN,
VALUE_SEPARATOR_TOKEN, STRING_TOKEN, NUMERIC_TOKEN, LITERAL_TOKEN, KEY_TOKEN, NUM_TOKENS,
BEGIN_ARRAY_TOKEN, BEGIN_OBJECT_TOKEN, END_ARRAY_TOKEN, END_OBJECT_TOKEN, KEY_SEPARATOR_TOKEN,
KEY_TOKEN, LITERAL_TOKEN, NUM_TOKENS, NUMERIC_TOKEN, STRING_TOKEN, VALUE_SEPARATOR_TOKEN,
};
use crate::enums::ScanMode::{GRAMMAR_SCAN, STRING_SCAN, NUMERIC_SCAN, LITERAL_SCAN};
use crate::get_literal::JSONLiteral;
use crate::json_entry::{JSONContextStackEntry, JSONEntry, JSONEntryPacked};
use crate::json_tables::{
TOKEN_VALIDATION_TABLE, PROCESS_RAW_TRANSCRIPT_TABLE, JSON_CAPTURE_TABLE, TOKEN_FLAGS_TABLE,
TOKEN_IS_ARRAY_OBJECT_OR_VALUE,
JSON_CAPTURE_TABLE, PROCESS_RAW_TRANSCRIPT_TABLE, TOKEN_FLAGS_TABLE,
TOKEN_IS_ARRAY_OBJECT_OR_VALUE, TOKEN_VALIDATION_TABLE,
};
use crate::token_flags::TokenFlags;
use crate::transcript_entry::{
ValidationFlags, TranscriptEntry, RawTranscriptEntry, ScanData, PostProcessScanData,
PostProcessScanData, RawTranscriptEntry, ScanData, TranscriptEntry, ValidationFlags,
};

/**
Expand Down
Loading

0 comments on commit 1f6276b

Please sign in to comment.