YSTest: SContext.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

SContext.h
浏览该文件的文档.
1 /*
2 © 2012-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef NPL_INC_SContext_h_
29 #define NPL_INC_SContext_h_ 1
30
31 #include "YModules.h"
32 #include YFM_NPL_Lexical
33 #include YFM_YSLib_Core_ValueNode
34
35 namespace NPL
36 {
37
39 using YSLib::ValueObject;
41 using YSLib::ValueNode;
42 using TokenList = list<string>;
43 using TLIter = TokenList::iterator;
44 using TLCIter = TokenList::const_iterator;
46
47 using YSLib::observer_ptr;
48 using YSLib::LoggedEvent;
49
51 using TermNode = ValueNode;
52
53 using TNIter = TermNode::iterator;
54 using TNCIter = TermNode::const_iterator;
55
56 inline PDefH(TermNode&, MapToTermNode, TermNode& term)
57 ImplRet(term)
58 inline PDefH(const TermNode&, MapToTermNode, const TermNode& term)
59 ImplRet(term)
60
61 inline PDefH(ValueNode&, MapToValueNode, ValueNode& node)
62 ImplRet(node)
63 inline PDefH(const ValueNode&, MapToValueNode, const ValueNode& node)
64 ImplRet(node)
66
67
72 inline PDefH(bool, HasValue, const TermNode& term, const ValueObject& vo)
73 ImplRet(term.Value == vo)
74
75
80 class YF_API Session
81 {
82 public:
84
85 using CharParser = std::function<void(LexicalAnalyzer&, char)>;
86
88 LexicalAnalyzer Lexer;
89
91 DefDeCtor(Session)
93 template<typename _tIn>
94 Session(_tIn first, _tIn last, CharParser parse = DefaultParseByte)
95 : Lexer()
96 {
97 std::for_each(first, last,
98 std::bind(parse, std::ref(Lexer), std::placeholders::_1));
99 }
100 template<typename _tRange,
101 yimpl(typename = ystdex::exclude_self_t<Session, _tRange>)>
102 Session(const _tRange& c, CharParser parse = DefaultParseByte)
103 : Session(begin(c), end(c), parse)
104 {}
105 DefDeCopyMoveCtorAssignment(Session)
106
107 DefGetterMem(const ynothrow, const string&, Buffer, Lexer)
109 DefGetter(const, TokenList, TokenList, Tokenize(Lexer.Literalize()))
110
111
115 static void
116 DefaultParseByte(LexicalAnalyzer&, char);
117
122 static void
123 DefaultParseQuoted(LexicalAnalyzer&, char);
124 };
125
126
131 namespace SContext
132 {
133
143 YF_API TLCIter
144 Validate(TLCIter b, TLCIter e);
145
147
148
157 YF_API TLCIter
158 Reduce(TermNode& term, TLCIter b, TLCIter e);
159
160
166 YF_API void
167 Analyze(TermNode&, const TokenList&);
168 YF_API void
169 Analyze(TermNode&, const Session&);
171 YF_API void
172 Analyze(TermNode&, string_view);
174 template<typename _type>
176 TermNode
177 Analyze(const _type& arg)
178 {
179 TermNode root;
180
181 Analyze(root, arg);
182 return root;
183 }
185
186 } // namespace SContext;
187
188 } // namespace NPL;
189
190 #endif
191
NPL::term
const TermNode &term ValueNode &node const ValueNode &node const TermNode & term
Definition: SContext.h:72
ystdex::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:415
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
NPL::ImplRet
const TermNode &term ImplRet(term) inline PDefH(ValueNode &
YSLib::ValueNode::iterator
Container::iterator iterator
Definition: ValueNode.h:65
NPL::SContext::Validate
YF_API TLCIter Validate(TLCIter b, TLCIter e)
遍历记号列表，验证基本合法性：圆括号是否对应。
Definition: SContext.cpp:53
NPL::TLIter
TokenList::iterator TLIter
Definition: SContext.h:43
NPL::MapToValueNode
const TermNode &term MapToValueNode
Definition: SContext.h:61
DefDeCopyMoveCtorAssignment
#define DefDeCopyMoveCtorAssignment(_t)
Definition: YBaseMacro.h:201
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
NPL::TLCIter
TokenList::const_iterator TLCIter
Definition: SContext.h:44
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
YSLib::vo
vo
Definition: YApplication.h:196
NPL::Tokenize
YF_API list< string > Tokenize(const list< string > &)
记号化：提取字符串列表中的记号。
Definition: Lexical.cpp:403
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:156
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:246
ystdex::exclude_self_t
enable_if_t<!is_same< _tClass &, decay_t< _tParam > & >::value, _type > exclude_self_t
移除选择类类型的特定重载避免构造模板和复制/转移特殊成员函数冲突。
Definition: type_traits.hpp:708
CHRLib::c
c
Definition: CharacterProcessing.h:81
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:256
NPL::MapToTermNode
MapToTermNode
Definition: SContext.h:58
NPL::LexicalAnalyzer::Literalize
list< string > Literalize() const
根据中间结果取字符串列表。
Definition: Lexical.cpp:216
YSLib::ValueNode::const_iterator
Container::const_iterator const_iterator
Definition: ValueNode.h:67
YModules.h
NPL::TokenList
list< string > TokenList
Definition: SContext.h:42
NPL
Definition: NPL/Configuration.h:34
NPL::SContext::Analyze
YF_API void Analyze(TermNode &, const TokenList &)
分析指定源，取抽象语法树储存至指定值类型节点。
Definition: SContext.cpp:92
NPL::SContext::Reduce
YF_API TLCIter Reduce(TermNode &term, TLCIter b, TLCIter e)
遍历规约记号列表，取抽象语法树储存至指定值类型节点。
Definition: SContext.cpp:71
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:57
NPL::LexicalAnalyzer
词法分析器。
Definition: Lexical.h:145
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
NPL::PDefH
YF_API const char * PDefH(void, InstallFile, const string &dst, const string &src) ImplExpr(InstallFile(dst.c_str()
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:272
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
ystdex::transformed_iterator
变换迭代器。
Definition: iterator.hpp:216
ystdex::ref
lref< _type > ref(_type &t)
构造引用包装。
Definition: ref.hpp:120
NPL::HasValue
const TermNode &term ValueNode &node const ValueNode &node HasValue
Definition: SContext.h:72