diff options
| author | thegeorg <[email protected]> | 2025-07-28 23:26:41 +0300 |
|---|---|---|
| committer | thegeorg <[email protected]> | 2025-07-28 23:42:24 +0300 |
| commit | 2e3c965f3bac5a35f0ce39c7ae4e81bac879542f (patch) | |
| tree | 7de46185d4d1bc4b1808109d95f72b914fa4adce /library/cpp/regex/pire/inline | |
| parent | 48b676b29c3a9750b57dfb8c1c3c6aaa5e056a66 (diff) | |
library/cpp/pire: Tab to space
```
$ ya-subst '\t' ' '
$ ya-subst '\s+$' ''
```
commit_hash:402b2f02694cb6fae6bd903d31e429e1cc9a5d4b
Diffstat (limited to 'library/cpp/regex/pire/inline')
| -rw-r--r-- | library/cpp/regex/pire/inline/inline.l | 340 |
1 files changed, 170 insertions, 170 deletions
diff --git a/library/cpp/regex/pire/inline/inline.l b/library/cpp/regex/pire/inline/inline.l index a198ab9f978..72c1e32c6ab 100644 --- a/library/cpp/regex/pire/inline/inline.l +++ b/library/cpp/regex/pire/inline/inline.l @@ -47,27 +47,27 @@ static int isatty(int) { return 0; } class Die { public: - Die() { - Msg = filename.empty() ? "pire_inline" : (filename + ":" + ToString(line) + ":"); - } + Die() { + Msg = filename.empty() ? "pire_inline" : (filename + ":" + ToString(line) + ":"); + } - template<class T> - Die& operator << (const T& t) { - Msg += ToString(t); - return *this; - } + template<class T> + Die& operator << (const T& t) { + Msg += ToString(t); + return *this; + } - ~Die() { - fprintf(stderr, "%s\n", Msg.c_str()); - exit(1); - } + ~Die() { + fprintf(stderr, "%s\n", Msg.c_str()); + exit(1); + } private: - ystring Msg; + ystring Msg; }; Die DieHelper() { - return Die(); + return Die(); } void putChar(char c) { putc(c, yyout); } @@ -90,115 +90,115 @@ void eatComment(void (*action)(char)); <INITIAL>"PIRE_REGEXP"[:space:]*"(" { BEGIN(Regexp); args.clear(); args.push_back(ystring()); } <Regexp>"\""([^\"]|\\.)*"\"" { - ystring& s = args.back(); - const char* p; - for (p = yytext + 1; *p && p[1]; ++p) { - if (*p == '\\') { - ++p; - if (!*p) - Die() << "string ends with a backslash"; - else if (*p == '\'' || *p == '\"' || *p == '\\') - s.push_back(*p); - else if (*p == 'n') - s.push_back('\n'); - else if (*p == 't') - s.push_back('\t'); - else if (isdigit(*p)) { - const char* beg = p; - while (isdigit(*p)) - ++p; - s.push_back(strtol(ystring(beg, p).c_str(), 0, 8)); - } else if (*p == 'x') { - const char* beg = p; - while (isdigit(*p) || (*p > 'a' && *p <= 'f') || (*p > 'A' && *p < 'F')) - ++p; - s.push_back(strtol(ystring(beg, p).c_str(), 0, 16)); - } else - Die() << "unknown escape sequence (\\" << *p << ")"; - } else - s.push_back(*p); - } - if (!*p) - Die() << "string ends with a backslash"; + ystring& s = args.back(); + const char* p; + for (p = yytext + 1; *p && p[1]; ++p) { + if (*p == '\\') { + ++p; + if (!*p) + Die() << "string ends with a backslash"; + else if (*p == '\'' || *p == '\"' || *p == '\\') + s.push_back(*p); + else if (*p == 'n') + s.push_back('\n'); + else if (*p == 't') + s.push_back('\t'); + else if (isdigit(*p)) { + const char* beg = p; + while (isdigit(*p)) + ++p; + s.push_back(strtol(ystring(beg, p).c_str(), 0, 8)); + } else if (*p == 'x') { + const char* beg = p; + while (isdigit(*p) || (*p > 'a' && *p <= 'f') || (*p > 'A' && *p < 'F')) + ++p; + s.push_back(strtol(ystring(beg, p).c_str(), 0, 16)); + } else + Die() << "unknown escape sequence (\\" << *p << ")"; + } else + s.push_back(*p); + } + if (!*p) + Die() << "string ends with a backslash"; } <Regexp>[ \t] {} <Regexp>\n { ++line; } <Regexp>"," { args.push_back(ystring()); } <Regexp>")" { - if (args.size() & 1 || args.empty()) - Die() << "Usage: PIRE_REGEXP(\"regexp1\", \"flags1\" [, \"regexp2\", \"flags2\" [,...] ])"; - - bool first = true; - Pire::Scanner sc; - ystring pattern; - for (auto i = args.begin(), ie = args.end(); i != ie; i += 2) { - - Pire::Lexer lexer(i->c_str(), i->c_str() + i->size()); - bool surround = false; - bool greedy = false; - bool reverse = false; - for (const char* option = (i+1)->c_str(); *option; ++option) { - if (*option == 'i') - lexer.AddFeature(Pire::Features::CaseInsensitive()); - else if (*option == 'u') - lexer.SetEncoding(Pire::Encodings::Utf8()); - else if (*option == 's') - surround = true; - else if (*option == 'a') - lexer.AddFeature(Pire::Features::AndNotSupport()); - else if (*option == 'g') - greedy = true; - else if (*option == 'r') - reverse = true; - else - Die() << "unknown option " << *option << ""; - } - - Pire::Fsm fsm; - try { - fsm = lexer.Parse(); - } - catch (std::exception& e) { - Die() << "" << filename << ":" << line << ": " << e.what() << ""; - } - if (reverse) - fsm.Reverse(); - if (greedy && surround) - Die() << "greedy and surround options are incompatible"; - if (greedy) - fsm = ~fsm.Surrounded() + fsm; - else if (surround) - fsm.Surround(); - - Pire::Scanner tsc(fsm); - if (first) { - pattern = *i; - first = false; - tsc.Swap(sc); - } else { - sc = Pire::Scanner::Glue(sc, tsc); - pattern += " | "; - pattern += *i; - } - } - - BufferOutput buf; - AlignedOutput stream(&buf); - Save(&stream, sc); - - fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>(PIRE_LITERAL( // %s \n \"", pattern.c_str()); - size_t pos = 5; - for (auto i = buf.Buffer().Begin(), ie = buf.Buffer().End(); i != ie; ++i) { - pos += fprintf(yyout, "\\x%02X", static_cast<unsigned char>(*i)); - if (pos >= 78) { - fprintf(yyout, "\"\n \""); - pos = 5; - } - } - fprintf(yyout, "\"), %u)\n#line %d \"%s\"\n", - (unsigned int) buf.Buffer().Size(), line, filename.c_str()); - BEGIN(INITIAL); + if (args.size() & 1 || args.empty()) + Die() << "Usage: PIRE_REGEXP(\"regexp1\", \"flags1\" [, \"regexp2\", \"flags2\" [,...] ])"; + + bool first = true; + Pire::Scanner sc; + ystring pattern; + for (auto i = args.begin(), ie = args.end(); i != ie; i += 2) { + + Pire::Lexer lexer(i->c_str(), i->c_str() + i->size()); + bool surround = false; + bool greedy = false; + bool reverse = false; + for (const char* option = (i+1)->c_str(); *option; ++option) { + if (*option == 'i') + lexer.AddFeature(Pire::Features::CaseInsensitive()); + else if (*option == 'u') + lexer.SetEncoding(Pire::Encodings::Utf8()); + else if (*option == 's') + surround = true; + else if (*option == 'a') + lexer.AddFeature(Pire::Features::AndNotSupport()); + else if (*option == 'g') + greedy = true; + else if (*option == 'r') + reverse = true; + else + Die() << "unknown option " << *option << ""; + } + + Pire::Fsm fsm; + try { + fsm = lexer.Parse(); + } + catch (std::exception& e) { + Die() << "" << filename << ":" << line << ": " << e.what() << ""; + } + if (reverse) + fsm.Reverse(); + if (greedy && surround) + Die() << "greedy and surround options are incompatible"; + if (greedy) + fsm = ~fsm.Surrounded() + fsm; + else if (surround) + fsm.Surround(); + + Pire::Scanner tsc(fsm); + if (first) { + pattern = *i; + first = false; + tsc.Swap(sc); + } else { + sc = Pire::Scanner::Glue(sc, tsc); + pattern += " | "; + pattern += *i; + } + } + + BufferOutput buf; + AlignedOutput stream(&buf); + Save(&stream, sc); + + fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>(PIRE_LITERAL( // %s \n \"", pattern.c_str()); + size_t pos = 5; + for (auto i = buf.Buffer().Begin(), ie = buf.Buffer().End(); i != ie; ++i) { + pos += fprintf(yyout, "\\x%02X", static_cast<unsigned char>(*i)); + if (pos >= 78) { + fprintf(yyout, "\"\n \""); + pos = 5; + } + } + fprintf(yyout, "\"), %u)\n#line %d \"%s\"\n", + (unsigned int) buf.Buffer().Size(), line, filename.c_str()); + BEGIN(INITIAL); } <INITIAL>. { putc(*yytext, yyout); } @@ -209,26 +209,26 @@ void eatComment(void (*action)(char)); void eatComment(void (*action)(char)) { - int c; - action('/'); action('*'); - for (;;) { - while ((c = yyinput()) != EOF && c != '*') { - if (c == '\n') - ++line; - action(c); - } - if (c == '*') { - action(c); - while ((c = yyinput()) == '*') - action(c); - if (c == '/') { - action(c); - break; - } - } - if (c == EOF) - Die() << "EOF in comment"; - } + int c; + action('/'); action('*'); + for (;;) { + while ((c = yyinput()) != EOF && c != '*') { + if (c == '\n') + ++line; + action(c); + } + if (c == '*') { + action(c); + while ((c = yyinput()) == '*') + action(c); + if (c == '/') { + action(c); + break; + } + } + if (c == EOF) + Die() << "EOF in comment"; + } } int yywrap() { return 1; } @@ -236,37 +236,37 @@ int yywrap() { return 1; } int main(int argc, char** argv) { - // Suppress warnings - static_cast<void>(&yy_fatal_error); - static_cast<void>(&yyunput); - - - try { - const char* outfile = 0; - if (argc >= 3 && !strcmp(argv[1], "-o")) { - outfile = argv[2]; - argv += 2, argc -= 2; - } - if (argc == 2) - filename = ystring(argv[1]); - else if (argc > 2) - Die() << "usage: pire_inline [-o outfile] [infile]"; - - yyin = stdin, yyout = stdout; - if (outfile && (yyout = fopen(outfile, "w")) == NULL) - Die() << "cannot open file " << outfile << " for writing"; - if (!filename.empty()) { - if ((yyin = fopen(filename.c_str(), "r")) == NULL) - Die() << "cannot open file " << filename.c_str() << "\n"; - } else - filename = "(stdin)"; - - - yylex(); - return 0; - } - catch (std::exception& e) { - fprintf(stderr, "%s\n", e.what()); - return 1; - } + // Suppress warnings + static_cast<void>(&yy_fatal_error); + static_cast<void>(&yyunput); + + + try { + const char* outfile = 0; + if (argc >= 3 && !strcmp(argv[1], "-o")) { + outfile = argv[2]; + argv += 2, argc -= 2; + } + if (argc == 2) + filename = ystring(argv[1]); + else if (argc > 2) + Die() << "usage: pire_inline [-o outfile] [infile]"; + + yyin = stdin, yyout = stdout; + if (outfile && (yyout = fopen(outfile, "w")) == NULL) + Die() << "cannot open file " << outfile << " for writing"; + if (!filename.empty()) { + if ((yyin = fopen(filename.c_str(), "r")) == NULL) + Die() << "cannot open file " << filename.c_str() << "\n"; + } else + filename = "(stdin)"; + + + yylex(); + return 0; + } + catch (std::exception& e) { + fprintf(stderr, "%s\n", e.what()); + return 1; + } } |
