Giter Site home page Giter Site logo

Comments (2)

martinburchell avatar martinburchell commented on August 12, 2024

Yes I saw that too when running with Valgrind. I'd dismissed it as user error as it went away as soon as I'd re-fetched from the server.

from camcops.

RudolfCardinal avatar RudolfCardinal commented on August 12, 2024

It seems fine in the debugger. But under Memcheck, the regular expression is not being parsed consistently.

With a debugging insert:

void IdPolicy::tokenize(QString policy_text)
{
    m_valid = true;

    // Single line, whitespace trimmed, newlines/tabs etc. removed
    policy_text = policy_text.simplified();

    // QString::split() splits using the regex to match BOUNDARIES.
    // Our regex matches CONTENT, so we use QRegularExpression functions.
    // https://dangelog.wordpress.com/2012/04/07/qregularexpression/
    const QRegularExpression re(TOKENIZE_RE_STR);
    QRegularExpressionMatchIterator it = re.globalMatch(policy_text);
    QStringList words;
    while (it.hasNext()) {
        const QRegularExpressionMatch match = it.next();
        const QString word = match.captured(1);
        words << word;
    }
    // Debugging under memcheck:
    qWarning() << "... TOKENIZE_RE_STR = " << TOKENIZE_RE_STR;
    qWarning() << "... policy_text = " << policy_text;
    qWarning() << "... words = " << words;
    for (const QString& word : words) {
        const QString element = word.toLower();
        const int token = nameToToken(element);
        if (token == BAD_TOKEN) {
            reportSyntaxError(QString("unknown word: %1").arg(word));
            invalidate();
            return;
        }
        m_tokens.append(token);
    }
    // check syntax:
    AttributesType blank_attributes;
    for (const QString& name : s_name_to_token.keys()) {
        blank_attributes[name] = false;
    }
    if (idPolicyChunk(m_tokens, blank_attributes) == ChunkValue::SyntaxError) {
        invalidate();
    }
}

One run:

camcops[2314512]: 2024-06-26T15:55:17.828: warning: ../tablet_qt/lib/idpolicy.cpp(172): ... TOKENIZE_RE_STR =  "\\s*(\\w+|\\(|\\))"
camcops[2314512]: 2024-06-26T15:55:17.829: warning: ../tablet_qt/lib/idpolicy.cpp(173): ... policy_text =  "forename AND surname AND sex AND dob AND anyidnum"
camcops[2314512]: 2024-06-26T15:55:17.829: warning: ../tablet_qt/lib/idpolicy.cpp(174): ... words =  QList("AND", "surname", "AND", "sex", "AND", "dob", "AND", "anyidnum")
camcops[2314512]: 2024-06-26T15:55:17.831: warning: ../tablet_qt/lib/idpolicy.cpp(237): Syntax error in policy ("chunk can't start with AND/OR/')'"); policy text is: "forename AND surname AND sex AND dob AND anyidnum"

Another:

camcops[2315554]: 2024-06-26T15:56:26.417: warning: ../tablet_qt/lib/idpolicy.cpp(172): ... TOKENIZE_RE_STR =  "\\s*(\\w+|\\(|\\))"
camcops[2315554]: 2024-06-26T15:56:26.417: warning: ../tablet_qt/lib/idpolicy.cpp(173): ... policy_text =  "forename AND surname AND sex AND dob AND anyidnum"
camcops[2315554]: 2024-06-26T15:56:26.417: warning: ../tablet_qt/lib/idpolicy.cpp(174): ... words =  QList()
camcops[2315554]: 2024-06-26T15:56:26.420: warning: ../tablet_qt/lib/idpolicy.cpp(237): Syntax error in policy ("policy incomplete"); policy text is: "forename AND surname AND sex AND dob AND anyidnum"

??

from camcops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.