Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e227293
add: is_reference()
admiswalker Aug 18, 2024
fd1a655
add: TEST(memory_terp, list_ope_assign_with_reference)
admiswalker Aug 18, 2024
1370077
change name from sstd_yaml::num_ to sstd_yaml::type_
admiswalker Jul 14, 2024
6938288
split type and format
admiswalker Aug 4, 2024
7dc6b81
wip
admiswalker Aug 4, 2024
659bc52
Fix bug of multiple line string input with multile list. add: TEST(ya…
admiswalker Aug 19, 2024
dbf7500
WIP (under implementing the anchor and alias to sstd::yaml)
admiswalker Sep 7, 2024
1594cf1
fix conflict of mearge
admiswalker Dec 30, 2024
3322094
fix mearge conflict of print
admiswalker Dec 30, 2024
9192b2d
rm unused lines
admiswalker Jan 18, 2025
f89571d
add: TEST(yaml, _str2token__multi_list__anchor_and_alias__case1), TES…
admiswalker Jan 18, 2025
ef0f548
wip
admiswalker Jan 18, 2025
f062403
wip
admiswalker Jan 18, 2025
e3b1cfd
fix bug of sstd::terp::var::push_back()
admiswalker Jan 18, 2025
beed14d
wip
admiswalker Jan 19, 2025
8b9589e
add: sstd::split(c, c, int), sstd::split(s, c, int)
admiswalker Jan 19, 2025
31599ab
add TEST(yaml, anchor_and_alias__case03)
admiswalker Feb 1, 2025
be43d12
wip
admiswalker Feb 1, 2025
56df751
change the order of code to resolve dependencies
admiswalker Feb 1, 2025
145851f
add: TEST(yaml, anchor_and_alias__case04)
admiswalker Feb 1, 2025
6df881e
add: TEST(yaml, anchor_and_alias__case06_hash_value) (WIP)
admiswalker Feb 1, 2025
9004fd0
fix bug of sstd::terp::equal()
admiswalker Apr 19, 2025
b953648
add: TEST(yaml, block_list_and_flow_list_02)
admiswalker Apr 27, 2025
925e95e
add: TEST(memory_terp, hash_find_ref)
admiswalker Apr 28, 2025
87eb91d
add: TEST(memory_terp, var_ope_square_brackets_hash_REF_02)
admiswalker Apr 28, 2025
a4d31a3
add: TEST(yaml, anchor_and_alias__case09_hash)
admiswalker Apr 29, 2025
97ce7f1
add: TEST(yaml, anchor_and_alias__case09b_hash)
admiswalker May 11, 2025
1abf7a9
wip
admiswalker May 26, 2025
a66ba6e
WIP: add: TEST(strEdit, splitAll_CC)
admiswalker Jun 9, 2025
39eb64e
Bug fix (breaking change): sstd::split(c/s), sstd::split(c/s,c/s). Ad…
admiswalker Jun 14, 2025
442551d
wip
admiswalker Jun 14, 2025
a861179
add: sstd::splitAll_tight(c/s,c/s)
admiswalker Jun 14, 2025
c138d9b
add: TEST(yaml, anchor_and_alias__case09error01_hash)
admiswalker Jun 14, 2025
df2bb58
rm unused lines
admiswalker Jun 14, 2025
cdfe617
add TEST(yaml, hash_multiple_line)
admiswalker Jun 14, 2025
f6a6477
add: TEST(yaml, anchor_and_alias__case09d_hash)
admiswalker Jun 15, 2025
89be3ff
add: TEST(yaml, anchor_and_alias__case09error03_hash)
admiswalker Jun 15, 2025
879746c
add: TEST(yaml, hash_multiple_line_02)
admiswalker Jun 15, 2025
ec46ca5
add: TEST(yaml, anchor_and_alias__case09d_hash)
admiswalker Jun 15, 2025
5d89474
add: TEST(yaml, anchor_and_alias__case10_hash_list)
admiswalker Jun 15, 2025
bf88f7a
add: TEST(yaml, anchor_and_alias__case11_list)
admiswalker Jun 15, 2025
32e6171
add: TEST(yaml, anchor_and_alias__case07b_list)
admiswalker Jun 29, 2025
e0d7423
add: TEST(yaml, anchor_and_alias__case08b_hash)
admiswalker Jun 29, 2025
87c4ee0
rm unused lines
admiswalker Jun 29, 2025
3241e9f
add: TEST(yaml, anchor_and_alias__case12_list_hash)
admiswalker Jun 29, 2025
13c75bb
rm debugging prints
admiswalker Jun 29, 2025
819da80
rm debugging prints
admiswalker Jun 29, 2025
91cd0ca
change ubuntu-24.04 to ubuntu-24.040-arm at main_tests_on_raspberry_p…
admiswalker Jul 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/main_tests_on_raspberry_pi_os_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ on:

jobs:
Build-and-Test:
runs-on: ubuntu-24.04
# runs-on: ubuntu-24.04
runs-on: ubuntu-24.04-arm

steps:
- name: checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

- name: Install build tools
run: |
Expand Down
698 changes: 428 additions & 270 deletions sstd/src/file/yaml.cpp

Large diffs are not rendered by default.

84 changes: 43 additions & 41 deletions sstd/src/file/yaml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,73 @@ namespace sstd_yaml{
//---
// operation definition

const static uint8 ope_null = 255;
const static uint8 ope_alloc = 0; // allocate
const static uint8 ope_stack = 1; // stacking a value to v_dst
const static uint8 ope_assign = 2; // assignemnt
const static uint8 ope_null = 255;
const static uint8 ope_alloc = 0; // allocate
const static uint8 ope_stack = 1; // stacking a value to v_dst
const static uint8 ope_assign = 2; // assignemnt
// const static uint8 ope_push_ref = 3; // pushing a reference address to the hash table
// const static uint8 ope_pull_ref = 4; // pulling a reference address from the hash table

//---
// type definition

// TODO: num_ -> type_ に名前を置換する
const static uint8 type_null = 255;
const static uint8 type_str = 0; // for BLOCK_STYLE
const static uint8 type_list = 1; // for BLOCK_STYLE
const static uint8 type_hash = 2; // for BLOCK_STYLE
const static uint8 type_list_and_hash = 3; // for BLOCK_STYLE

const static uint8 num_null = 255;
const static uint8 num_block_style_base = 0;
const static uint8 num_str = 0; // for BLOCK_STYLE
const static uint8 num_list = 1; // for BLOCK_STYLE
const static uint8 num_hash = 2; // for BLOCK_STYLE
const static uint8 num_list_and_hash = 3; // for BLOCK_STYLE
const static uint8 num_flow_style_base = 4;
// sstd_yaml::num_flow_style_base + sstd_yaml::num_str 4 // reserved number for FLOW_STYLE
// sstd_yaml::num_flow_style_base + sstd_yaml::num_list 5 // reserved number for FLOW_STYLE
// sstd_yaml::num_flow_style_base + sstd_yaml::num_hash 6 // reserved number for FLOW_STYLE
// sstd_yaml::num_flow_style_base + sstd_yaml::num_list_and_hash 7 // reserved number for FLOW_STYLE
const static uint8 format_null = 255;
const static uint8 format_block_style = 0; // using indents to construct
const static uint8 format_flow_style = 1; // list [] or {}

const static uint8 ref_type_null = 255;
const static uint8 ref_type_anchor = 0; // &
const static uint8 ref_type_alias = 1; // *

//---
// token for proceed YAML parsing

struct token {
// Data for Debug YAML parsing
uint line_num_begin = 1; // beginning line number
uint line_num_end = 1; // endding line number (for multipleline)
std::string rawStr; // A raw string splitted by line concering the YAML processing units.
uint line_num_begin = 1; // beginning line number
uint line_num_end = 1; // endding line number (for multipleline)
std::string rawStr; // A raw string splitted by line concering the YAML processing units.

// Data structure to load YAML
//uint type = sstd_yaml::num_null; // sstd_yaml::num_str; // A destination type number of this line
uint type = sstd_yaml::num_str; // A destination type number of this line
uint format = sstd_yaml::num_block_style_base; // If containing flow style notation
uint list_type_cnt = 0; // Number of list type. (`- - - v`)
uint hsc_lx = 0; // head space counts for list type
uint hsc_hx = 0; // head space counts for hash type
uint8 type = sstd_yaml::type_str; // A destination type number of this line
uint8 format = sstd_yaml::format_block_style; // If containing flow style notation
uint8 ref_type = sstd_yaml::ref_type_null; // If containing anchor or alias
uint list_type_cnt = 0; // Number of list type. (`- - - v`)
uint hsc_lx = 0; // head space counts for list type
uint hsc_hx = 0; // head space counts for hash type

bool hasValue = false; // If the value (val1 or val2) is vaild for each data type (list or hash).
bool key_is_dqed = false;
bool key_is_sqed = false;
bool val_is_dqed = false;
bool val_is_sqed = false;
bool hasValue = false; // If the value (val1 or val2) is vaild for each data type (list or hash)
bool key_is_dqed = false; // _dqed: double quated
bool key_is_sqed = false; // _sqed: single quated
bool val_is_dqed = false; // _dqed: double quated
bool val_is_sqed = false; // _sqed: single quated
bool mult_line_val = false;
std::string key; // key for "hash"
std::string val; // value for "list" or "hash"
std::string aa_val; // value for anchor and alias
};
struct command{
// Data for Debug YAML parsing
uint line_num_begin = 1; // beginning line number
uint line_num_end = 1; // endding line number (for multipleline)
std::string rawStr; // A raw string splitted by line concering the YAML processing units.

uint line_num_begin = 1; // beginning line number
uint line_num_end = 1; // endding line number (for multipleline)
std::string rawStr; // A raw string splitted by line concering the YAML processing units.
// Data structure to construct YAML
uint ope; // operation
uint hsc; // hsc: head space count
uint8 type; // data type
uint8 format; // data format
std::string val; // value

// Anchor and Alias
uint8 ref_type = sstd_yaml::ref_type_null; // If containing anchor or alias
std::string aa_val; // anchor and alias value
};

//---
Expand Down Expand Up @@ -102,13 +109,8 @@ namespace sstd_yaml{
//-----------------------------------------------------------------------------------------------------------------------------------------------

namespace sstd{
void print(const sstd_yaml::token& rhs);
void for_printn(const sstd_yaml::token& rhs);
void print_for_vT(const sstd_yaml::token& rhs);

void print(const sstd_yaml::command& rhs);
void for_printn(const sstd_yaml::command& rhs);
void print_for_vT(const sstd_yaml::command& rhs);
void print_base(const sstd_yaml::token& rhs);
void print_base(const sstd_yaml::command& rhs);

bool yaml_load ( sstd::terp::var & ret_yml, const char* s);
bool yaml_load ( sstd::terp::var & ret_yml, const std::string& s);
Expand Down
61 changes: 35 additions & 26 deletions sstd/src/memory/terp/terp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ void _free_val(sstd::terp::var* _pVar, void*& _p, sstd::terp::srcr_tbl* _pSRCR_t
//-----------------------------------------------------------------------------------------------------------------------------------------------
// for internal use

// cast
std::string* _cast2str (void* rhs){ return ( std::string*)rhs; }
std::vector<sstd::void_ptr>* _cast2vec (void* rhs){ return (std::vector<sstd::void_ptr>*)rhs; }
std::unordered_map<std::string,sstd::void_ptr>* _cast2hash(void* rhs){ return (std::unordered_map<std::string,sstd::void_ptr>*)rhs; }

#define STR (*(std::string*)src.p())

void sstd::terp::_to( bool & dst, const sstd::terp::var& src){
Expand Down Expand Up @@ -210,7 +205,11 @@ sstd::terp::var::var( float rhs): _type(sstd::num_str ), _is_referen
sstd::terp::var::var( double rhs): _type(sstd::num_str ), _is_reference(false), _is_pSRCR_tbl_base(true), _pSRCR_tbl(new sstd::terp::srcr_tbl()), _p(new std::string(sstd::ssprintf(_format(rhs).c_str(), rhs))) {}
sstd::terp::var::var(const char* rhs): _type(sstd::num_str ), _is_reference(false), _is_pSRCR_tbl_base(true), _pSRCR_tbl(new sstd::terp::srcr_tbl()), _p(new std::string(rhs)) {}
sstd::terp::var::var(const std::string& rhs): _type(sstd::num_str ), _is_reference(false), _is_pSRCR_tbl_base(true), _pSRCR_tbl(new sstd::terp::srcr_tbl()), _p(new std::string(rhs)) {}
sstd::terp::var::var(const sstd::terp::srcr_tbl* rhs): _type(sstd::num_null), _is_reference(false), _is_pSRCR_tbl_base(false), _pSRCR_tbl((sstd::terp::srcr_tbl*)rhs), _p(NULL) {}

sstd::terp::var::var(const sstd::terp::srcr_tbl* tbl ): _type(sstd::num_null), _is_reference(false), _is_pSRCR_tbl_base(false), _pSRCR_tbl((sstd::terp::srcr_tbl*)tbl), _p(NULL) {}
sstd::terp::var::var(const sstd::terp::srcr_tbl* tbl, const class var& rhs): _type(sstd::num_null), _is_reference(false), _is_pSRCR_tbl_base(false), _pSRCR_tbl((sstd::terp::srcr_tbl*)tbl), _p(NULL) { copy(rhs); }
sstd::terp::var::var(const sstd::terp::srcr_tbl* tbl, class var&& rhs): _type(sstd::num_null), _is_reference(false), _is_pSRCR_tbl_base(false), _pSRCR_tbl((sstd::terp::srcr_tbl*)tbl), _p(NULL) { free(); move(std::move(rhs)); }
sstd::terp::var::var(const sstd::terp::srcr_tbl* tbl, const char* rhs): _type(sstd::num_str ), _is_reference(false), _is_pSRCR_tbl_base(false), _pSRCR_tbl((sstd::terp::srcr_tbl*)tbl), _p(new std::string(rhs)) {}

sstd::terp::var::~var(){ sstd::terp::var::free(); }

Expand Down Expand Up @@ -574,8 +573,8 @@ sstd::terp::var& sstd::terp::var::operator=(const sstd::terp::var* pRhs_in){
template <typename T>
void sstd::terp::var::_overwrite(T* ptr){
_free_val(this, _p, _pSRCR_tbl, _type, _is_reference);
this->_type = sstd::type2num(T());
this->_p = ptr;
this->_type = sstd::type2num(T());
this->_p = ptr;
}
sstd::terp::var& sstd::terp::var::operator=(const char* rhs){
_overwrite(new std::string(rhs));
Expand Down Expand Up @@ -614,8 +613,9 @@ bool _is_equal_hash(const sstd::terp::var& lhs, const sstd::terp::var& rhs,

auto itr_rhs = rhs.find(key.c_str());
if(!(itr_rhs!=rhs.end())){ return false; }

if(!_is_equal(itr.second(), itr_rhs.second(), check_ref_flag, ref_addr_graph, check_ref_abs_addr, vStack_lhsP_and_rhsP, tbl_lhsAds_to_rhsAds)){ return false; }

//if(!_is_equal(itr.second(), itr_rhs.second(), check_ref_flag, ref_addr_graph, check_ref_abs_addr, vStack_lhsP_and_rhsP, tbl_lhsAds_to_rhsAds)){ return false; } // This is invalid implimentation. Because the "itr.second()" makes the new temporal object and the address of `pSRCR_tbl()` changed.
if(!_is_equal(lhs[key.c_str()], rhs[key.c_str()], check_ref_flag, ref_addr_graph, check_ref_abs_addr, vStack_lhsP_and_rhsP, tbl_lhsAds_to_rhsAds)){ return false; }
}

return true;
Expand All @@ -637,7 +637,7 @@ bool _is_equal(const sstd::terp::var& lhs, const sstd::terp::var& rhs,
// ├────────────────────────────────┼───────────────────────────────────────────────┼──────────────┤
// │ sstd::terp::equal_val() │ true │ false │ false │ │
// ├────────────────────────────────┼───────────────────────────────────────────────┼──────────────┤
// │ sstd::terp::equal_refAbsAddr() │ true │ true │ false │ │
// │ sstd::terp::equal_refAbsAddr() │ true │ true │ false │ │ /* <- This is NOT implimented yet */
// └────────────────────────────────┴───────────────────────────────────────────────┴──────────────┘
// *1. Options:
// true: sets to check the option
Expand All @@ -647,26 +647,28 @@ bool _is_equal(const sstd::terp::var& lhs, const sstd::terp::var& rhs,
// ref_flag: 'true' | 'false'
// ref_addr_graph: 'true' | 'false'

if(lhs.type()!=rhs.type()){ return false; }

if(ref_addr_graph){
tbl_lhsAds_to_rhsAds[ (sstd::terp::var*)&lhs ] = (sstd::terp::var*)&rhs;
}
if(check_ref_flag){
if(lhs.is_reference()!=rhs.is_reference()){ return false; }
if(lhs.is_reference()){
bool is_internal_ref_lhs = _is_internal_ref(&lhs);
bool is_internal_ref_rhs = _is_internal_ref(&rhs);

if(is_internal_ref_lhs != is_internal_ref_rhs){ return false; }
if(is_internal_ref_lhs){
// If the reference is `internal` reference.
vStack_lhsP_and_rhsP.push_back( std::make_tuple((sstd::terp::var*)&lhs, (sstd::terp::var*)&rhs) );
return true; // Check the `vStack_lhsP_and_rhsP` later. (Just confirm the address consistency is enough.)
}else{
// If the reference is `external` reference.
if(lhs.p() != rhs.p()){ sstd::printn_all("");return false; }
if(lhs.p() != rhs.p()){ return false; }
}
}
}
if(lhs.type()!=rhs.type()){ return false; }

if(ref_addr_graph){
tbl_lhsAds_to_rhsAds[ (sstd::terp::var*)&lhs ] = (sstd::terp::var*)&rhs;
}

switch(lhs.typeNum()){
case sstd::num_str: { return lhs.to<std::string>()==rhs.to<std::string>(); } break;
Expand Down Expand Up @@ -723,9 +725,11 @@ bool sstd::terp::var::operator!=(const sstd::terp::var& rhs){ return !sstd::terp
} \
return *this;
#define _OPE_SUBSCRIPT_KEY_BASE(pKey) \
void* local_p = (! this->_is_reference) ? _p : (void*)((sstd::terp::var*)_p)->_p; \
\
switch(_type){ \
case sstd::num_hash_terp_var: { \
sstd::terp::var** ppVal = &(_CAST2HASH(_p)[pKey]); \
sstd::terp::var** ppVal = &(_CAST2HASH(local_p)[pKey]); \
if(*ppVal==NULL){ (*ppVal)=new sstd::terp::var(_pSRCR_tbl); } \
return **ppVal; \
} break; \
Expand All @@ -740,11 +744,13 @@ bool sstd::terp::var::operator!=(const sstd::terp::var& rhs){ return !sstd::terp
} \
return *this;
#define _OPE_SUBSCRIPT_KEY_BASE_CONST(pKey) \
void* local_p = (! this->_is_reference) ? _p : (void*)((sstd::terp::var*)_p)->_p; \
\
switch(_type){ \
case sstd::num_hash_terp_var: { \
sstd::terp::var* pVal = _CAST2HASH(_p)[pKey]; \
if(pVal==NULL){ sstd::pdbg_err("Ope[](char*) is failed. NULL pointer detection error. pKey: `%s` is NOT allocated.\n", pKey); return *this; } \
return *pVal; \
sstd::terp::var** ppVal = &(_CAST2HASH(local_p)[pKey]); \
if(*ppVal==NULL){ sstd::pdbg_err("Ope[](char*) is failed. NULL pointer detection error. pKey: `%s` is NOT allocated.\n", pKey); return *this; } \
return **ppVal; \
} break; \
default: { sstd::pdbg_err("Ope[](char*) is failed. Unexpedted data type. sstd::terp::var takes type number `%d`, but treat as a \"sstd::terp::hash()\".\n", _type); } break; \
} \
Expand Down Expand Up @@ -840,7 +846,10 @@ uint sstd::terp::var::erase(const char* pKey){

sstd::terp::iterator sstd::terp::var::find(const char* pKey) const {
switch(_type){
case sstd::num_hash_terp_var: { return sstd::terp::iterator( _CAST2HASH(_p).find(pKey) ); } break;
case sstd::num_hash_terp_var: {
void* local_p = (! this->_is_reference) ? _p : (void*)((sstd::terp::var*)_p)->_p;
return sstd::terp::iterator( _CAST2HASH(local_p).find(pKey) );
} break;
case sstd::num_null: {} break;
default: { sstd::pdbg_err("ERROR\n"); }
}
Expand All @@ -866,22 +875,22 @@ void sstd::terp::var::pop_back(){
void sstd::terp::var::push_back(){ // push_back null
NULL_CHECK(_p);
if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(char*) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; }
_CAST2VEC(_p).push_back(new sstd::terp::var());
_CAST2VEC(_p).push_back(new sstd::terp::var((sstd::terp::srcr_tbl*)this->_pSRCR_tbl));
}
void sstd::terp::var::push_back(const char* pRhs){
NULL_CHECK(_p);
if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(char*) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; }
_CAST2VEC(_p).push_back(new sstd::terp::var(pRhs));
_CAST2VEC(_p).push_back(new sstd::terp::var((sstd::terp::srcr_tbl*)this->_pSRCR_tbl, pRhs));
}
void sstd::terp::var::push_back(const sstd::terp::var& rhs){
NULL_CHECK(_p);
if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(var&) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; }
_CAST2VEC(_p).push_back(new sstd::terp::var(rhs));
_CAST2VEC(_p).push_back(new sstd::terp::var((sstd::terp::srcr_tbl*)this->_pSRCR_tbl, rhs));
}
void sstd::terp::var::push_back( sstd::terp::var&& rhs){
NULL_CHECK(_p);
if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(var&) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; }
_CAST2VEC(_p).push_back(new sstd::terp::var(std::move(rhs))); // call move constructor of "sstd::void_ptr::void_ptr()"
_CAST2VEC(_p).push_back(new sstd::terp::var((sstd::terp::srcr_tbl*)this->_pSRCR_tbl, std::move(rhs))); // call move constructor of "sstd::void_ptr::void_ptr()"
}

void sstd::terp::var::resize(uint len){
Expand Down
Loading