Ignore:
Timestamp:
Dec 19, 2017, 12:17:52 PM (13 months ago)
Author:
cameron
Message:

Further parser bug fixes and restructuring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_parser_ere.cpp

    r5787 r5789  
    2727}
    2828
    29 // A parenthesized group.  Input precondition: the opening ( has been consumed
     29// A parenthesized capture group.  Input precondition: the opening ( has been consumed
    3030RE * RE_Parser_ERE::parse_group() {
    31     // Capturing paren group.
    3231    mGroupsOpen++;
    33     RE * captured = parse_alt();
    34     mCaptureGroupCount++;
    35     std::string captureName = "\\" + std::to_string(mCaptureGroupCount);
    36     Name * const capture  = mMemoizer.memoize(makeCapture(captureName, captured));
    37     auto key = std::make_pair("", captureName);
    38     mNameMap.insert(std::make_pair(std::move(key), capture));
    39     if (!accept(')')) ParseFailure("Closing parenthesis required.");
     32    RE * captured = parse_capture_body();
     33    require(')');
    4034    mGroupsOpen--;
    41     return capture;
     35    return captured;
    4236}
    4337
     
    4943    if (accept('<')) return makeWordBegin();
    5044    if (accept('>')) return makeWordEnd();
    51     if (isdigit(*mCursor)) {
    52         mCursor++;
    53         std::string backref = std::string(mCursor.pos()-2, mCursor.pos());
    54         auto key = std::make_pair("", backref);
    55         auto f = mNameMap.find(key);
    56         if (f != mNameMap.end()) {
    57             return makeReference(backref, f->second);
    58         }
    59         else {
    60             ParseFailure("Back reference " + backref + " without prior capture group.");
    61         }
    62     }
     45    if (isdigit(*mCursor)) return parse_back_reference();
    6346    else {
    6447        return createCC(parse_literal_codepoint());
     
    7053// Items represent individual characters or sets of characters.
    7154// Ranges may be formed by individual character items separated by '-'.
     55// Note that there are no backslash escapes for ERE or BRE bracket expressions.
    7256RE * RE_Parser_ERE::parse_bracket_expr () {
    7357    bool negated = accept('^');
     
    8468    } while (mCursor.more() && !at(']'));
    8569    RE * t = makeAlt(items.begin(), items.end());
    86     if (!accept(']')) ParseFailure("Expecting ]");
     70    require(']');
    8771    if (negated) return makeComplement(t);
    8872    else return t;
Note: See TracChangeset for help on using the changeset viewer.