Skip to content

Commit 784e071

Browse files
committed
Started #14 bug with intent
1 parent 40965c6 commit 784e071

File tree

2 files changed

+75
-65
lines changed

2 files changed

+75
-65
lines changed

src/wsjcpp_yaml.cpp

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,12 @@ bool WsjcppYaml::parse(const std::string &sFileName, const std::string &sBuffer,
12801280
bool isArrayItem = m_parseLine.isArrayItem();
12811281
int nLineIntent = m_parseLine.getIntent();
12821282
int nDiffIntent = nLineIntent - m_nParseCurrentIntent;
1283-
1283+
std::cout << nLine << ": " << m_nParseCurrentIntent << ", " << nLineIntent << " ; line:[" << m_parsePlaceInFile.getLine() << "]" << std::endl;
1284+
1285+
/*if (nLine > 6) {
1286+
return false;
1287+
}*/
1288+
12841289
if (m_parseLine.isEmptyLine()) {
12851290
if (m_pParseCurrentItem != nullptr) {
12861291
if (m_pParseCurrentItem->isArray() || m_pParseCurrentItem->isMap() || m_pParseCurrentItem->isUndefined()) {
@@ -1303,6 +1308,9 @@ bool WsjcppYaml::parse(const std::string &sFileName, const std::string &sBuffer,
13031308
}
13041309

13051310
while (nDiffIntent < 0) {
1311+
std::cout << nLine << ": nDiffIntent = " << nDiffIntent << std::endl;
1312+
std::cout << nLine << ": m_pParseCurrentItem = " << m_pParseCurrentItem->getNodeDiffIntent() << std::endl;
1313+
std::cout << nLine << ": m_pParseCurrentItem = " << m_pParseCurrentItem->getName() << std::endl;
13061314
int nNodeDiffIntent = m_pParseCurrentItem->getNodeDiffIntent();
13071315
if (nNodeDiffIntent == 0) {
13081316
sError = "Node diff intent cann't be 0 ";
@@ -1317,31 +1325,27 @@ bool WsjcppYaml::parse(const std::string &sFileName, const std::string &sBuffer,
13171325
}
13181326
}
13191327

1320-
if (nDiffIntent == 0) {
1321-
if (m_parseLine.isEmptyName()) {
1322-
if ( ! isEmptyValue && isArrayItem) {
1323-
process_sameIntent_emptyName_hasValue_arrayItem();
1324-
} else if (! isEmptyValue && ! isArrayItem) {
1325-
process_sameIntent_emptyName_hasValue_noArrayItem();
1326-
} else if (isEmptyValue && isArrayItem) {
1327-
process_sameIntent_emptyName_emptyValue_arrayItem();
1328-
} else if (isEmptyValue && ! isArrayItem) {
1329-
process_sameIntent_emptyName_emptyValue_noArrayItem();
1330-
} else {
1331-
logUnknownParseLine();
1332-
}
1333-
} else if ( ! m_parseLine.isEmptyName()) {
1334-
if ( ! isEmptyValue && isArrayItem) {
1335-
process_sameIntent_hasName_hasValue_arrayItem();
1336-
} else if ( ! isEmptyValue && ! isArrayItem) {
1337-
process_sameIntent_hasName_hasValue_noArrayItem();
1338-
} else if (isEmptyValue && isArrayItem) {
1339-
process_sameIntent_hasName_emptyValue_arrayItem();
1340-
} else if (isEmptyValue && ! isArrayItem) {
1341-
process_sameIntent_hasName_emptyValue_noArrayItem();
1342-
} else {
1343-
logUnknownParseLine();
1344-
}
1328+
if (m_parseLine.isEmptyName()) {
1329+
if ( ! isEmptyValue && isArrayItem) {
1330+
process_emptyName_hasValue_arrayItem();
1331+
} else if (! isEmptyValue && ! isArrayItem) {
1332+
process_emptyName_hasValue_noArrayItem();
1333+
} else if (isEmptyValue && isArrayItem) {
1334+
process_emptyName_emptyValue_arrayItem();
1335+
} else if (isEmptyValue && ! isArrayItem) {
1336+
process_emptyName_emptyValue_noArrayItem();
1337+
} else {
1338+
logUnknownParseLine();
1339+
}
1340+
} else if ( ! m_parseLine.isEmptyName()) {
1341+
if ( ! isEmptyValue && isArrayItem) {
1342+
process_hasName_hasValue_arrayItem();
1343+
} else if ( ! isEmptyValue && ! isArrayItem) {
1344+
process_hasName_hasValue_noArrayItem();
1345+
} else if (isEmptyValue && isArrayItem) {
1346+
process_hasName_emptyValue_arrayItem();
1347+
} else if (isEmptyValue && ! isArrayItem) {
1348+
process_hasName_emptyValue_noArrayItem();
13451349
} else {
13461350
logUnknownParseLine();
13471351
}
@@ -1354,33 +1358,36 @@ bool WsjcppYaml::parse(const std::string &sFileName, const std::string &sBuffer,
13541358

13551359
// ---------------------------------------------------------------------
13561360

1357-
void WsjcppYaml::process_sameIntent_hasName_emptyValue_arrayItem() {
1358-
WsjcppLog::warn(TAG, "process_sameIntent_hasName_emptyValue_arrayItem");
1361+
void WsjcppYaml::process_hasName_emptyValue_arrayItem() {
1362+
WsjcppLog::warn(TAG, "process_hasName_emptyValue_arrayItem");
13591363
this->logUnknownParseLine();
13601364
}
13611365

13621366
// ---------------------------------------------------------------------
13631367

1364-
void WsjcppYaml::process_sameIntent_hasName_emptyValue_noArrayItem() {
1365-
WsjcppYamlNode *pItem = new WsjcppYamlNode(
1368+
void WsjcppYaml::process_hasName_emptyValue_noArrayItem() {
1369+
WsjcppYamlNode *pNode = new WsjcppYamlNode(
13661370
m_pParseCurrentItem, m_parsePlaceInFile,
13671371
WSJCPP_YAML_NODE_UNDEFINED
13681372
);
13691373
if (m_parseLine.getValueQuotes() != WSJCPP_YAML_QUOTES_NONE) {
1370-
pItem->doValue();
1371-
pItem->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
1374+
pNode->doValue();
1375+
pNode->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
13721376
}
1373-
pItem->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
1374-
pItem->setComment(m_parseLine.getComment());
1375-
m_pParseCurrentItem->setElement(m_parseLine.getName(), pItem);
1376-
m_pParseCurrentItem = pItem;
13771377
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
1378+
pNode->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
1379+
pNode->setComment(m_parseLine.getComment());
1380+
pNode->setNodeDiffIntent(nDiffIntent);
1381+
// m_pParseCurrentItem->getParent()
1382+
std::cout << "process_hasName_emptyValue_noArrayItem " << m_parseLine.getName() << " " << nDiffIntent << std::endl;
1383+
m_pParseCurrentItem->setElement(m_parseLine.getName(), pNode);
1384+
m_pParseCurrentItem = pNode;
13781385
m_nParseCurrentIntent = m_nParseCurrentIntent + nDiffIntent;
13791386
}
13801387

13811388
// ---------------------------------------------------------------------
13821389

1383-
void WsjcppYaml::process_sameIntent_hasName_hasValue_arrayItem() {
1390+
void WsjcppYaml::process_hasName_hasValue_arrayItem() {
13841391
if (m_pParseCurrentItem->isUndefined()) {
13851392
m_pParseCurrentItem->doArray();
13861393
}
@@ -1393,38 +1400,40 @@ void WsjcppYaml::process_sameIntent_hasName_hasValue_arrayItem() {
13931400
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
13941401
m_nParseCurrentIntent = m_nParseCurrentIntent + nDiffIntent;
13951402

1396-
WsjcppYamlNode *pItem = new WsjcppYamlNode(
1403+
WsjcppYamlNode *pNode = new WsjcppYamlNode(
13971404
m_pParseCurrentItem, m_parsePlaceInFile,
13981405
WSJCPP_YAML_NODE_VALUE
13991406
);
1400-
pItem->setComment(m_parseLine.getComment());
1401-
pItem->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
1402-
pItem->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
1403-
pMapItem->setElement(m_parseLine.getName(), pItem);
1404-
m_pParseCurrentItem = pItem;
1407+
pNode->setComment(m_parseLine.getComment());
1408+
pNode->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
1409+
pNode->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
1410+
pMapItem->setElement(m_parseLine.getName(), pNode);
1411+
m_pParseCurrentItem = pNode;
14051412
nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
1413+
pNode->setNodeDiffIntent(nDiffIntent);
14061414
m_nParseCurrentIntent = m_nParseCurrentIntent + nDiffIntent;
14071415
}
14081416

14091417
// ---------------------------------------------------------------------
14101418

1411-
void WsjcppYaml::process_sameIntent_hasName_hasValue_noArrayItem() {
1419+
void WsjcppYaml::process_hasName_hasValue_noArrayItem() {
14121420
WsjcppYamlNode *pItem = new WsjcppYamlNode(
14131421
m_pParseCurrentItem, m_parsePlaceInFile,
14141422
WSJCPP_YAML_NODE_VALUE
14151423
);
1424+
std::cout << m_parseLine.getName() << std::endl;
14161425
pItem->setComment(m_parseLine.getComment());
14171426
pItem->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
14181427
pItem->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
14191428
m_pParseCurrentItem->setElement(m_parseLine.getName(), pItem);
1420-
m_pParseCurrentItem = pItem;
1429+
// m_pParseCurrentItem = pItem;
14211430
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
14221431
m_nParseCurrentIntent = m_nParseCurrentIntent + nDiffIntent;
14231432
}
14241433

14251434
// ---------------------------------------------------------------------
14261435

1427-
void WsjcppYaml::process_sameIntent_emptyName_hasValue_arrayItem() {
1436+
void WsjcppYaml::process_emptyName_hasValue_arrayItem() {
14281437
if (m_pParseCurrentItem->isUndefined()) {
14291438
m_pParseCurrentItem->doArray();
14301439
}
@@ -1442,38 +1451,41 @@ void WsjcppYaml::process_sameIntent_emptyName_hasValue_arrayItem() {
14421451

14431452
// ---------------------------------------------------------------------
14441453

1445-
void WsjcppYaml::process_sameIntent_emptyName_hasValue_noArrayItem() {
1446-
WsjcppLog::warn(TAG, "TODO process_sameIntent_emptyName_hasValue_noArrayItem");
1454+
void WsjcppYaml::process_emptyName_hasValue_noArrayItem() {
1455+
WsjcppLog::warn(TAG, "TODO process_emptyName_hasValue_noArrayItem");
14471456
this->logUnknownParseLine();
14481457

14491458
}
14501459

14511460
// ---------------------------------------------------------------------
14521461

1453-
void WsjcppYaml::process_sameIntent_emptyName_emptyValue_arrayItem() {
1462+
void WsjcppYaml::process_emptyName_emptyValue_arrayItem() {
14541463
if (m_pParseCurrentItem->isUndefined()) {
14551464
m_pParseCurrentItem->doArray();
14561465
}
1457-
WsjcppYamlNode *pItem = new WsjcppYamlNode(
1466+
WsjcppYamlNode *pNode = new WsjcppYamlNode(
14581467
m_pParseCurrentItem, m_parsePlaceInFile,
14591468
WSJCPP_YAML_NODE_VALUE
14601469
);
1461-
pItem->setComment(m_parseLine.getComment());
1462-
pItem->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
1463-
m_pParseCurrentItem->appendElement(pItem);
1464-
m_pParseCurrentItem = pItem;
1470+
pNode->setComment(m_parseLine.getComment());
1471+
pNode->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
1472+
m_pParseCurrentItem->appendElement(pNode);
1473+
m_pParseCurrentItem = pNode;
14651474
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
1475+
pNode->setNodeDiffIntent(nDiffIntent);
14661476
m_nParseCurrentIntent = m_nParseCurrentIntent + nDiffIntent;
14671477
}
14681478

14691479
// ---------------------------------------------------------------------
14701480

1471-
void WsjcppYaml::process_sameIntent_emptyName_emptyValue_noArrayItem() {
1481+
void WsjcppYaml::process_emptyName_emptyValue_noArrayItem() {
14721482
WsjcppYamlNode *pNode = new WsjcppYamlNode(
14731483
m_pParseCurrentItem, m_parsePlaceInFile,
14741484
WSJCPP_YAML_NODE_EMPTY
14751485
);
14761486
pNode->setComment(m_parseLine.getComment());
1487+
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
1488+
pNode->setNodeDiffIntent(nDiffIntent);
14771489
m_pParseCurrentItem->appendElement(pNode);
14781490
}
14791491

src/wsjcpp_yaml.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,14 @@ class WsjcppYaml {
261261
// TODO replace to WsjcppCore::split()
262262
std::vector<std::string> splitToLines(const std::string &sBuffer);
263263
bool parse(const std::string &sFileName, const std::string &sBuffer, std::string &sError);
264-
void process_sameIntent_hasName_emptyValue_arrayItem();
265-
void process_sameIntent_hasName_emptyValue_noArrayItem();
266-
void process_sameIntent_hasName_hasValue_arrayItem();
267-
void process_sameIntent_hasName_hasValue_noArrayItem();
268-
void process_sameIntent_emptyName_hasValue_arrayItem();
269-
void process_sameIntent_emptyName_hasValue_noArrayItem();
270-
void process_sameIntent_emptyName_emptyValue_arrayItem();
271-
void process_sameIntent_emptyName_emptyValue_noArrayItem();
272-
273-
264+
void process_hasName_emptyValue_arrayItem();
265+
void process_hasName_emptyValue_noArrayItem();
266+
void process_hasName_hasValue_arrayItem();
267+
void process_hasName_hasValue_noArrayItem();
268+
void process_emptyName_hasValue_arrayItem();
269+
void process_emptyName_hasValue_noArrayItem();
270+
void process_emptyName_emptyValue_arrayItem();
271+
void process_emptyName_emptyValue_noArrayItem();
274272

275273
std::vector<std::string> m_sLines;
276274
WsjcppYamlNode *m_pRoot;

0 commit comments

Comments
 (0)