summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/domain/unpackPqTextArray.ll
blob: e4b0ccdf576868ec914637b378ce501abb1a51da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
%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 [^,\"}]+
quote \"
esc \\.
char [^"]

%x FIRST
%x AFTER
%x NEXT
%x QUOTED

%%

{begin} {
	yy_push_state(FIRST);
}
<FIRST,AFTER>{end} {
	yy_pop_state();
}
<FIRST,NEXT>{unquoted} {
	list.push_back(YYText());
	BEGIN(AFTER);
}
<FIRST,NEXT>{quote} {
	list.push_back(std::string());
	BEGIN(QUOTED);
}
<AFTER>{comma} {
	BEGIN(NEXT);
}
<QUOTED>{quote} {
	BEGIN(AFTER);
}
<QUOTED>{esc} {
	list.back().push_back(*(YYText() + 1));
}
<QUOTED>{char} {
	list.back().append(YYText());
}

%%

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);
		}
  }
}