YSTest: Configuration.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Configuration.cpp
浏览该文件的文档.
1 /*
2 © 2012-2016, 2020 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 #include "NPL/YModules.h"
29 #include YFM_NPL_Configuration
30 #include YFM_NPL_SContext
31
32 using namespace YSLib;
33
34 namespace NPL
35 {
36
37 std::ostream&
38 operator<<(std::ostream& os, const Configuration& conf)
39 {
40 PrintNode(os, conf.GetRoot(), LiteralizeEscapeNodeLiteral);
41 return os;
42 }
43
44 std::istream&
45 operator>>(std::istream& is, Configuration& conf)
46 {
47 using sb_it_t = std::istreambuf_iterator<char>;
48 // TODO: Validate for S-expression?
49 // TODO: Use allocator?
50 Session sess{};
51
52 TryExpr(conf.root = A1::LoadNode(
53 SContext::Analyze(sess, sess.Process(sb_it_t(is), sb_it_t{}))))
54 CatchExpr(..., ystdex::rethrow_badstate(is, std::ios_base::failbit))
55 return is;
56 }
57
58 } // namespace NPL;
59
ystdex::rethrow_badstate
void rethrow_badstate(std::basic_ios< _tChar, _tTraits > &ios, std::ios_base::iostate state=std::ios_base::badbit)
设置流状态并重新抛出当前异常。
Definition: ios.hpp:64
NPL::Configuration::root
ValueNode root
Definition: NPL/Configuration.h:67
NPL::operator<<
std::ostream & operator<<(std::ostream &os, const Configuration &conf)
Definition: Configuration.cpp:38
YModules.h
NPL 库模块配置文件。
NPL::Configuration
设置：使用 S 表达式存储外部状态。
Definition: NPL/Configuration.h:65
NPL
Definition: NPL/Configuration.h:35
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
NPL::Session
会话：分析组成 NPL 基本翻译单元的源代码。
Definition: SContext.h:797
NPL::LiteralizeEscapeNodeLiteral
YB_ATTR_nodiscard YF_API YB_PURE string LiteralizeEscapeNodeLiteral(const ValueNode &)
转义 NPLA 节点字面量。
Definition: NPLA.cpp:70
NPL::A1::LoadNode
YB_ATTR_nodiscard ValueNode LoadNode(_type &&tree, _tParams &&... args)
加载 NPLA1 翻译单元。
Definition: NPL/Configuration.h:48
NPL::PrintNode
YF_API void PrintNode(std::ostream &, const ValueNode &, NodeToString=EscapeNodeLiteral, IndentGenerator=DefaultGenerateIndent, size_t=0)
打印 NPLA 节点。
Definition: NPLA.cpp:96
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
NPL::SContext::Analyze
void Analyze(TermNode &root, const _tParseResult &parse_result)
分析指定源，取抽象语法树储存至指定值类型节点。
Definition: SContext.h:1127
NPL::operator>>
std::istream & operator>>(std::istream &is, Configuration &conf)
Definition: Configuration.cpp:45