forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributesParser.h
More file actions
executable file
·116 lines (90 loc) · 2.97 KB
/
AttributesParser.h
File metadata and controls
executable file
·116 lines (90 loc) · 2.97 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// AttributesParser.h
//
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/AttributesParser.h#2 $
//
// Library: CppParser
// Package: Attributes
// Module: AttributesParser
//
// Definition of the AttributesParser class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_AttributesParser_INCLUDED
#define CppParser_AttributesParser_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Tokenizer.h"
#include "Poco/CppParser/Attributes.h"
namespace Poco {
namespace CppParser {
class CppParser_API AttributesParser
/// A parser for POCO-style C++ attributes.
///
/// Using a special comment syntax, C++ declarations for
/// structs/classes, functions, types, etc. can be annotated
/// with attributes.
///
/// Attributes always come immediately before the symbol that
/// is being annotated, and are written inside special comments
/// with the syntax:
/// //@ <attrDecl>[,<attrDec>...]
/// where <attrDecl> is
/// <name>[=<value>]
/// <name> is a valid C++ identifier, or two identifiers separated by
/// a period (struct accessor notation).
/// <value> is a string, integer, identifier, bool literal, or a complex value
/// in the form
/// {<name>=<value>[,<name>=<value>...]}
{
public:
AttributesParser(Attributes& attrs, std::istream& istr);
/// Creates the AttributesParser.
~AttributesParser();
/// Destroys the AttributesParser.
void parse();
/// Parses attributes.
protected:
void setAttribute(const std::string& name, const std::string& value);
const Poco::Token* parseAttributes(const Poco::Token* pNext);
const Poco::Token* parseAttribute(const Poco::Token* pNext);
const Poco::Token* parseComplexAttribute(const Token* pNext, const std::string& id);
const Poco::Token* parseIdentifier(const Poco::Token* pNext, std::string& id);
const Poco::Token* next();
static bool isIdentifier(const Poco::Token* pToken);
static bool isOperator(const Poco::Token* pToken, int kind);
static bool isLiteral(const Poco::Token* pToken);
static bool isEOF(const Poco::Token* pToken);
private:
Attributes& _attrs;
Tokenizer _tokenizer;
std::string _id;
};
//
// inlines
//
inline const Poco::Token* AttributesParser::next()
{
return _tokenizer.next();
}
inline bool AttributesParser::isEOF(const Poco::Token* pToken)
{
return pToken->is(Token::EOF_TOKEN);
}
inline bool AttributesParser::isIdentifier(const Poco::Token* pToken)
{
return pToken->is(Poco::Token::IDENTIFIER_TOKEN) || pToken->is(Poco::Token::KEYWORD_TOKEN);
}
inline bool AttributesParser::isOperator(const Poco::Token* pToken, int kind)
{
return pToken->is(Poco::Token::OPERATOR_TOKEN) && pToken->asInteger() == kind;
}
inline bool AttributesParser::isLiteral(const Poco::Token* pToken)
{
return pToken->is(Poco::Token::STRING_LITERAL_TOKEN) || pToken->is(Poco::Token::INTEGER_LITERAL_TOKEN);
}
} } // namespace Poco::CppParser
#endif // CppParser_AttributesParser_INCLUDED