Parsing a C++ function declaration with Perl 6 grammar
up vote
0
down vote
favorite
I wrote a Perl 6 grammar to parse a C++ function. My final goal would be to parse an entire header. The aim is not to correct C++ syntax errors, but to parse valid C++.
Do you have some advice or improvements?
#!/usr/bin/env perl6
grammar FUNCTION {
token TOP { [ <attr> s+ ]? <type> [ s* <type_mod> ]?
(s+) <fname> (s*) "("
(s*) [<parameter> [ "," (s*) <parameter> ]* ]? (s*)
')'(s*) ';'
}
token name { w+ }
token namespace { [ "::" ]? [ <name> "::" ]* }
token attr { <name> }
token type { <namespace>? <name> }
token type_mod { [ *|& ]+ }
token fname { <name> }
token variable { <name> }
token parameter { <type> [s* <type_mod> ]? s+ <variable> }
}
my $str = "const ::one::std::string ** ma1n( int&& i, two::std::string va1e_ );";
my $parsed = FUNCTION.parse($str);
say $parsed;
c++ parsing grammar perl6 lexer
add a comment |
up vote
0
down vote
favorite
I wrote a Perl 6 grammar to parse a C++ function. My final goal would be to parse an entire header. The aim is not to correct C++ syntax errors, but to parse valid C++.
Do you have some advice or improvements?
#!/usr/bin/env perl6
grammar FUNCTION {
token TOP { [ <attr> s+ ]? <type> [ s* <type_mod> ]?
(s+) <fname> (s*) "("
(s*) [<parameter> [ "," (s*) <parameter> ]* ]? (s*)
')'(s*) ';'
}
token name { w+ }
token namespace { [ "::" ]? [ <name> "::" ]* }
token attr { <name> }
token type { <namespace>? <name> }
token type_mod { [ *|& ]+ }
token fname { <name> }
token variable { <name> }
token parameter { <type> [s* <type_mod> ]? s+ <variable> }
}
my $str = "const ::one::std::string ** ma1n( int&& i, two::std::string va1e_ );";
my $parsed = FUNCTION.parse($str);
say $parsed;
c++ parsing grammar perl6 lexer
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wrote a Perl 6 grammar to parse a C++ function. My final goal would be to parse an entire header. The aim is not to correct C++ syntax errors, but to parse valid C++.
Do you have some advice or improvements?
#!/usr/bin/env perl6
grammar FUNCTION {
token TOP { [ <attr> s+ ]? <type> [ s* <type_mod> ]?
(s+) <fname> (s*) "("
(s*) [<parameter> [ "," (s*) <parameter> ]* ]? (s*)
')'(s*) ';'
}
token name { w+ }
token namespace { [ "::" ]? [ <name> "::" ]* }
token attr { <name> }
token type { <namespace>? <name> }
token type_mod { [ *|& ]+ }
token fname { <name> }
token variable { <name> }
token parameter { <type> [s* <type_mod> ]? s+ <variable> }
}
my $str = "const ::one::std::string ** ma1n( int&& i, two::std::string va1e_ );";
my $parsed = FUNCTION.parse($str);
say $parsed;
c++ parsing grammar perl6 lexer
I wrote a Perl 6 grammar to parse a C++ function. My final goal would be to parse an entire header. The aim is not to correct C++ syntax errors, but to parse valid C++.
Do you have some advice or improvements?
#!/usr/bin/env perl6
grammar FUNCTION {
token TOP { [ <attr> s+ ]? <type> [ s* <type_mod> ]?
(s+) <fname> (s*) "("
(s*) [<parameter> [ "," (s*) <parameter> ]* ]? (s*)
')'(s*) ';'
}
token name { w+ }
token namespace { [ "::" ]? [ <name> "::" ]* }
token attr { <name> }
token type { <namespace>? <name> }
token type_mod { [ *|& ]+ }
token fname { <name> }
token variable { <name> }
token parameter { <type> [s* <type_mod> ]? s+ <variable> }
}
my $str = "const ::one::std::string ** ma1n( int&& i, two::std::string va1e_ );";
my $parsed = FUNCTION.parse($str);
say $parsed;
c++ parsing grammar perl6 lexer
c++ parsing grammar perl6 lexer
edited 31 mins ago
Jamal♦
30.2k11115226
30.2k11115226
asked 8 hours ago
tejas
20116
20116
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I'd expect to see many more tests of any program that addresses a problem this gnarly.
Choosing a couple I've recently had cause to write (on Stack Overflow), I would immediately add
void (SENDER::*get_func())(double, double);
(from Passing pointers to member function as returned values to QObject::connect())
constexpr std::size_t len(const T(&)[length]);
(from Differentiate between Array and Pointer in function parameter)
Neither of these succeeded when I tried them.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I'd expect to see many more tests of any program that addresses a problem this gnarly.
Choosing a couple I've recently had cause to write (on Stack Overflow), I would immediately add
void (SENDER::*get_func())(double, double);
(from Passing pointers to member function as returned values to QObject::connect())
constexpr std::size_t len(const T(&)[length]);
(from Differentiate between Array and Pointer in function parameter)
Neither of these succeeded when I tried them.
add a comment |
up vote
1
down vote
I'd expect to see many more tests of any program that addresses a problem this gnarly.
Choosing a couple I've recently had cause to write (on Stack Overflow), I would immediately add
void (SENDER::*get_func())(double, double);
(from Passing pointers to member function as returned values to QObject::connect())
constexpr std::size_t len(const T(&)[length]);
(from Differentiate between Array and Pointer in function parameter)
Neither of these succeeded when I tried them.
add a comment |
up vote
1
down vote
up vote
1
down vote
I'd expect to see many more tests of any program that addresses a problem this gnarly.
Choosing a couple I've recently had cause to write (on Stack Overflow), I would immediately add
void (SENDER::*get_func())(double, double);
(from Passing pointers to member function as returned values to QObject::connect())
constexpr std::size_t len(const T(&)[length]);
(from Differentiate between Array and Pointer in function parameter)
Neither of these succeeded when I tried them.
I'd expect to see many more tests of any program that addresses a problem this gnarly.
Choosing a couple I've recently had cause to write (on Stack Overflow), I would immediately add
void (SENDER::*get_func())(double, double);
(from Passing pointers to member function as returned values to QObject::connect())
constexpr std::size_t len(const T(&)[length]);
(from Differentiate between Array and Pointer in function parameter)
Neither of these succeeded when I tried them.
answered 4 hours ago
Toby Speight
22.2k536108
22.2k536108
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208179%2fparsing-a-c-function-declaration-with-perl-6-grammar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown