Git Product home page Git Product logo

parserlib's People

Contributors

asmwarrior avatar axilmar avatar cflaviu avatar g40 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parserlib's Issues

A match id is always being a std::string?

Hi, when I read the home page:

const auto grammar = (-terminalSet('+', '-') >> terminalRange('0', '9')) == std::string("int");
std::string input = "123";
ParseContext<> pc(input);
const bool ok = grammar(pc);
for(const auto& match : pc.matches()) {
    if (match.id() == "int") {
	    const auto parsedString = match.content();
    	//process int
    }
}

There is a condintion check:

match.id() == "int"

So, here comes my question: A match id is always be a std::string?

Thanks.

BTW: I'm also interested in develop a similar PEG like parsers in C++, see some of my idea here:

joemalle/limn#10 (comment)

Add a license

I think this is looking great, but a license would be helpful to those who might want to use your code. :)

Question: How to use only syntax rules

Is it possible to create & use a grammar that will parse a vector of already parsed tokens? It means the lexical parsing of terminals is not necessary. Only syntax rules will be used, something like:

enum class token { aa, bb, cc};    
auto rule = token::aa >> token::bb >> -token::cc;
std::vector<token> tokens{token::aa, token:bb, token:cc};
auto ok = parse(tokens.cbegin(), tokens.cend(), rule);

homepage document improvement suggestion

First, in the last section: https://github.com/axilmar/parserlib#resuming-from-errors

I suggest adding a real input string, so that the "resume from errors" can be more clear.

Second, in the first section: https://github.com/axilmar/parserlib#introduction
Especially in the code:

extern Rule<> add;

const auto val = +terminalRange('0', '9');

const auto num = val
               | '(' >> add >> ')';

Rule<> mul = mul >> '*' >> num
           | mul >> '/' >> num
           | num;

Rule<> add = add >> '+' >> mul
           | add >> '-' >> mul
           | mul;

I think you need to explain why the extern Rule<> add;, maybe adding some link to https://github.com/axilmar/parserlib#non-left-recursion, because in the section, it said //forward declaration of recursive rule in the comments.

BTW: look at the above code, why mul don't need a forward declaration? Is it because the definition and the reference is in the same statement?

skip whitespace for different lexers

I think for some kinds of low level lexer, the white space should not be skipped. But when parsing the high level Token, we should skip the white space. That's why the boost spirit has a skipper object as the parser input.

Can you have such kind of options? Thanks.

Wrong processing two continuous terminal

I think the parserlib wrong process whitespaces between identifier and terminal. This is my rules:

#define JAVA_LETTER (range('a', 'z') | range('A', 'Z') | set("$_"))
#define JAVA_DIGIT range('0', '9')
#define JAVA_LETTER_OR_DIGIT (JAVA_LETTER | JAVA_DIGIT)
#define NEWLINE nl(expr("\r\n") | "\n\r" | '\n' | '\r')
#define EVERYTHING_TO(endChar) *(!expr(endChar) >> range(0, 255))

rule whitespace = *(NEWLINE | range(0, 32));
rule identifier = (JAVA_LETTER >> *JAVA_LETTER_OR_DIGIT);
//rule identifier = *JAVA_LETTER;
rule qualifiedName = identifier >> *('.' >> identifier);
rule annotationText = expr('(') >> EVERYTHING_TO(')') >> ')';
rule annotation = expr('@') >> qualifiedName >> annotationText;
rule packageDeclaration = *annotation >> "package" >> qualifiedName >> ';';
rule importDeclaration = expr("import") >> -expr("static") >> qualifiedName >> -expr(".*") >> ';';
rule classOrInterfaceModifier = expr("public") | "protected" | "private" | "static" | "abstract" | "final" | "strictfp";
rule templateBlockText = EVERYTHING_TO(set("<>"));
rule templateBlock = expr('<') >> templateBlockText >> -templateBlock >> '>';
rule classDeclaration = term("class") >> identifier /* -templateBlock >>*/ >> "extends" /* >> identifier >> "implements" >> identifier >> '{' >> '}'*/;
rule typeDeclaration = *classOrInterfaceModifier >> classDeclaration;
rule compilationUnit = /*packageDeclaration >> *importDeclaration >>*/ typeDeclaration;

but I cannot reach separation for "identifier" and "extends" word (rule classDeclaration). When I test the string "protected abstract static class ClassName extends", I obtain an error:

found 1 error:
    line 1, col 51:

This is my test code:

error_list errors;
RootCompilationUnit *root;
string str = "protected abstract static class ClassName extends \n";
input input(str.begin(), str.end());
parse(input, compilationUnit, whitespace, errors, root);

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.