summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/service/unpackPqTextArray.ll
diff options
context:
space:
mode:
Diffstat (limited to 'gentoobrowse-api/service/unpackPqTextArray.ll')
-rw-r--r--gentoobrowse-api/service/unpackPqTextArray.ll64
1 files changed, 64 insertions, 0 deletions
diff --git a/gentoobrowse-api/service/unpackPqTextArray.ll b/gentoobrowse-api/service/unpackPqTextArray.ll
new file mode 100644
index 0000000..6281063
--- /dev/null
+++ b/gentoobrowse-api/service/unpackPqTextArray.ll
@@ -0,0 +1,64 @@
+%option batch
+%option c++
+%option noyywrap
+%option 8bit
+%option stack
+%option yylineno
+%option yyclass="Portage::Utils::UnpackPqTextArray"
+%option prefix="pqBase"
+
+%{
+#include "unpackPqTextArray.h"
+#include <boost/algorithm/string/trim.hpp>
+#pragma GCC diagnostic ignored "-Wsign-compare"
+%}
+
+begin "{"
+end "}"
+comma ,
+unquoted [^,\"}]+
+quoted (\"[^\"]+\")
+
+%x FIRST
+%x AFTER
+%x NEXT
+
+%%
+
+{begin} {
+ yy_push_state(FIRST);
+}
+<FIRST,AFTER>{end} {
+ yy_pop_state();
+}
+<FIRST,NEXT>{unquoted} {
+ list.push_back(YYText());
+ BEGIN(AFTER);
+}
+<FIRST,NEXT>{quoted} {
+ list.push_back(YYText());
+ boost::algorithm::trim_if(list.back(), [](auto c){ return c == '"'; });
+ BEGIN(AFTER);
+}
+<AFTER>{comma} {
+ BEGIN(NEXT);
+}
+
+%%
+
+namespace Portage {
+ namespace Utils {
+ UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) :
+ yyFlexLexer(&f, NULL),
+ list(sl)
+ {
+ }
+
+ void
+ UnpackPqTextArray::LexerError(const char * msg)
+ {
+ throw std::runtime_error(msg);
+ }
+ }
+}
+