@@ -527,10 +527,9 @@ void ScriptParser::readOutputFormat() {
527527
528528void ScriptParser::readPhdrs () {
529529 expect (" {" );
530-
531- while (!errorCount () && !consume (" }" )) {
530+ while (auto tok = till (" }" )) {
532531 PhdrsCommand cmd;
533- cmd.name = next () ;
532+ cmd.name = tok ;
534533 cmd.type = readPhdrType ();
535534
536535 while (!errorCount () && !consume (" ;" )) {
@@ -626,15 +625,14 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
626625
627626void ScriptParser::readOverwriteSections () {
628627 expect (" {" );
629- while (! errorCount () && ! consume (" }" ))
630- script->overwriteSections .push_back (readOutputSectionDescription (next () ));
628+ while (auto tok = till (" }" ))
629+ script->overwriteSections .push_back (readOutputSectionDescription (tok ));
631630}
632631
633632void ScriptParser::readSections () {
634633 expect (" {" );
635634 SmallVector<SectionCommand *, 0 > v;
636- while (!errorCount () && !consume (" }" )) {
637- StringRef tok = next ();
635+ while (auto tok = till (" }" )) {
638636 if (tok == " OVERLAY" ) {
639637 for (SectionCommand *cmd : readOverlay ())
640638 v.push_back (cmd);
@@ -1005,8 +1003,7 @@ OutputDesc *ScriptParser::readOutputSectionDescription(StringRef outSec) {
10051003 osec->constraint = ConstraintKind::ReadWrite;
10061004 expect (" {" );
10071005
1008- while (!errorCount () && !consume (" }" )) {
1009- StringRef tok = next ();
1006+ while (auto tok = till (" }" )) {
10101007 if (tok == " ;" ) {
10111008 // Empty commands are allowed. Do nothing here.
10121009 } else if (SymbolAssignment *assign = readAssignment (tok)) {
@@ -1806,8 +1803,7 @@ Expr ScriptParser::readMemoryAssignment(StringRef s1, StringRef s2,
18061803// MEMORY { name [(attr)] : ORIGIN = origin, LENGTH = len ... }
18071804void ScriptParser::readMemory () {
18081805 expect (" {" );
1809- while (!errorCount () && !consume (" }" )) {
1810- StringRef tok = next ();
1806+ while (auto tok = till (" }" )) {
18111807 if (tok == " INCLUDE" ) {
18121808 readInclude ();
18131809 continue ;
0 commit comments