coal
or is there a benefit on having match as a object-dependent method instead of a static
Anonymous
have you considered using templates instead
PEGTL’s templates are complicated and they make for some slightly complicated grammar
coal
have you considered using templates instead
then you can declare your derived classes as: class Char : Rule<Char> { }
coal
yeah but i think you dont need to use new so much
coal
and it makes your code very vulnerable if you, for some reason, miss to delete something
coal
and it looks strange ngl
Anonymous
for example https://gist.github.com/1301240b1b43614ad44b505b53af44f3
coal
yeah looks like pegtl
coal
all implementations of peg i've seen look like that, the worst probably being LPEG
Anonymous
yea, it is just… disorganized and unclean it is difficult to tell if a rule has an action associated with it and it is difficult to tell what rule an action belongs to, and in which grammar it is being used also template strings are a macro mess plus paramater packing and other stuff i do not like due to complexity
Anonymous
the only thing i do like is it’s tracer (which i modified to include additional information such as source line and location carrot, which has been merged into PEGTL) success #52 tao::pegtl::at<GLSL_PREPROCESSOR::function_end> position GLSL preprocessor function expansion:1:4 source Y(z) ^ success #51 tao::pegtl::until<tao::pegtl::at<GLSL_PREPROCESSOR::function_end>, GLSL_PREPROCESSOR::function_call_arg_and_optional_comma> #54 GLSL_PREPROCESSOR::function_end apply argument count: 1 required argument count: 1 expanding function body with function parameters and defines position GLSL preprocessor macro expansion:1:1 source a y ^ #1 GLSL_PREPROCESSOR::grammar___ #2 tao::pegtl::plus<tao::pegtl::sor<GLSL_PREPROCESSOR::whitespaces, GLSL_PREPROCESSOR::function_call, GLSL_PREPROCESSOR::identifier, tao::pegtl::ascii::any>> #3 tao::pegtl::sor<GLSL_PREPROCESSOR::whitespaces, GLSL_PREPROCESSOR::function_call, GLSL_PREPROCESSOR::identifier, tao::pegtl::ascii::any> #4 GLSL_PREPROCESSOR::whitespaces #5 GLSL_PREPROCESSOR::spaces failure #6 GLSL_PREPROCESSOR::tabs failure failure #4 GLSL_PREPROCESSOR::whitespaces #7 GLSL_PREPROCESSOR::function_call #8 GLSL_PREPROCESSOR::function_call_actual #9 GLSL_PREPROCESSOR::function_name #10 tao::pegtl::ascii::identifier_first success position GLSL preprocessor macro expansion:1:2 source a y ^ #11 tao::pegtl::opt<tao::pegtl::skip<tao::pegtl::ascii::identifier_other> > #12 tao::pegtl::skip<tao::pegtl::ascii::identifier_other> failure success #11 tao::pegtl::opt<tao::pegtl::skip<tao::pegtl::ascii::identifier_other> > success #9 GLSL_PREPROCESSOR::function_name #13 tao::pegtl::opt<GLSL_PREPROCESSOR::whitespaces_or_newlines> #14 GLSL_PREPROCESSOR::whitespaces_or_newlines #15 GLSL_PREPROCESSOR::spaces success position GLSL preprocessor macro expansion:1:3 source a y ^
Anonymous
rule names can be a long tho due to the template thing, such as tao::pegtl::opt<tao::pegtl::skip<tao::pegtl::ascii::identifier_other> > or tao::pegtl::plus<tao::pegtl::sor<GLSL_PREPROCESSOR::whitespaces, GLSL_PREPROCESSOR::function_call, GLSL_PREPROCESSOR::identifier, tao::pegtl::ascii::any>>
Anonymous
but it makes for an excellent Grammar debugger
coal
that's a very cool feature
coal
the one i mentioned earlier, LPEG
coal
i literally can't find any good point to use it, it's just a mess
coal
i literally can't find any good point to use it, it's just a mess
https://github.com/leafo/moonscript/blob/master/moonscript/parse/literals.lua
coal
local White = S(" \t\r\n") ^ 0 local plain_space = S(" \t") ^ 0 local Break = P("\r") ^ -1 * P("\n") local Stop = Break + -1 local Comment = P("--") * (1 - S("\r\n")) ^ 0 * L(Stop) local Space = plain_space * Comment ^ -1 local SomeSpace = S(" \t") ^ 1 * Comment ^ -1 local SpaceBreak = Space * Break local EmptyLine = SpaceBreak local AlphaNum = R("az", "AZ", "09", "__") local Name = C(R("az", "AZ", "__") * AlphaNum ^ 0) local Num = P("0x") * R("09", "af", "AF") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) ^ -1 + R("09") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) + (R("09") ^ 1 * (P(".") * R("09") ^ 1) ^ -1 + P(".") * R("09") ^ 1) * (S("eE") * P("-") ^ -1 * R("09") ^ 1) ^ -1 local Shebang = P("#!") * P(1 - Stop) ^ 0
Anonymous
in comparison to, for example, an LLDB backtrace which is difficult to read more difficult to determine which rule you are currrently in where you are in your grammar and how you got there frame #7: 0x0000000100032e62 main`CPP::Rules::Sequence::match(this=0x0000608000001320, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:866:31 frame #8: 0x0000000100022430 main`CPP::Rules::RuleHolder::match(this=0x0000616000000d20, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:531:31 frame #9: 0x0000000100020467 main`CPP::Rules::Or::match(this=0x0000608000001420, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:815:34 frame #10: 0x0000000100022430 main`CPP::Rules::RuleHolder::match(this=0x000060e000001c90, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:531:31 frame #11: 0x0000000100020467 main`CPP::Rules::Or::match(this=0x00006080000014a0, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:815:34 frame #12: 0x000000010002af07 main`CPP::Rules::OneOrMore::match(this=0x00007ffeefbfdf20, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:730:64 frame #13: 0x000000010000a5b2 main`CPP::Rules::Rule::match(this=0x00007ffeefbfdf20, string="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n", doAction=true) at Rules.h:276:24 frame #14: 0x000000010003ecc6 main`CPP::CPP::preprocess(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n", data=0x00007ffeefbff540) at CPP.h:523:21 frame #15: 0x000000010000a063 main`CPP::CPP::preprocess(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n") at CPP.h:52:13 frame #16: 0x000000010000568a main`CPP::CPP::parse(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n") at CPP.h:535:13 frame #17: 0x000000010000546f main`main at main.cpp:95:9
coal
it tries to act like a metalanguage would do
coal
it attempts to look like EBNF would, but it simply looks horrible
coal
it's like a sodomized yacc grammar
Anonymous
yea
coal
a lua implementation of PEG
coal
haha
doesnt it look beautiful
Anonymous
nope
coal
thanks for your honesty
Anonymous
kinda hurts my eyes lol
Anonymous
eg TEST(Rules, at_test_pass) { std::string a = "Hello World!"; CPP::Iterator<std::string> b(a); EXPECT_TRUE(CPP::Rules::At(new CPP::Rules::Char('H')).match(b)); EXPECT_EQ(b.currentPosition(), 0); EXPECT_EQ(b.peekNext(), 'H'); } At automatically deletes Char when it gets destructed
coal
kinda hurts my eyes lol
it hurts everyone's eyes
coal
fair
coal
yeah most likely
coal
does it recursively delete other members of itself as well
coal
for example, pointer class members
Anonymous
this is the rule holder https://gist.github.com/b414100f82dec3345c35259b4dcc44b5
Anonymous
it does not touch anything inside the Rule
coal
so, if you delete a Rule object that has a pointer member of another pointer instantiated with new
Anonymous
also if a RuleHolder contains another RuleHolder then yes it will “delete itself recursively"
coal
then the other pointer member becomes stranded and you have a memory leak
Anonymous
eg { RuleHolder( // deleted when this goes out of scope new RuleHolder( // deleted by above rule holder new RuleHolder( // deleted by above rule holder new Any() // deleted by above rule holder ) ) ) // Any is still alive } // Any does not exist anymore
coal
that explains it lol, very nice work
Anonymous
also Rule * r; { r = new RuleHolder( // deleted when r is deleted new RuleHolder( // deleted by above rule holder new RuleHolder( // deleted by above rule holder new Any() // deleted by above rule holder ) ) ) // Any is still alive } // Any is still alive delete r; // Any does not exist anymore
Anonymous
with all these nested allocations, how do you deal with exceptions and allocation failures?
exceptions simply call abort(); (they do not throw) and allocation failure is not yet implemented (as the grammar should not take up much space even if it is very complex, so it would probably take A LOT to yeild a BAD_ALLOC from allocating millions of rules for whatever reason ( who even needs a million rules lol ))
Anonymous
if an Action throws however, then it is up to the user to catch this try { grammar_that_throws.match(wrong_input); } catch // … or my_action = [] (auto input) { try { function_that_throws(); } catch // …
olli
exceptions simply call abort(); (they do not throw) and allocation failure is not yet implemented (as the grammar should not take up much space even if it is very complex, so it would probably take A LOT to yeild a BAD_ALLOC from allocating millions of rules for whatever reason ( who even needs a million rules lol ))
while it might not take up a lot of space, dynamic allocation can always fail. There might be system or process constraints and limitations in place which _could_ be pretty low. The thing is, if an allocation fails / throws you end up leaking memory which is not ideal.
Anonymous
lmao
Anonymous
auto preprocessor_directive = new Rules::Sequence({ new Rules::Sequence({ new Rules::Char('#'), optional_whitespaces, new Rules::Or({ define }) }, [&data](Rules::Input in) { XOut << getTag(data) << ' ' << "erasing preprocessor statement: " << in.quotedStringRemoveCharactersFromEnd(1) << std::endl; in.eraseAndRescan(); }), reset_preprocessor_state });
coal
fair
Chriss
Any C language expert here? Who can solve a problem? Find the sum of factorial of prime number upto N. If you can do this in C, I have gift for you.
Chriss
Any C language expert here? Who can solve a problem? Find the sum of factorial of prime number upto N. Solve the following equation: 2! +3! +5! +7! + 11! +13! + ……… +n! Here, n is a prime number. n is to be taken input through keyboard. If you can do this in C, I have gift for you.
Chriss
Please help me to fix this
coal
and where's the gift
coal
lol
Chriss
and where's the gift
Hello. Code is not working
Chriss
Check inbox
Abhanif
Done
Kadude
Pleasure
Clash
#include <iostream> #include <vector> using namespace std; int main() { vector<int> myvector{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (auto i = myvector.begin(); i != myvector.end(); ++i) { if (*i % 2 == 0) { myvector.erase(i); i--; } } for (auto it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; } why this time complexity is O(n^2) ?