Created
December 20, 2018 13:21
-
-
Save aiya000/4e7601d03623a079e3c8632eb13c5b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/xpressive/xpressive.hpp> | |
// --regex-kotlin=/^[ \t]*(private|protected|public)?[ \t]*((abstract|final|sealed)[ \t]*)*(data[ \t]*)?class[ \t]+([a-zA-Z0-9_]+)/\8/c,class/ | |
namespace xp = boost::xpressive; | |
int main() { | |
// 基本コンビネーター | |
xp::sregex empty = xp::sregex::compile(""); | |
xp::sregex blank = *xp::space; | |
// Converts a string to xp::sregex | |
auto let = [empty](std::string x){ | |
return x >> empty; | |
}; | |
// 目的たち | |
xp::sregex visibility = | |
(let("private") | "protected" | "public") | |
>> blank | |
; | |
xp::sregex kind = | |
(let("abstract") | "final" | "sealed") | |
>> blank | |
; | |
xp::sregex class_ = | |
blank | |
>> !visibility | |
>> !kind | |
>> !let("data") >> blank | |
>> "class" >> blank | |
>> (xp::s1 = *(xp::alnum | '_')) | |
>> *xp::_ | |
; | |
// Go!! | |
xp::smatch what; | |
std::string x = "public data class You(val me: String)"; | |
std::string y = "sealed class Product {}"; | |
if (xp::regex_match(x, what, class_)) { | |
std::cout << what[0] << '\n'; | |
} | |
if (xp::regex_match(y, what, class_)) { | |
std::cout << what[0] << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment