YSTest: NPLA.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

NPLA.h
浏览该文件的文档.
1 /*
2 © 2014-2017 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_NPLA_h_
29 #define NPL_INC_NPLA_h_ 1
30
31 #include "YModules.h"
32 #include YFM_NPL_SContext // for string, NPLTag, ValueNode, TermNode,
33 // LoggedEvent, ystdex::lref, ystdex::equality_comparable, shared_ptr,
34 // weak_ptr, ystdex::as_const;
35 #include <ystdex/base.h> // for ystdex::derived_entity;
36 #include YFM_YSLib_Core_YEvent // for YSLib::GHEvent, ystdex::fast_any_of,
37 // ystdex::indirect, YSLib::GEvent, YSLib::GCombinerInvoker,
38 // YSLib::GDefaultLastValueInvoker;
39 #include <ystdex/any.h> // for ystdex::any;
40
41 namespace NPL
42 {
43
51 using YSLib::MakeIndex;
54 using YSLib::NodeSequence;
56 using YSLib::NodeLiteral;
58
59 using YSLib::enable_shared_from_this;
60 using YSLib::make_shared;
61 using YSLib::make_weak;
62 using YSLib::observer_ptr;
64 using YSLib::pair;
66 using YSLib::to_string;
67 using YSLib::shared_ptr;
68 using YSLib::weak_ptr;
70
71
77 struct YF_API NPLATag : NPLTag
78 {};
79
80
88 template<class _tNodeOrCon, typename... _tParams>
89 ValueNode::iterator
90 InsertSyntaxNode(_tNodeOrCon&& node_or_con,
91 std::initializer_list<ValueNode> il, _tParams&&... args)
92 {
93 return node_or_con.emplace_hint(node_or_con.end(), ValueNode::Container(il),
94 MakeIndex(node_or_con), yforward(args)...);
95 }
96 template<class _tNodeOrCon, typename _type, typename... _tParams>
97 ValueNode::iterator
98 InsertSyntaxNode(_tNodeOrCon&& node_or_con, _type&& arg, _tParams&&... args)
99 {
100 return node_or_con.emplace_hint(node_or_con.end(), yforward(arg),
101 MakeIndex(node_or_con), yforward(args)...);
102 }
104
105
110 using NodeMapper = std::function<ValueNode(const TermNode&)>;
111
113
114 using NodeToString = std::function<string(const ValueNode&)>;
115
116 template<class _tCon>
117 using GNodeInserter = std::function<void(TermNode&&, _tCon&)>;
118
119 using NodeInserter = GNodeInserter<TermNode::Container&>;
120
121 using NodeSequenceInserter = GNodeInserter<NodeSequence>;
123
124
126
127
134 YF_API ValueNode
135 MapNPLALeafNode(const TermNode&);
136
142 YF_API ValueNode
143 TransformToSyntaxNode(const ValueNode&, const string& = {});
145
152 YF_API string
153 EscapeNodeLiteral(const ValueNode&);
154
162 YF_API string
163 LiteralizeEscapeNodeLiteral(const ValueNode&);
164
171 YF_API string
172 ParseNPLANodeString(const ValueNode&);
173
174
182 template<class _tNodeOrCon>
184 ValueNode::iterator
185 InsertChildSyntaxNode(_tNodeOrCon&& node_or_con, ValueNode& child)
186 {
187 return InsertSyntaxNode(yforward(node_or_con), child.GetContainerRef());
188 }
189 template<class _tNodeOrCon>
190 ValueNode::iterator
191 InsertChildSyntaxNode(_tNodeOrCon&& node_or_con, ValueNode&& child)
192 {
193 return InsertSyntaxNode(yforward(node_or_con),
194 std::move(child.GetContainerRef()));
195 }
196 template<class _tNodeOrCon>
197 ValueNode::iterator
198 InsertChildSyntaxNode(_tNodeOrCon&& node_or_con, const NodeLiteral& nl)
199 {
200 return
201 InsertChildSyntaxNode(yforward(node_or_con), TransformToSyntaxNode(nl));
202 }
204
205
207
208 using IndentGenerator = std::function<string(size_t)>;
210
212 YF_API string
213 DefaultGenerateIndent(size_t);
214
216
217
221 YF_API void
222 PrintIndent(std::ostream&, IndentGenerator = DefaultGenerateIndent, size_t = 1);
223
236 YF_API void
237 PrintNode(std::ostream&, const ValueNode&, NodeToString = EscapeNodeLiteral,
238 IndentGenerator = DefaultGenerateIndent, size_t = 0);
239
250 YF_API void
251 PrintNodeChild(std::ostream&, const ValueNode&, NodeToString
252 = EscapeNodeLiteral, IndentGenerator = DefaultGenerateIndent, size_t = 0);
253
263 YF_API bool
264 PrintNodeString(std::ostream&, const ValueNode&,
265 NodeToString = EscapeNodeLiteral);
267
268
269 namespace SXML
270 {
271
273
274
279 YF_API string
280 ConvertAttributeNodeString(const TermNode&);
281
294 YF_API string
295 ConvertDocumentNode(const TermNode&, IndentGenerator = DefaultGenerateIndent,
296 size_t = 0, ParseOption = ParseOption::Normal);
297
302 YF_API string
303 ConvertStringNode(const TermNode&);
304
313 YF_API void
314 PrintSyntaxNode(std::ostream& os, const TermNode&,
315 IndentGenerator = DefaultGenerateIndent, size_t = 0);
317
318
320
321
323 template<typename... _tParams>
324 ValueNode
325 MakeTop(const string& name, _tParams&&... args)
326 {
327 return YSLib::AsNodeLiteral(name,
328 {{MakeIndex(0), "*TOP*"}, NodeLiteral(yforward(args))...});
329 }
330 inline PDefH(ValueNode, MakeTop, )
331 ImplRet(MakeTop({}))
333
340 YF_API ValueNode
341 MakeXMLDecl(const string& = {}, const string& = "1.0",
342 const string& = "UTF-8", const string& = {});
343
349 YF_API ValueNode
350 MakeXMLDoc(const string& = {}, const string& = "1.0",
351 const string& = "UTF-8", const string& = {});
352
354
355 inline PDefH(NodeLiteral, MakeAttributeTagLiteral,
356 std::initializer_list<NodeLiteral> il)
357 ImplRet({"@", il})
358 template<typename... _tParams>
359 NodeLiteral
360 MakeAttributeTagLiteral(_tParams&&... args)
361 {
362 return SXML::MakeAttributeTagLiteral({NodeLiteral(yforward(args)...)});
363 }
365
367
368 inline PDefH(NodeLiteral, MakeAttributeLiteral, const string& name,
369 std::initializer_list<NodeLiteral> il)
370 ImplRet({name, {MakeAttributeTagLiteral(il)}})
371 template<typename... _tParams>
372 NodeLiteral
373 MakeAttributeLiteral(const string& name, _tParams&&... args)
374 {
375 return {name, {SXML::MakeAttributeTagLiteral(yforward(args)...)}};
376 }
378
380
381 template<class _tNodeOrCon>
382 inline void
383 InsertAttributeNode(_tNodeOrCon&& node_or_con, const string& name,
384 std::initializer_list<NodeLiteral> il)
385 {
386 InsertChildSyntaxNode(node_or_con, MakeAttributeLiteral(name, il));
387 }
388 template<class _tNodeOrCon, typename... _tParams>
389 inline void
390 InsertAttributeNode(_tNodeOrCon&& node_or_con, const string& name,
391 _tParams&&... args)
392 {
393 InsertChildSyntaxNode(node_or_con,
394 SXML::MakeAttributeLiteral(name, yforward(args)...));
395 }
397
398
399 } // namespace SXML;
401
402
408 class YF_API NPLException : public LoggedEvent
410 {
411 public:
412 YB_NONNULL(2)
413 NPLException(const char* str = "", YSLib::RecordLevel lv = YSLib::Err)
414 : LoggedEvent(str, lv)
415 {}
416 NPLException(const string_view sv, YSLib::RecordLevel lv = YSLib::Err)
417 : LoggedEvent(sv, lv)
418 {}
419 DefDeCtor(NPLException)
420
421
422 ~NPLException() override;
423 };
424
425
431 class YF_API ListReductionFailure : public NPLException
432 {
433 public:
435 using NPLException::NPLException;
436 DefDeCtor(ListReductionFailure)
437
438
439 ~ListReductionFailure() override;
440 };
441
442
444 class YF_API InvalidSyntax : public NPLException
445 {
446 public:
447 using NPLException::NPLException;
448 DefDeCtor(InvalidSyntax)
449
450
451 ~InvalidSyntax() override;
452 };
453
454
459 class YF_API ParameterMismatch : public InvalidSyntax
460 {
461 public:
462 using InvalidSyntax::InvalidSyntax;
463 DefDeCtor(ParameterMismatch)
464
465
466 ~ParameterMismatch() override;
467 };
468
469
474 class YF_API ArityMismatch : public ParameterMismatch
475 {
476 private:
477 size_t expected;
478 size_t received;
479
480 public:
481 DefDeCtor(ArityMismatch)
486 ArityMismatch(size_t, size_t, YSLib::RecordLevel = YSLib::Err);
487
489 ~ArityMismatch() override;
490
491 DefGetter(const ynothrow, size_t, Expected, expected)
492 DefGetter(const ynothrow, size_t, Received, received)
493 };
494
495
500 class YF_API BadIdentifier : public NPLException
501 {
502 private:
503 shared_ptr<string> p_identifier;
504
505 public:
516 YB_NONNULL(2)
517 BadIdentifier(const char*, size_t = 0, YSLib::RecordLevel = YSLib::Err);
518 BadIdentifier(string_view, size_t = 0, YSLib::RecordLevel = YSLib::Err);
519 DefDeCtor(BadIdentifier)
520
522 ~BadIdentifier() override;
523
524 DefGetter(const ynothrow, const string&, Identifier,
525 YSLib::Deref(p_identifier))
526 };
528
529
534 enum class LexemeCategory
535 {
537 Symbol,
539 Code,
541 Data,
543 Extended
544 };
545
546
548
549
551
560 YF_API LexemeCategory
561 CategorizeBasicLexeme(string_view) ynothrowv;
562
567 YF_API LexemeCategory
568 CategorizeLexeme(string_view) ynothrowv;
570
577 YF_API bool
578 IsNPLAExtendedLiteral(string_view) ynothrowv;
579
584 yconstfn PDefH(bool, IsNPLAExtendedLiteralNonDigitPrefix, char c) ynothrow
585 ImplRet(c == '#'|| c == '+' || c == '-')
586
588 inline PDefH(bool, IsNPLAExtendedLiteralPrefix, char c) ynothrow
589 ImplRet(std::isdigit(c) || IsNPLAExtendedLiteralNonDigitPrefix(c))
590
591
595 inline PDefH(bool, IsNPLASymbol, string_view id) ynothrowv
596 ImplRet(CategorizeLexeme(id) == LexemeCategory::Symbol)
598
599
600
609 using TokenValue = ystdex::derived_entity<string, NPLATag>;
610
611
617 YF_API observer_ptr<const TokenValue>
618 TermToNamePtr(const TermNode&);
619
625 YF_API void
626 TokenizeTerm(TermNode& term);
627
628
633 enum class ReductionStatus : yimpl(size_t)
634 {
636
637 Clean = 0,
640 Retained,
642 Retrying
644 };
645
646
656 using DelayedTerm = ystdex::derived_entity<TermNode, NPLATag>;
657
658
667 class YF_API TermReference
668 {
669 private:
670 ystdex::lref<TermNode> term_ref;
671
672 public:
673 yconstfn
674 TermReference(TermNode& term)
675 : term_ref(term)
676 {}
677 DefDeCopyCtor(TermReference)
678
679 DefDeCopyAssignment(TermReference)
680
681 friend PDefHOp(bool, ==, const TermReference& x, const TermReference& y)
682 ImplRet(&x.term_ref.get() == &y.term_ref.get())
683
684 yconstfn DefCvtMem(const ynothrow, TermNode&, term_ref)
685
686 yconstfn PDefH(TermNode&, get, ) const ynothrow
687 ImplRet(term_ref.get())
688 };
689
690
692
693
698 YF_API TermNode&
699 ReferenceTerm(TermNode&);
700 YF_API const TermNode&
701 ReferenceTerm(const TermNode&);
702
707 template<typename _type>
708 inline _type&
709 AccessTerm(ValueNode& term)
710 {
711 return ReferenceTerm(term).Value.Access<_type>();
712 }
713 template<typename _type>
714 inline const _type&
715 AccessTerm(const ValueNode& term)
716 {
717 return ReferenceTerm(term).Value.Access<_type>();
718 }
719
721
722 template<typename _type>
723 inline observer_ptr<_type>
724 AccessTermPtr(TermNode& term) ynothrow
725 {
726 return ReferenceTerm(term).Value.AccessPtr<_type>();
727 }
728 template<typename _type>
729 inline observer_ptr<const _type>
730 AccessTermPtr(const TermNode& term) ynothrow
731 {
732 return ReferenceTerm(term).Value.AccessPtr<_type>();
733 }
735
736
737
742 inline PDefH(ReductionStatus, CheckNorm, const TermNode& term) ynothrow
743 ImplRet(IsBranch(term) ? ReductionStatus::Retained : ReductionStatus::Clean)
744
745
753 YB_PURE YF_API bool
754 CheckReducible(ReductionStatus);
755
760 template<typename _func, typename... _tParams>
761 void
762 CheckedReduceWith(_func f, _tParams&&... args)
763 {
764 ystdex::retry_on_cond(CheckReducible, f, yforward(args)...);
765 }
766
767
769
770 YF_API void
772 LiftTerm(TermNode&, TermNode&);
774 inline PDefH(void, LiftTerm, ValueObject& term_v, ValueObject& vo)
775 ImplExpr(term_v = std::move(vo))
777 inline PDefH(void, LiftTerm, TermNode& term, ValueObject& vo)
778 ImplExpr(LiftTerm(term.Value, vo))
780
782
783
790 YF_API ValueObject
791 LiftTermObject(const ValueObject&);
792
807 YF_API void
808 LiftTermOrRef(TermNode&, TermNode&);
809
815 inline PDefH(void, LiftTermRef, TermNode& term, const TermNode& tm)
817 ImplExpr(YSLib::SetContentWith(term, tm, LiftTermObject))
818 inline PDefH(void, LiftTermRef, ValueObject& term_v, const ValueObject& vo)
819 ImplExpr(term_v = LiftTermObject(vo))
820 inline PDefH(void, LiftTermRef, TermNode& term, const ValueObject& vo)
821 ImplExpr(LiftTermRef(term.Value, vo))
823
832 YF_API void
833 LiftToReference(TermNode&, TermNode&);
834
839 YF_API void
840 LiftToSelf(TermNode&);
841
849 YF_API void
850 LiftToOther(TermNode&, TermNode&);
852
853
858 inline PDefH(void, LiftDelayed, TermNode& term, DelayedTerm& tm)
859 ImplExpr(LiftTermRef(term, tm))
860
861
863
864
868 inline PDefH(void, LiftFirst, TermNode& term)
869 ImplExpr(IsBranch(term), LiftTerm(term, Deref(term.begin())))
870
875 inline PDefH(void, LiftLast, TermNode& term)
876 ImplExpr(IsBranch(term), LiftTerm(term, Deref(term.rbegin())))
878
879
893 YF_API ReductionStatus
894 ReduceHeadEmptyList(TermNode&) ynothrow;
895
900 YF_API ReductionStatus
901 ReduceToList(TermNode&) ynothrow;
903
904
906
907
911 struct PassesCombiner
912 {
917 template<typename _tIn>
918 ReductionStatus
919 operator()(_tIn first, _tIn last) const
920 {
921 auto res(ReductionStatus::Clean);
922
923 return ystdex::fast_any_of(first, last, [&](ReductionStatus r) ynothrow{
924 if(r == ReductionStatus::Retained)
925 res = r;
926 return r == ReductionStatus::Retrying;
927 }) ? ReductionStatus::Retrying : res;
928 }
929 };
930
931
933 class ContextNode;
934
940 template<typename... _tParams>
942 using GPasses = YSLib::GEvent<ReductionStatus(_tParams...),
943 YSLib::GCombinerInvoker<ReductionStatus, PassesCombiner>>;
945 using TermPasses = GPasses<TermNode&>;
947 using EvaluationPasses = GPasses<TermNode&, ContextNode&>;
953 using LiteralPasses = GPasses<TermNode&, ContextNode&, string_view>;
955
956
958 using Guard = ystdex::any;
963 using GuardPasses = YSLib::GEvent<Guard(TermNode&, ContextNode&),
964 YSLib::GDefaultLastValueInvoker<Guard>>;
966
967
974 using EnvironmentList = vector<ValueObject>;
975
976
982 class YF_API Environment : private ystdex::equality_comparable<Environment>,
983 public enable_shared_from_this<Environment>
984 {
985 public:
987
988 using BindingMap = ValueNode;
989
990 mutable BindingMap Bindings{};
992
1005 std::function<observer_ptr<const Environment>(string_view)> Redirect{
1006 std::bind(DefaultRedirect, std::cref(*this), std::placeholders::_1)};
1024 std::function<observer_ptr<ValueNode>(string_view)> Resolve{
1025 std::bind(DefaultResolve, std::cref(*this), std::placeholders::_1)};
1027
1032 ValueObject Parent{};
1033
1035 DefDeCtor(Environment)
1036 DefDeCopyMoveCtorAssignment(Environment)
1042 explicit
1043 Environment(const BindingMap&& m)
1044 : Bindings(m)
1045 {}
1046 explicit
1047 Environment(BindingMap&& m)
1048 : Bindings(std::move(m))
1049 {}
1051
1057 explicit
1058 Environment(const ValueObject& vo)
1059 : Parent((CheckParent(vo), vo))
1060 {}
1061 explicit
1062 Environment(ValueObject&& vo)
1063 : Parent((CheckParent(vo), std::move(vo)))
1064 {}
1066
1067 friend PDefHOp(bool, ==, const Environment& x, const Environment& y)
1068 ynothrow
1069 ImplRet(x.Bindings == y.Bindings)
1070
1071
1075 DefGetter(const ynothrow, BindingMap&, MapRef, Bindings)
1076
1078
1079
1085 static void
1086 CheckParent(const ValueObject&);
1087
1089
1090
1106 static observer_ptr<const Environment>
1107 DefaultRedirect(const Environment&, string_view);
1108
1115 static observer_ptr<ValueNode>
1116 DefaultResolve(const Environment&, string_view);
1118
1119
1128 void
1130 Define(string_view, ValueObject&&, bool);
1131
1140 observer_ptr<ValueNode>
1141 LookupName(string_view) const;
1142
1144
1145 void
1147 Redefine(string_view, ValueObject&&, bool);
1148
1149 /*
1150 \brief 以字符串为标识符在指定上下文移除对象。
1151 \return 是否成功移除。
1152 */
1153 bool
1154 Remove(string_view, bool);
1156
1157
1164 YB_NORETURN static void
1165 ThrowForInvalidType(const ystdex::type_info&);
1166 };
1167
1168
1174 class YF_API ContextNode
1175 {
1176 private:
1181 shared_ptr<Environment> p_record{make_shared<Environment>()};
1182
1183 public:
1184 EvaluationPasses EvaluateLeaf{};
1185 EvaluationPasses EvaluateList{};
1186 LiteralPasses EvaluateLiteral{};
1187 GuardPasses Guard{};
1188
1189 DefDeCtor(ContextNode)
1194 ContextNode(const ContextNode&, shared_ptr<Environment>&&);
1195 DefDeCopyCtor(ContextNode)
1201 ContextNode(ContextNode&&);
1202 DefDeCopyMoveAssignment(ContextNode)
1203
1205
1206 DefGetter(const ynothrow, Environment::BindingMap&, BindingsRef,
1207 GetRecordRef().GetMapRef())
1208 DefGetter(const ynothrow, Environment&, RecordRef, *p_record)
1209
1210 PDefH(shared_ptr<Environment>, ShareRecord, ) const
1211 ImplRet(GetRecordRef().shared_from_this())
1212
1213 PDefH(weak_ptr<Environment>, WeakenRecord, ) const
1214 // TODO: Blocked. Use C++1z %weak_from_this and throw-expression.
1215 ImplRet(make_weak(ShareRecord()))
1216
1217 friend PDefH(void, swap, ContextNode& x, ContextNode& y) ynothrow
1218 ImplExpr(swap(x.p_record, y.p_record), swap(x.EvaluateLeaf,
1219 y.EvaluateLeaf), swap(x.EvaluateList, y.EvaluateList),
1220 swap(x.EvaluateLiteral, y.EvaluateLiteral), swap(x.Guard, y.Guard))
1222 };
1223
1224
1226
1227
1229 using ContextHandler = YSLib::GHEvent<ReductionStatus(TermNode&, ContextNode&)>;
1232 using LiteralHandler = YSLib::GHEvent<ReductionStatus(const ContextNode&)>;
1234
1236 inline PDefH(void, RegisterContextHandler, ContextNode& ctx, const string& name,
1237 ContextHandler f)
1238 ImplExpr(ctx.GetBindingsRef()[name].Value = std::move(f))
1239
1241 inline PDefH(void, RegisterLiteralHandler, ContextNode& ctx, const string& name,
1242 LiteralHandler f)
1243 ImplExpr(ctx.GetBindingsRef()[name].Value = std::move(f))
1245
1246
1248
1249
1251 template<typename _tKey>
1252 inline observer_ptr<ValueNode>
1253 LookupName(Environment& ctx, const _tKey& id) ynothrow
1254 {
1255 return YSLib::AccessNodePtr(ctx.GetMapRef(), id);
1256 }
1257 template<typename _tKey>
1258 inline observer_ptr<const ValueNode>
1259 LookupName(const Environment& ctx, const _tKey& id) ynothrow
1260 {
1261 return YSLib::AccessNodePtr(ctx.GetMapRef(), id);
1262 }
1264
1266 template<typename _tKey>
1267 ValueObject
1268 FetchValue(const Environment& env, const _tKey& name)
1269 {
1270 return GetValueOf(NPL::LookupName(env, name));
1271 }
1272
1274 template<typename _tKey>
1275 observer_ptr<const ValueObject>
1276 FetchValuePtr(const Environment& env, const _tKey& name)
1277 {
1278 return GetValuePtrOf(NPL::LookupName(env, name));
1279 }
1281
1282
1284
1285 template<class _tPasses, typename... _tParams>
1287 typename _tPasses::result_type
1288 InvokePasses(observer_ptr<const ValueNode> p, TermNode& term, ContextNode& ctx,
1289 _tParams&&... args)
1290 {
1291 return ystdex::call_value_or([&](const _tPasses& passes){
1292 // XXX: Blocked. 'yforward' cause G++ 5.3 crash: internal compiler
1293 // error: Segmentation fault.
1294 return passes(term, ctx, std::forward<_tParams>(args)...);
1295 }, YSLib::AccessPtr<const _tPasses>(p));
1296 }
1298 template<class _tPasses, typename... _tParams>
1299 inline typename _tPasses::result_type
1300 InvokePasses(const string& name, TermNode& term, ContextNode& ctx,
1301 _tParams&&... args)
1302 {
1303 return NPL::InvokePasses<_tPasses>(YSLib::AccessNodePtr(
1304 ystdex::as_const(ctx.GetBindingsRef()), name), term, ctx,
1305 yforward(args)...);
1306 }
1308
1309 } // namespace NPL;
1310
1311 #endif
1312
NPL::SXML::PDefH
PDefH(ValueNode, MakeTop,) ImplRet(MakeTop(
Definition: NPLA.h:330
NPL::SXML::ConvertDocumentNode
YF_API string ConvertDocumentNode(const TermNode &, IndentGenerator=DefaultGenerateIndent, size_t=0, ParseOption=ParseOption::Normal)
转换 SXML 文档节点为 XML 字符串。
Definition: NPLA.cpp:178
any.h
动态泛型类型。
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
NPL::CategorizeBasicLexeme
YF_API LexemeCategory CategorizeBasicLexeme(string_view) ynothrowv
对排除扩展字面量的词素分类。
ystdex::derived_entity
派生类实体。
Definition: base.h:177
NPL::ReferenceTerm
YF_API TermNode & ReferenceTerm(TermNode &)
访问项并取解析 TermReference 间接值后的引用。
Definition: NPLA.cpp:424
NPL::SXML::ConvertAttributeNodeString
YF_API string ConvertAttributeNodeString(const TermNode &)
转换 SXML 节点为 XML 属性字符串。
Definition: NPLA.cpp:154
NPL::SXML::ConvertStringNode
YF_API string ConvertStringNode(const TermNode &)
转换 SXML 节点为被转义的 XML 字符串。
Definition: NPLA.cpp:282
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:306
NPL::InsertChildSyntaxNode
ValueNode::iterator InsertChildSyntaxNode(_tNodeOrCon &&node_or_con, ValueNode &child)
插入语法子节点。
Definition: NPLA.h:185
NPL::Environment::Environment
Environment(BindingMap &&m)
Definition: NPLA.h:1047
NPL::SXML::ParseOption
ParseOption
限定解析选项。
Definition: NPL.h:60
ystdex::isdigit
bool isdigit(char c)
区域无关的 std::isdigit 实现。
Definition: cctype.h:122
NPL::YB_NONNULL
YF_API YB_NONNULL(1, 2) void InstallFile(const char *
安装文件：复制单个文件。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
NPL::LiftToReference
void LiftToReference(TermNode &term, TermNode &tm)
Definition: NPLA.cpp:482
YSLib::GCombinerInvoker
结果组合调用器。
Definition: YEvent.hpp:249
NPL::ContextNode
上下文节点。
Definition: NPLA.h:1174
YSLib::MakeIndex
MakeIndex
Definition: ValueNode.h:1202
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
NPL::x
const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow TermNode &term const TermNode &term ValueNode &node const ValueNode &node const _type & x
Definition: SContext.h:94
NPL::ArityMismatch::received
size_t received
Definition: NPLA.h:478
NPL::ReductionStatus::Retrying
需要重规约。
NPL::LexemeCategory::Extended
扩展字面量：由 NPLA 定义的其它字面量类别。
NPL::NodeToString
std::function< string(const ValueNode &)> NodeToString
Definition: NPLA.h:114
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
NPL::LiftToSelf
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(YSLib YF_API void LiftToSelf(TermNode &)
提升项引用：使用第二个参数指定的项的内容引用替换第一个项的内容。
Definition: NPLA.h:840
NPL::NodeMapper
std::function< ValueNode(const TermNode &)> NodeMapper
节点映射操作类型：变换节点为另一个节点。
Definition: NPLA.h:110
ystdex::cpp2014::rbegin
auto rbegin(_tRange &c) -> decltype(c.rbegin())
Definition: range.hpp:94
ystdex::make_weak
std::weak_ptr< _type > make_weak(const std::shared_ptr< _type > &p)
使用指定的 std::shared_ptr 实例的对象创建对应的 std::weak_ptr 实例的对象。
Definition: memory.hpp:956
NPL::InsertSyntaxNode
ValueNode::iterator InsertSyntaxNode(_tNodeOrCon &&node_or_con, std::initializer_list< ValueNode > il, _tParams &&...args)
插入语法节点。
Definition: NPLA.h:90
YModules.h
CHRLib::f
f(d, s)
NPL::PassesCombiner
遍合并器：逐次调用直至成功。
Definition: NPLA.h:911
ystdex::call_value_or
auto call_value_or(_func f, _type &&p) -> decay_t< decltype(f(*std::forward< decltype(p)>(p)))>
调用非空值或取默认值。
Definition: deref_op.hpp:140
DefDeCopyMoveAssignment
#define DefDeCopyMoveAssignment(_t)
Definition: YBaseMacro.h:197
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:262
NPL::CategorizeLexeme
YF_API LexemeCategory CategorizeLexeme(string_view) ynothrowv
对词素分类。
Definition: NPLA.cpp:386
NPL::LexemeCategory
LexemeCategory
字面量类别。
Definition: NPLA.h:534
NPL::ListReductionFailure
列表规约失败。
Definition: NPLA.h:431
YSLib::GetValuePtrOf
observer_ptr< const ValueObject > GetValuePtrOf(observer_ptr< const ValueNode > p_node)
Definition: ValueNode.cpp:150
NPL::SXML::ParseOption::Normal
NPL::ReductionStatus
ReductionStatus
规约状态：一遍规约可能的中间结果。
Definition: NPLA.h:633
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:50
ystdex::make_shared
std::shared_ptr< _type > make_shared(std::initializer_list< _tValue > il)
使用指定类型的初始化列表构造指定类型的 std::shared_ptr 对象。
Definition: memory.hpp:945
DefDeCopyMoveCtorAssignment
#define DefDeCopyMoveCtorAssignment(_t)
Definition: YBaseMacro.h:202
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
NPL::PrintNodeString
YF_API bool PrintNodeString(std::ostream &, const ValueNode &, NodeToString=EscapeNodeLiteral)
打印节点字符串。
Definition: NPLA.cpp:141
NPL::AccessTerm
_type & AccessTerm(ValueNode &term)
访问解析 TermReference 后的项的指定类型对象。 异常中立：空实例或类型检查失败。
Definition: NPLA.h:709
NPL::BadIdentifier::p_identifier
shared_ptr< string > p_identifier
Definition: NPLA.h:503
NPL::Guard
ystdex::any Guard
作用域守护类型。
Definition: NPLA.h:958
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:527
NPL::PDefH
YF_API const char * PDefH(void, InstallFile, const string &dst, const string &src) ImplExpr(InstallFile(dst.c_str()
NPL::Environment::DefDeCtor
DefDeCtor(Environment) DefDeCopyMoveCtorAssignment(Environment) explicit Environment(const BindingMap &&m)
无参数构造：初始化空环境。
Definition: NPLA.h:1035
NPL::PrintNodeChild
YF_API void PrintNodeChild(std::ostream &, const ValueNode &, NodeToString=EscapeNodeLiteral, IndentGenerator=DefaultGenerateIndent, size_t=0)
打印作为子节点的 NPLA 节点。
Definition: NPLA.cpp:124
ystdex::lref< TermNode >
NPL::ContextHandler
YSLib::GHEvent< ReductionStatus(TermNode &, ContextNode &)> ContextHandler
上下文处理器类型。
Definition: NPLA.h:1230
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:161
YSLib::ValueNode::Container
ystdex::mapped_set< ValueNode, ystdex::less<>> Container
Definition: ValueNode.h:62
NPL::ArityMismatch
元数不匹配错误。
Definition: NPLA.h:474
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:845
NPL::LexemeCategory::Symbol
符号：非字面量。
NPL::Environment::Environment
Environment(const ValueObject &vo)
构造：使用父环境。 异常中立：由 CheckParent 抛出。
Definition: NPLA.h:1058
NPL::SXML::PrintSyntaxNode
YF_API void PrintSyntaxNode(std::ostream &os, const TermNode &, IndentGenerator=DefaultGenerateIndent, size_t=0)
打印 SContext::Analyze 分析取得的 SXML 语法树节点并刷新流。
Definition: NPLA.cpp:288
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:157
NPL::ReduceToList
YF_API ReductionStatus ReduceToList(TermNode &) ynothrow
规约为列表：对枝节点移除第一个子项，保留余下的子项作为列表。
Definition: NPLA.cpp:523
NPL::EscapeNodeLiteral
YF_API string EscapeNodeLiteral(const ValueNode &)
转义 NPLA 节点字面量。
Definition: NPLA.cpp:68
ystdex::dep_ops::equality_comparable
_t< details::ops_seq< _type, _type2, _tOpt, cond_t< is_same< _type, _type2 >, index_sequence< 7 >, index_sequence< 6, 7, 8 >>>> equality_comparable
Definition: operators.hpp:243
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:539
NPL::TermReference::TermReference
yconstfn TermReference(TermNode &term)
Definition: NPLA.h:674
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::transformed_iterator
变换迭代器。
Definition: iterator.hpp:216
YSLib::ValueNode::iterator
Container::iterator iterator
Definition: ValueNode.h:66
NPL::NodeInserter
GNodeInserter< TermNode::Container & > NodeInserter
Definition: NPLA.h:119
NPL::PassesCombiner::operator()
ReductionStatus operator()(_tIn first, _tIn last) const
Definition: NPLA.h:919
NPL::LexemeCategory::Data
数据字面量。
YSLib::SetContentWith
_fCallable void SetContentWith(ValueNode &dst, _tNode &node, _fCallable f)
Definition: ValueNode.h:1172
ystdex
特性测试宏。
Definition: ydef.h:822
NPL::Environment
环境。
Definition: NPLA.h:982
NPL::ParseNPLANodeString
YF_API string ParseNPLANodeString(const ValueNode &)
解析 NPLA 节点字符串。
Definition: NPLA.cpp:80
NPL::CheckedReduceWith
PDefH(ReductionStatus, CheckNorm, const TermNode &term) ynothrow ImplRet(IsBranch(term)?ReductionStatus void CheckedReduceWith(_func f, _tParams &&...args)
检查视为范式的节点并提取规约状态。
Definition: NPLA.h:762
YSLib::AccessNodePtr
YF_API observer_ptr< ValueNode > AccessNodePtr(ValueNode::Container &, const string &) ynothrow
访问节点指针。
Definition: ValueNode.cpp:113
NPL::TermNode
yimpl(ValueNode) TermNode
项节点：存储语法分析结果的值类型节点。
Definition: SContext.h:51
NPL::IndentGenerator
std::function< string(size_t)> IndentGenerator
生成前缀缩进的函数类型。
Definition: NPLA.h:209
NPL::BadIdentifier
标识符错误。
Definition: NPLA.h:500
NPL::TermToNamePtr
YF_API observer_ptr< const TokenValue > TermToNamePtr(const TermNode &)
访问项的值作为记号。
Definition: NPLA.cpp:408
NPL::Environment::Environment
Environment(ValueObject &&vo)
Definition: NPLA.h:1062
NPL::AccessTermPtr
observer_ptr< _type > AccessTermPtr(TermNode &term) ynothrow
访问解析 TermReference 后的项的指定类型对象指针。
Definition: NPLA.h:724
DefCvtMem
#define DefCvtMem(_q, _t, _m)
Definition: YBaseMacro.h:211
YF_API
#define YF_API
Definition: Platform.h:56
NPL::SXML::InsertAttributeNode
void InsertAttributeNode(_tNodeOrCon &&node_or_con, const string &name, std::initializer_list< NodeLiteral > il)
插入只有 XML 属性节点到语法节点。
Definition: NPLA.h:383
NPL::ImplExpr
YF_API const char src const string const char const char *src ImplExpr(InstallDirectory(string(dst), string(src))) YF_API YB_NONNULL(1
安装硬链接：创建硬链接，失败则安装文件。
NPL::LexemeCategory::Code
代码字面量。
base.h
基类实用设施。
NPL::ImplRet
const TermNode &term ynothrow ImplRet(!term) inline PDefH(bool
NPL::PrintIndent
YF_API void PrintIndent(std::ostream &, IndentGenerator=DefaultGenerateIndent, size_t=1)
异常中立：参数指定的处理器为空。
Definition: NPLA.cpp:93
NPL::ArityMismatch::expected
size_t expected
Definition: NPLA.h:477
ystdex::fast_any_of
bool fast_any_of(_tIn first, _tIn last, _fPred pred)
Definition: algorithm.hpp:75
NPL::NPLTag
NPL 元标签。
Definition: NPL.h:43
YSLib::NodeLiteral
包装节点的组合字面量。
Definition: ValueNode.h:1246
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
NPL::LiftTermObject
ValueObject LiftTermObject(const ValueObject &vo)
Definition: NPLA.cpp:465
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:58
NPL::ReduceHeadEmptyList
ReductionStatus ReduceHeadEmptyList(TermNode &term) ynothrow
Definition: NPLA.cpp:515
NPL::SXML::MakeAttributeLiteral
NodeLiteral MakeAttributeLiteral(const string &name, _tParams &&...args)
Definition: NPLA.h:373
NPL::InvalidSyntax
语法错误。
Definition: NPLA.h:444
std
Definition: memory.hpp:1183
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
NPL::MapNPLALeafNode
YF_API ValueNode MapNPLALeafNode(const TermNode &)
映射 NPLA 叶节点。
Definition: NPLA.cpp:38
YSLib::NodeSequence
yimpl(YSLib::vector)< ValueNode > NodeSequence
节点序列容器。
Definition: ValueNode.h:1239
YSLib::GetValueOf
ValueObject GetValueOf(observer_ptr< const ValueNode > p_node)
Definition: ValueNode.cpp:144
NPL
Definition: NPL/Configuration.h:34
NPL::ReductionStatus::Clean
规约成功终止且不需要保留子项。
NPL::DefaultGenerateIndent
YF_API string DefaultGenerateIndent(size_t)
生成水平制表符为单位的缩进。
Definition: NPLA.cpp:87
NPL::NPLATag
NPLA 元标签。
Definition: NPLA.h:77
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:504
NPL::SXML::MakeTop
ValueNode MakeTop(const string &name, _tParams &&...args)
构造 SXML 文档顶级节点。
Definition: NPLA.h:325
platform::Descriptions::Err
Definition: YCommon.h:166
NPL::CheckReducible
bool CheckReducible(ReductionStatus status)
Definition: NPLA.cpp:442
NPL::SXML::MakeAttributeTagLiteral
NodeLiteral MakeAttributeTagLiteral(_tParams &&...args)
Definition: NPLA.h:360
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::UI::name
yconstfn const string & name
Definition: Loader.h:130
YSLib::Text::str
const char const char * str
Definition: TextFile.h:81
NPL::LiteralHandler
YSLib::GHEvent< ReductionStatus(const ContextNode &)> LiteralHandler
字面量处理器类型。
Definition: NPLA.h:1232
CHRLib::c
c
Definition: CharacterProcessing.h:81
NPL::TransformToSyntaxNode
YF_API ValueNode TransformToSyntaxNode(const ValueNode &, const string &={})
变换节点为语法分析树叶节点。
Definition: NPLA.cpp:45
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
ystdex::retry_on_cond
result_of_t< _fCallable &&(_tParams &&...)> retry_on_cond(_fCond cond, _fCallable &&f, _tParams &&...args)
循环重复调用：代替直接使用 do-while 语句以避免过多引入作用域外的变量。
Definition: functional.hpp:1152
NPL::InvokePasses
typename _tParams _tPasses::result_type InvokePasses(observer_ptr< const ValueNode > p, TermNode &term, ContextNode &ctx, _tParams &&...args)
Definition: NPLA.h:1288
NPL::GNodeInserter
std::function< void(TermNode &&, _tCon &)> GNodeInserter
Definition: NPLA.h:117
NPL::NodeSequenceInserter
GNodeInserter< NodeSequence > NodeSequenceInserter
Definition: NPLA.h:121
NPL::SXML::MakeXMLDoc
YF_API ValueNode MakeXMLDoc(const string &={}, const string &="1.0", const string &="UTF-8", const string &={})
构造包含 XML 声明的 SXML 文档节点。
Definition: NPLA.cpp:313
NPL::TermReference::term_ref
ystdex::lref< TermNode > term_ref
Definition: NPLA.h:670
NPL::TokenizeTerm
YF_API void TokenizeTerm(TermNode &term)
标记记号节点：递归变换节点，转换其中的词素为记号值。
Definition: NPLA.cpp:414
NPL::SXML::MakeXMLDecl
YF_API ValueNode MakeXMLDecl(const string &={}, const string &="1.0", const string &="UTF-8", const string &={})
构造 SXML 文档 XML 声明节点。
Definition: NPLA.cpp:299
ystdex::as_const
add_const_t< _type > & as_const(_type &t)
转换 const 引用。
Definition: utility.hpp:51
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
NPL::NPLException
NPL 异常基类。
Definition: NPLA.h:409
NPL::LiftLast
tm LiftLast
Definition: NPLA.h:875
NPL::ParameterMismatch
参数匹配失败。
Definition: NPLA.h:459
YSLib::vo
vo
Definition: YApplication.h:231
ystdex::cref
lref< const _type > cref(const _type &t)
Definition: ref.hpp:142
NPL::LiftTermOrRef
YF_API void LiftTermOrRef(TermNode &, TermNode &)
提升项或创建引用项。
Definition: NPLA.cpp:473
NPL::TermReference
项引用。
Definition: NPLA.h:667
NPL::IsNPLAExtendedLiteral
YF_API bool IsNPLAExtendedLiteral(string_view) ynothrowv
判断不是非扩展字面量的词素是否为 NPLA 扩展字面量。
Definition: NPLA.cpp:395
NPL::LiteralizeEscapeNodeLiteral
YF_API string LiteralizeEscapeNodeLiteral(const ValueNode &)
转义 NPLA 节点字面量。
Definition: NPLA.cpp:74
NPL::PrintNode
YF_API void PrintNode(std::ostream &, const ValueNode &, NodeToString=EscapeNodeLiteral, IndentGenerator=DefaultGenerateIndent, size_t=0)
打印 NPLA 节点。
Definition: NPLA.cpp:100
NPL::ReductionStatus::Retained
规约成功但需要保留子项。
ystdex::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:415
NPL::LiftToOther
YF_API void LiftToOther(TermNode &, TermNode &)
递归提升项及其子项或递归创建项和子项对应的包含间接值的引用项到其它项。
Definition: NPLA.cpp:507
NPL::GPasses
YSLib::GEvent< ReductionStatus(_tParams...), YSLib::GCombinerInvoker< ReductionStatus, PassesCombiner >> GPasses
一般合并遍。
Definition: NPLA.h:943
CHRLib::p
const auto p(d)
YSLib::lv
RecordLevel lv
Definition: YException.cpp:58
NPL::EnvironmentList
vector< ValueObject > EnvironmentList
环境列表。
Definition: NPLA.h:974
NPL::LiftTerm
YF_API void LiftTerm(TermNode &, TermNode &)
提升项：使用第二个参数指定的项的内容替换第一个项的内容。
Definition: NPLA.cpp:454
ystdex::details::get
get())
Definition: cast.hpp:102