Giter Club home page Giter Club logo

Comments (5)

g40 avatar g40 commented on June 14, 2024

A bit more info. There is something odd happening with https://github.com/yhirose/cpp-peglib/blob/master/peglib.h#L2368
The length of the string passed in 's' is 743. But strlen is coming up with 760 hence it fails as ret.len != n.
If I use parse_n(..) the parse succeeds. Hmm. String is ascii.

from cpp-peglib.

yhirose avatar yhirose commented on June 14, 2024

Hi Jerry,
Could you make make sure that the 's' is a really null terminated string?

Here is my test code. When I run the code, I successfully got the success message.

#include <peglib.h>
#include <iostream>

using namespace peg;
using namespace std;

auto syn = R"(
# a grammar to parse the GDB 'machine interface' (GDB/MI)
GDB_MI          <- (GDB_ELEMENT EOL)*
GDB_ELEMENT     <- (AT_STRING / NEG_STRING / OP_LIST)
AT_STRING       <- '@' STRING_LITERAL
NEG_STRING      <- '~' STRING_LITERAL
OP_LIST         <- OP_CHAR IDENTIFIER ',' (RESULT_LIST)*
OP_CHAR         <- ( '~' / '*' / '=' / '+' / '^')
RESULT_LIST     <- RESULT (COMMA RESULT)*
RESULT          <- (IDENTIFIER (ASSIGNMENT_OP/HASH_OP))? (STRING_LITERAL / LBRACE (RESULT_LIST)* RBRACE / LBRACK (RESULT_LIST)* RBRACK)
~ASSIGNMENT_OP  <- < '=' >
HASH_OP         <- < '#' >
LBRACE          <- < '{' >
RBRACE          <- < '}' >
LBRACK          <- < '[' >
RBRACK          <- < ']' >
~COMMA          <- < ',' >
# GDB/MI strings contain escape sequences. The <> ensures the token 
# content is captured in the STRING_LITERAL AST node
STRING_LITERAL  <- < '"' (('\\"' / '\\t' / '\\n') / (!["] .))* '"' > 
# GDB/MI identifiers can contain '-' as in -info-breakpoint
IDENTIFIER      <- < [_a-zA-Z] ([_A-Za-z0-9] / '-')* > 
# recognize but ignore end of line characters
~EOL            <- '\n'
# sent at the end of a sequence
~TERMINATOR     <- '(gdb)' 
# consume the following during parse. +1!
%whitespace     <-  [ \t\r]*
)";

auto src = R"(^done,address="0x4000bb28",load-size="116244",transfer-rate="41104",write-rate="369",BreakpointTable={nr_rows="1",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x40003e10",func="main",file="../cyfxbulklpauto.c",fullname="r:\\src\\cypress\\fx3\\usbbulkloopauto\\cyfxbulklpauto.c",line="702",thread-groups=["i1"],times="0",original-location="main"}]}
)";

int main(int argc, const char** argv)
{
    parser parser(syn);
    parser.enable_ast();

    shared_ptr<Ast> ast;
    if (parser.parse(src, ast)) {
        cout << "success" << endl;
        return 0;
    }

    cout << "syntax error..." << endl;
    return -1;
}

from cpp-peglib.

yhirose avatar yhirose commented on June 14, 2024

Hi Jerry,
How about this issue now? Is it resolved?

from cpp-peglib.

g40 avatar g40 commented on June 14, 2024

Hi Yuji, not sure./ Closing. Will re-open if this visits again.

from cpp-peglib.

yhirose avatar yhirose commented on June 14, 2024

Thanks for the reply!

from cpp-peglib.

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.