2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
5 #ifndef PACKAGE_INFO_PARSER_H
6 #define PACKAGE_INFO_PARSER_H
9 #include <package/PackageInfo.h>
12 namespace BPackageKit
{
16 * Parses a ".PackageInfo" file and fills a BPackageInfo object with the
17 * package info elements found.
19 class BPackageInfo::Parser
{
21 Parser(ParseErrorListener
* listener
= NULL
);
23 status_t
Parse(const BString
& packageInfoString
,
24 BPackageInfo
* packageInfo
);
26 status_t
ParseVersion(const BString
& versionString
,
27 bool revisionIsOptional
,
28 BPackageVersion
& _version
);
29 status_t
ParseResolvableExpression(
30 const BString
& expressionString
,
31 BPackageResolvableExpression
& _expression
);
36 struct ListElementParser
;
37 friend struct ListElementParser
;
41 TOKEN_OPERATOR_ASSIGN
,
43 TOKEN_OPERATOR_LESS_EQUAL
,
45 TOKEN_OPERATOR_NOT_EQUAL
,
46 TOKEN_OPERATOR_GREATER_EQUAL
,
47 TOKEN_OPERATOR_GREATER
,
57 void _RewindTo(const Token
& token
);
59 void _ParseStringValue(BString
* value
,
60 const char** _tokenPos
= NULL
);
62 void _ParseArchitectureValue(
63 BPackageArchitecture
* value
);
64 void _ParseVersionValue(BPackageVersion
* value
,
65 bool revisionIsOptional
);
66 static void _ParseVersionValue(Token
& word
,
67 BPackageVersion
* value
,
68 bool revisionIsOptional
);
69 void _ParseResolvableExpression(
71 BPackageResolvableExpression
& _value
,
72 BString
* _basePackage
);
73 void _ParseList(ListElementParser
& elementParser
,
74 bool allowSingleNonListElement
);
75 void _ParseStringList(BStringList
* value
,
76 bool requireResolvableName
= false,
77 bool convertToLowerCase
= false);
78 void _ParseResolvableList(
79 BObjectList
<BPackageResolvable
>* value
);
80 void _ParseResolvableExprList(
81 BObjectList
<BPackageResolvableExpression
>*
83 BString
* _basePackage
= NULL
);
84 void _ParseGlobalWritableFileInfos(
85 GlobalWritableFileInfoList
* infos
);
86 void _ParseUserSettingsFileInfos(
87 UserSettingsFileInfoList
* infos
);
88 void _ParseUsers(UserList
* users
);
90 void _Parse(BPackageInfo
* packageInfo
);
92 static bool _IsAlphaNumUnderscore(const BString
& string
,
93 const char* additionalChars
,
95 static bool _IsAlphaNumUnderscore(const char* string
,
96 const char* additionalChars
,
98 static bool _IsAlphaNumUnderscore(const char* start
,
100 const char* additionalChars
,
102 static bool _IsValidResolvableName(const char* string
,
106 ParseErrorListener
* fListener
;
111 struct BPackageInfo::Parser::ParseError
{
115 ParseError(const BString
& _message
, const char* _pos
)
116 : message(_message
), pos(_pos
)
122 struct BPackageInfo::Parser::Token
{
127 Token(TokenType _type
, const char* _pos
, int length
= 0,
128 const char* text
= NULL
)
135 else if (length
!= 0)
136 this->text
.SetTo(pos
, length
);
139 operator bool() const
141 return type
!= TOKEN_EOF
;
146 struct BPackageInfo::Parser::ListElementParser
{
147 virtual ~ListElementParser()
151 virtual void operator()(const Token
& token
) = 0;
155 } // namespace BPackageKit
158 #endif // PACKAGE_INFO_PARSER_H