2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>
4 * Distributed under the terms of the MIT License.
6 #ifndef PACKAGE_INFO_PARSER_H
7 #define PACKAGE_INFO_PARSER_H
10 #include <package/PackageInfo.h>
13 namespace BPackageKit
{
17 * Parses a ".PackageInfo" file and fills a BPackageInfo object with the
18 * package info elements found.
20 class BPackageInfo::Parser
{
22 Parser(ParseErrorListener
* listener
= NULL
);
24 status_t
Parse(const BString
& packageInfoString
,
25 BPackageInfo
* packageInfo
);
27 status_t
ParseVersion(const BString
& versionString
,
28 bool revisionIsOptional
,
29 BPackageVersion
& _version
);
30 status_t
ParseResolvableExpression(
31 const BString
& expressionString
,
32 BPackageResolvableExpression
& _expression
);
35 struct UrlStringValidator
;
36 struct StringValidator
;
39 struct ListElementParser
;
40 friend struct ListElementParser
;
44 TOKEN_OPERATOR_ASSIGN
,
46 TOKEN_OPERATOR_LESS_EQUAL
,
48 TOKEN_OPERATOR_NOT_EQUAL
,
49 TOKEN_OPERATOR_GREATER_EQUAL
,
50 TOKEN_OPERATOR_GREATER
,
60 void _RewindTo(const Token
& token
);
62 void _ParseStringValue(BString
* value
,
63 const char** _tokenPos
= NULL
);
65 void _ParseArchitectureValue(
66 BPackageArchitecture
* value
);
67 void _ParseVersionValue(BPackageVersion
* value
,
68 bool revisionIsOptional
);
69 static void _ParseVersionValue(Token
& word
,
70 BPackageVersion
* value
,
71 bool revisionIsOptional
);
72 void _ParseResolvableExpression(
74 BPackageResolvableExpression
& _value
,
75 BString
* _basePackage
);
76 void _ParseList(ListElementParser
& elementParser
,
77 bool allowSingleNonListElement
);
78 void _ParseStringList(BStringList
* value
,
79 bool requireResolvableName
= false,
80 bool convertToLowerCase
= false,
81 StringValidator
* stringValidator
= NULL
);
82 void _ParseResolvableList(
83 BObjectList
<BPackageResolvable
>* value
);
84 void _ParseResolvableExprList(
85 BObjectList
<BPackageResolvableExpression
>*
87 BString
* _basePackage
= NULL
);
88 void _ParseGlobalWritableFileInfos(
89 GlobalWritableFileInfoList
* infos
);
90 void _ParseUserSettingsFileInfos(
91 UserSettingsFileInfoList
* infos
);
92 void _ParseUsers(UserList
* users
);
94 void _Parse(BPackageInfo
* packageInfo
);
96 static bool _IsAlphaNumUnderscore(const BString
& string
,
97 const char* additionalChars
,
99 static bool _IsAlphaNumUnderscore(const char* string
,
100 const char* additionalChars
,
102 static bool _IsAlphaNumUnderscore(const char* start
,
104 const char* additionalChars
,
106 static bool _IsValidResolvableName(const char* string
,
110 ParseErrorListener
* fListener
;
115 struct BPackageInfo::Parser::ParseError
{
119 ParseError(const BString
& _message
, const char* _pos
)
120 : message(_message
), pos(_pos
)
126 struct BPackageInfo::Parser::Token
{
131 Token(TokenType _type
, const char* _pos
, int length
= 0,
132 const char* text
= NULL
)
139 else if (length
!= 0)
140 this->text
.SetTo(pos
, length
);
143 operator bool() const
145 return type
!= TOKEN_EOF
;
150 struct BPackageInfo::Parser::ListElementParser
{
151 virtual ~ListElementParser()
155 virtual void operator()(const Token
& token
) = 0;
159 struct BPackageInfo::Parser::StringValidator
{
161 virtual void Validate(const BString
&string
, const char *pos
) = 0;
165 struct BPackageInfo::Parser::UrlStringValidator
166 : public BPackageInfo::Parser::StringValidator
{
168 virtual void Validate(const BString
&string
, const char* pos
);
172 } // namespace BPackageKit
175 #endif // PACKAGE_INFO_PARSER_H