- // The token matches with the delimiter of the argument.
- cursor.remove();
-
- // If the phantom group has just one child, it is not necessary
- // and can be removed. However, this would complicate
- // all the code that follows, so given it is a rare case we
- // leave it alone
- // if (parent.size() == 1) parent.replace(parent[0]);
-
- // Eat both the argument and its delimiter
- frame.pos += 2;
- if (frame.pos == frame.entry.pattern.size())
- {
- // This token has completed the entry
- advance(parent.parent());
- }
- else if (frame.entry.paramDelimited(frame.pos))
- {
- // For the next is a delimited argument we have to place
- // a suitable phantom group with the cursor inside
- TNode g = doc.createG();
- parent.parent().append(g);
- g.append(cursor);
- }
- else
- parent.parent().append(cursor);
+ // The entry pattern is not empty. By our conventions this means
+ // the entry cannot be open at either end, hence we are parsing
+ // a delimited argument
+ assert(frame.pos + 1 < frame.entry.pattern.size());
+ assert(frame.entry.pattern[frame.pos + 1].category != TToken::PARAMETER);
+ if (frame.entry.pattern[frame.pos + 1] == token)
+ {
+ // The token matches with a delimiter of the argument,
+ // so we increment the frame.pos
+ frame.pos++;
+
+ if (frame.entry.lastDelimiter(frame.pos))
+ {
+ // this delimiter is the last one for the argumet,
+ // so the argument is completed
+ cursor.remove();
+ frame.pos++;
+
+ if (frame.pos == frame.entry.pattern.size())
+ {
+ // This token has completed the entry
+ frames.pop();
+ advance(parent.parent());
+ }
+ else if (frame.entry.paramDelimited(frame.pos))
+ {
+ // For the next is a delimited argument we have to place
+ // a suitable phantom group with the cursor inside
+ TNode g = doc.createG();
+ parent.parent().append(g);
+ g.append(cursor);
+ }
+ else
+ parent.parent().append(cursor);
+ }
+ }
+ else
+ {
+ // Delimiter mismatch.
+ if (frame.entry.pattern[frame.pos].category != TToken::PARAMETER)
+ {
+ // in this case, there is a sequence of delimiters that delimitates
+ // the argument, and the user correctly inserted a portion of this
+ // sequence, but has inserted a wrong delimiter.
+ // Here, there are some possibilities:
+ // - ignore the token, and wait for the correct delimiter
+ // - ignore the token, wait for the correct delimiter and emit an error
+ // If we want to emit an error, we shlould implement a class, that handle
+ // the error.
+ // At the moment, the error is printed to screen
+ cout << "push: it's not the correct delimiter...you have to type " << frame.entry.pattern[frame.pos + 1].value << endl;
+ }
+ else
+ {
+ // in this case, the sequence of delimiters is composed of one
+ // delimiter. It means that we have to process the token
+ process(token);
+ }
+ }