YSTest: NPLA1.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

NPLA1.h
浏览该文件的文档.
1 /*
2 © 2014-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 #ifndef NPL_INC_NPLA1_h_
29 #define NPL_INC_NPLA1_h_ 1
30
31 #include "YModules.h"
32 #include YFM_NPL_NPLA // for NPLATag, TermNode, ContextNode,
33 // ystdex::equality_comparable, std::declval, ystdex::exclude_self_t,
34 // ystdex::ref_eq, CombineReductionResult, pmr::memory_resource,
35 // NPL::make_observer, TNIter, LiftOther, ValueNode, NPL::Deref,
36 // NPL::AsTermNode, std::make_move_iterator, IsBranch, std::next,
37 // ystdex::retry_on_cond, std::find_if, ystdex::exclude_self_params_t,
38 // YSLib::AreEqualHeld, ystdex::make_parameter_list_t,
39 // ystdex::make_function_type_t, ystdex::decay_t, ystdex::expanded_caller,
40 // std::is_constructible, ystdex::or_, string_view, TermTags, TokenValue,
41 // Environment, ParseResultOf, ByteParser, SourcedByteParser,
42 // ystdex::type_info, SourceInformation, std::integral_constant, SourceName,
43 // NPL::tuple, NPL::get, NPL::forward_as_tuple, ReaderState,
44 // YSLib::allocate_shared;
45 #include YFM_YSLib_Core_YEvent // for YSLib::GHEvent, YSLib::GEvent,
46 // YSLib::GCombinerInvoker, YSLib::GDefaultLastValueInvoker;
47 #include <ystdex/algorithm.hpp> // for ystdex::fast_any_of, ystdex::split;
48 #include <ystdex/cast.hpp> // for ystdex::polymorphic_downcast;
49 #include <ystdex/scope_guard.hpp> // for ystdex::guard;
50
51 namespace NPL
52 {
53
55 namespace A1
56 {
57
63 struct YF_API NPLA1Tag : NPLATag
64 {};
65
66
68
69
71 using ContextHandler = YSLib::GHEvent<ReductionStatus(TermNode&, ContextNode&)>;
74 using LiteralHandler = YSLib::GHEvent<ReductionStatus(const ContextNode&)>;
76
77
82 enum class ValueToken
83 {
84 Null,
89 Undefined,
94 Unspecified,
95 GroupingAnchor,
96 OrderedAnchor
97 };
99
107 YB_ATTR_nodiscard YF_API YB_PURE string
108 to_string(ValueToken);
109
110
119 class YF_API Continuation : private ystdex::equality_comparable<Continuation>
120 {
121 public:
123 using allocator_type
124 = decltype(std::declval<const ContextNode&>().get_allocator());
125
126 ContextHandler Handler;
127
129
130 template<typename _func, yimpl(typename
131 = ystdex::exclude_self_t<Continuation, _func>)>
132 inline
133 Continuation(_func&& handler, allocator_type a)
134 : Handler(ystdex::make_obj_using_allocator<ContextHandler>(a,
135 yforward(handler)))
136 {}
137 template<typename _func, yimpl(typename
138 = ystdex::exclude_self_t<Continuation, _func>)>
139 inline
140 Continuation(_func&& handler, const ContextNode& ctx)
141 : Continuation(yforward(handler), ctx.get_allocator())
142 {}
143 Continuation(const Continuation& cont, allocator_type a)
144 : Handler(ystdex::make_obj_using_allocator<ContextHandler>(a,
145 cont.Handler))
146 {}
147 Continuation(Continuation&& cont, allocator_type a)
148 : Handler(ystdex::make_obj_using_allocator<ContextHandler>(a,
149 std::move(cont.Handler)))
150 {}
152 DefDeCopyMoveCtorAssignment(Continuation)
153
154 YB_ATTR_nodiscard YB_STATELESS friend
155 PDefHOp(bool, ==, const Continuation& x, const Continuation& y) ynothrow
156 ImplRet(ystdex::ref_eq<>()(x, y))
157
158
159 ReductionStatus
160 operator()(ContextNode&) const;
161
162 friend DefSwap(ynothrow, Continuation, swap(_x.Handler, _y.Handler))
163 };
164
165
167
168
172 YB_NORETURN YF_API void
173 ThrowInsufficientTermsError();
174
180 YB_NORETURN YF_API YB_NONNULL(1) void
182 ThrowInvalidSyntaxError(const char*);
183 YB_NORETURN YF_API void
184 ThrowInvalidSyntaxError(string_view);
186
191 YB_NORETURN YF_API void
192 ThrowNonmodifiableErrorForAssignee();
193
200 YB_NORETURN YF_API YB_NONNULL(1) void
202 ThrowUnsupportedLiteralError(const char*);
203 YB_NORETURN inline PDefH(void, ThrowUnsupportedLiteralError, string_view sv)
204 ImplExpr(ThrowUnsupportedLiteralError(sv.data()))
206
211 YB_NORETURN YF_API void
212 ThrowValueCategoryErrorForFirstArgument(const TermNode&);
214
215
217
218
223 struct PassesCombiner
224 {
229 template<typename _tIn>
230 YB_ATTR_nodiscard YB_PURE ReductionStatus
231 operator()(_tIn first, _tIn last) const
232 {
233 auto res(ReductionStatus::Neutral);
234
235 return ystdex::fast_any_of(first, last, [&](ReductionStatus r) ynothrow{
236 res = CombineReductionResult(res, r);
237 // XXX: Currently %CheckReducible is not used. This should be safe
238 // because only %ReductionStatus::Partial is the exception to be
239 // set, which is not supported here.
240 return r == ReductionStatus::Retrying;
241 }) ? ReductionStatus::Retrying : res;
242 }
243 };
244
245
251 template<typename... _tParams>
253 using GPasses = YSLib::GEvent<ReductionStatus(_tParams...),
254 YSLib::GCombinerInvoker<ReductionStatus, PassesCombiner>>;
256 using TermPasses = GPasses<TermNode&>;
258 using EvaluationPasses = GPasses<TermNode&, ContextNode&>;
264 using LiteralPasses = GPasses<TermNode&, ContextNode&, string_view>;
266
267
269 using Guard = any;
274 using GuardPasses = YSLib::GEvent<Guard(TermNode&, ContextNode&),
275 YSLib::GDefaultLastValueInvoker<Guard>>;
277
278
287 class YF_API ContextState : public ContextNode
288 {
289 public:
290 // XXX: Allocators are not used here for performance.
292 EvaluationPasses EvaluateLeaf{};
294 EvaluationPasses EvaluateList{};
296 LiteralPasses EvaluateLiteral{};
298 GuardPasses Guard{};
305 Continuation ReduceOnce{DefaultReduceOnce, *this};
306
307 private:
312 observer_ptr<TermNode> next_term_ptr{};
317 observer_ptr<TermNode> combining_term_ptr{};
318
319 public:
324 ContextState(pmr::memory_resource&);
326 ContextState(const ContextState&);
328 ContextState(ContextState&&);
330 ~ContextState() override;
331
332 DefDeCopyMoveAssignment(ContextState)
333
334
340 YB_ATTR_nodiscard YB_PURE static
341 PDefH(ContextState&, Access, ContextNode& ctx) ynothrowv
342 ImplRet(ystdex::polymorphic_downcast<ContextState&>(ctx))
343 YB_ATTR_nodiscard YB_PURE static
344 PDefH(const ContextState&, Access, const ContextNode& ctx) ynothrowv
345 ImplRet(ystdex::polymorphic_downcast<const ContextState&>(ctx))
347
353 DefGetter(const ynothrow, observer_ptr<TermNode>, CombiningTermPtr,
354 combining_term_ptr)
360 YB_ATTR_nodiscard YB_PURE TermNode&
361 GetNextTermRef() const;
362
368 PDefH(void, SetCombiningTermRef, TermNode& term) ynothrow
369 ImplExpr(combining_term_ptr = NPL::make_observer(&term))
375 PDefH(void, SetNextTermRef, TermNode& term) ynothrow
376 ImplExpr(next_term_ptr = NPL::make_observer(&term))
377
383 PDefH(void, ClearCombiningTerm, ) ynothrow
384 ImplExpr(combining_term_ptr = {})
385
390 PDefH(void, ClearNextTerm, ) ynothrow
391 ImplExpr(next_term_ptr = {})
392
428 static ReductionStatus
429 DefaultReduceOnce(TermNode&, ContextNode&);
430
441 ReductionStatus
442 RewriteGuarded(TermNode&, Reducer);
443
453 ReductionStatus
454 RewriteTerm(TermNode&);
455
461 ReductionStatus
462 RewriteTermGuarded(TermNode&);
464
465 friend PDefH(void, swap, ContextState& x, ContextState& y) ynothrow
466 ImplExpr(swap(static_cast< ContextNode&>(x), static_cast< ContextNode&>(
467 y)), swap(x.combining_term_ptr, y.combining_term_ptr),
468 swap(x.next_term_ptr, y.next_term_ptr), swap(x.EvaluateLeaf,
469 y.EvaluateLeaf), swap(x.EvaluateList, y.EvaluateList),
470 swap(x.EvaluateLiteral, y.EvaluateLiteral), swap(x.Guard, y.Guard))
471 };
472
473
474 inline PDefH(ReductionStatus, Continuation::operator(), ContextNode& ctx) const
475 ImplRet(Handler(ContextState::Access(ctx).GetNextTermRef(), ctx))
476
477
478
496 YF_API ReductionStatus
497 Reduce(TermNode&, ContextNode&);
498
516 YF_API void
517 ReduceArguments(TNIter, TNIter, ContextNode&);
518 inline PDefH(void, ReduceArguments, TermNode& term, ContextNode& ctx)
519 ImplRet(ReduceArguments(term.begin(), term.end(), ctx))
521
527 YF_API void
528 ReduceChildren(TNIter, TNIter, ContextNode&);
529 inline PDefH(void, ReduceChildren, TermNode& term, ContextNode& ctx)
530 ImplExpr(ReduceChildren(term.begin(), term.end(), ctx))
532
533
542 YF_API ReductionStatus
543 ReduceChildrenOrdered(TNIter, TNIter, ContextNode&);
544 inline PDefH(ReductionStatus, ReduceChildrenOrdered, TermNode& term,
545 ContextNode& ctx)
546 ImplRet(ReduceChildrenOrdered(term.begin(), term.end(), ctx))
548
561 YF_API ReductionStatus
562 ReduceFirst(TermNode&, ContextNode&);
563
578 YF_API ReductionStatus
579 ReduceOnce(TermNode&, ContextNode&);
580
591 inline PDefH(ReductionStatus, ReduceOnceLifted, TermNode& term,
592 ContextNode& ctx, TermNode& tm)
593 ImplRet(LiftOther(term, tm), ReduceOnce(term, ctx))
594
600 YF_API ReductionStatus
601 ReduceOrdered(TermNode&, ContextNode&);
602
611 YF_API ReductionStatus
612 ReduceTail(TermNode&, ContextNode&, TNIter);
614
615
616
622 inline PDefH(ReductionStatus, ReduceReturnUnspecified, TermNode& term) ynothrow
623 ImplRet((term.Value = ValueObject(std::allocator_arg, term.get_allocator(),
624 ValueToken::Unspecified)), ReductionStatus::Clean)
625
626
635 YF_API void
636 SetupTraceDepth(ContextState&, const string& = yimpl("$__depth"));
637
638
647 YF_API void
648 InsertChild(ValueNode&&, ValueNode::Container&);
649
672 YF_API ValueNode
673 TransformNode(const TermNode&);
674
675
685 struct SeparatorTransformer
686 {
688
689 template<typename _func, class _tTerm, class _fPred>
690 YB_ATTR_nodiscard TermNode
691 operator()(_func trans, _tTerm&& term, const ValueObject& pfx,
692 _fPred filter) const
693 {
694 using it_t = decltype(std::make_move_iterator(term.begin()));
695
696 return AddRange([&](TermNode& res, it_t b, it_t e){
697 const auto add([&](TermNode& node, it_t i){
698 node.Add(trans(NPL::Deref(i)));
699 });
700
701 if(b != e)
702 {
703 // XXX: This guarantees a single element is converted with
704 // no redundant parentheses according to NPLA1 syntax,
705 // consistent to the trivial reduction for term with one
706 // subnode in %ContextState::DefaultReduceOnce.
707 if(std::next(b) == e)
708 add(res, b);
709 else
710 {
711 auto child(NPL::AsTermNode(res.get_allocator()));
712
713 ystdex::retry_on_cond([&]() ynothrow{
714 return b != e;
715 }, [&]{
716 add(child, b++);
717 });
718 res.Add(std::move(child));
719 }
720 }
721 }, yforward(term), pfx, filter);
722 }
723
724 template<typename _func, class _tTerm, class _fPred>
725 YB_ATTR_nodiscard TermNode
726 AddRange(_func add_range, _tTerm&& term, const ValueObject& pfx,
727 _fPred filter) const
728 {
729 using it_t = decltype(std::make_move_iterator(term.begin()));
730 const auto a(term.get_allocator());
731 auto res(NPL::AsTermNode(a, yforward(term).Value));
732
733 if(IsBranch(term))
734 {
735 res.Add(NPL::AsTermNode(a, pfx));
736 ystdex::split(std::make_move_iterator(term.begin()),
737 std::make_move_iterator(term.end()), filter,
738 [&](it_t b, it_t e){
739 add_range(res, b, e);
740 });
741 }
742 return res;
743 }
744
745 template<class _tTerm, class _fPred>
746 YB_ATTR_nodiscard static TermNode
747 Process(_tTerm&& term, const ValueObject& pfx, _fPred filter)
748 {
749 return SeparatorTransformer()([&](_tTerm&& tm) ynothrow{
750 return yforward(tm);
751 }, yforward(term), pfx, filter);
752 }
753
759 template<class _fPred>
760 static void
761 ReplaceChildren(TermNode& term, const ValueObject& pfx,
762 _fPred filter)
763 {
764 if(std::find_if(term.begin(), term.end(), filter) != term.end())
765 term = Process(std::move(term), pfx, filter);
766 }
768 };
769
770
785 YF_API TermNode
786 ParseLeaf(string_view, TermNode::allocator_type);
787
797 YF_API TermNode
798 ParseLeafWithSourceInformation(string_view, const shared_ptr<string>&,
799 const SourceLocation&, TermNode::allocator_type);
801
802
804
805
810 template<typename _func>
811 class WrappedContextHandler
812 : private ystdex::equality_comparable<WrappedContextHandler<_func>>
813 {
814 public:
815 _func Handler;
816
818 template<typename... _tParams, yimpl(typename
819 = ystdex::exclude_self_params_t<WrappedContextHandler, _tParams...>)>
820 WrappedContextHandler(_tParams&&... args)
821 : Handler(yforward(args)...)
822 {}
824 DefDeCopyMoveCtorAssignment(WrappedContextHandler)
825
826 template<typename... _tParams>
827 ReductionStatus
828 operator()(_tParams&&... args) const
829 {
830 Handler(yforward(args)...);
831 return ReductionStatus::Clean;
832 }
833
839 YB_ATTR_nodiscard friend YB_PURE PDefHOp(bool, ==,
840 const WrappedContextHandler& x, const WrappedContextHandler& y)
841 ImplRet(YSLib::AreEqualHeld(x.Handler, y.Handler))
842
843
844 friend
845 DefSwap(ynothrow, WrappedContextHandler, swap(_x.Handler, _y.Handler))
846 };
847
848 template<class _tDst, typename _func>
849 YB_ATTR_nodiscard YB_PURE inline _tDst
850 WrapContextHandler(_func&& h, ystdex::false_)
851 {
852 return WrappedContextHandler<YSLib::GHEvent<ystdex::make_function_type_t<
853 void, ystdex::make_parameter_list_t<typename _tDst::BaseType>>>>(
854 yforward(h));
855 }
856 template<class, typename _func>
857 YB_ATTR_nodiscard YB_PURE inline _func
858 WrapContextHandler(_func&& h, ystdex::true_)
859 {
860 return yforward(h);
861 }
862 template<class _tDst, typename _func>
863 YB_ATTR_nodiscard YB_PURE inline _tDst
864 WrapContextHandler(_func&& h)
865 {
866 using BaseType = typename _tDst::BaseType;
867
868 // XXX: It is a hack to adjust the convertible result for the expanded
869 // caller here. It should have been implemented in %GHEvent, however types
870 // those cannot convert to expanded caller cannot be SFINAE'd out,
871 // otherwise it would cause G++ 5.4 crash with internal compiler error:
872 // "error reporting routines re-entered".
873 return A1::WrapContextHandler<_tDst>(yforward(h), ystdex::or_<
874 std::is_constructible<BaseType, _func>,
875 std::is_constructible<BaseType, ystdex::expanded_caller<
876 typename _tDst::FuncType, ystdex::decay_t<_func>>>>());
877 }
879
880 template<class _tDst, typename _func, class _tAlloc>
881 YB_ATTR_nodiscard YB_PURE inline _tDst
882 WrapContextHandler(_func&& h, const _tAlloc& a, ystdex::false_)
883 {
884 return WrappedContextHandler<YSLib::GHEvent<ystdex::make_function_type_t<
885 void, ystdex::make_parameter_list_t<typename _tDst::BaseType>>>>(
886 std::allocator_arg, a, yforward(h));
887 }
888 template<class, typename _func, class _tAlloc>
889 YB_ATTR_nodiscard YB_PURE inline _func
890 WrapContextHandler(_func&& h, const _tAlloc&, ystdex::true_)
891 {
892 return yforward(h);
893 }
894 template<class _tDst, typename _func, class _tAlloc>
895 YB_ATTR_nodiscard YB_PURE inline _tDst
896 WrapContextHandler(_func&& h, const _tAlloc& a)
897 {
898 using BaseType = typename _tDst::BaseType;
899
900 // XXX: Ditto
901 return A1::WrapContextHandler<_tDst>(yforward(h), a, ystdex::or_<
902 std::is_constructible<BaseType, _func>,
903 std::is_constructible<BaseType, ystdex::expanded_caller<
904 typename _tDst::FuncType, ystdex::decay_t<_func>>>>());
905 }
907
908
909
917 class YF_API FormContextHandler
918 : private ystdex::equality_comparable<FormContextHandler>
919 {
920 public:
921 ContextHandler Handler;
923
924
928 size_t Wrapping;
929
931 template<typename _func,
932 yimpl(typename = ystdex::exclude_self_t<FormContextHandler, _func>)>
933 FormContextHandler(_func&& f, size_t n = 0)
934 : Handler(A1::WrapContextHandler<ContextHandler>(yforward(f))),
935 Wrapping(n)
936 {}
938 template<typename _func, class _tAlloc>
939 FormContextHandler(std::allocator_arg_t, const _tAlloc& a, _func&& f,
940 size_t n = 0)
941 : Handler(std::allocator_arg, a, A1::WrapContextHandler<ContextHandler>(
942 yforward(f), a)), Wrapping(n)
943 {}
945 DefDeCopyMoveCtorAssignment(FormContextHandler)
947
948
953 YB_ATTR_nodiscard YB_PURE friend PDefHOp(bool, ==,
954 const FormContextHandler& x, const FormContextHandler& y)
955 ImplRet(x.Equals(y))
956
972 PDefHOp(ReductionStatus, (), TermNode& term, ContextNode& ctx) const
973 ImplRet(CallN(Wrapping, term, ctx))
974
975 private:
977 ReductionStatus
978 CallN(size_t, TermNode&, ContextNode&) const;
979
981 YB_ATTR_nodiscard YB_PURE bool
982 Equals(const FormContextHandler&) const;
983
984 public:
986 friend DefSwap(ynothrow, FormContextHandler, (swap(_x.Handler, _y.Handler),
987 std::swap(_x.Wrapping, _y.Wrapping)))
988 };
989
990
992
993
997 enum WrappingKind : decltype(FormContextHandler::Wrapping)
998 {
1000 Form = 0,
1002 Strict = 1
1003 };
1004
1005
1010 template<size_t _vWrapping = Strict, class _tTarget, typename... _tParams>
1012 inline void
1013 RegisterHandler(_tTarget& target, string_view name, _tParams&&... args)
1014 {
1015 NPL::EmplaceLeaf<ContextHandler>(target, name,
1016 FormContextHandler(yforward(args)..., _vWrapping));
1017 }
1019
1025 template<class _tTarget, typename... _tParams>
1027 inline void
1028 RegisterForm(_tTarget& target, string_view name, _tParams&&... args)
1029 {
1030 A1::RegisterHandler<Form>(target, name, yforward(args)...);
1031 }
1032
1034 template<class _tTarget, typename... _tParams>
1035 inline void
1036 RegisterStrict(_tTarget& target, string_view name, _tParams&&... args)
1037 {
1038 A1::RegisterHandler<>(target, name, yforward(args)...);
1039 }
1041
1042
1049 YB_ATTR_nodiscard YB_PURE inline
1050 PDefH(size_t, FetchArgumentN, const TermNode& term) ynothrowv
1051 ImplRet(AssertBranch(term), term.size() - 1)
1052
1053
1054
1071 YF_API ReductionStatus
1072 DefaultEvaluateLeaf(TermNode&, string_view);
1073
1075
1076
1104 YF_API ReductionStatus
1105 EvaluateIdentifier(TermNode&, const ContextNode&, string_view);
1106
1125 YF_API ReductionStatus
1126 EvaluateLeafToken(TermNode&, ContextNode&, string_view);
1128
1135 inline PDefH(void, EvaluateLiteralHandler, TermNode& term,
1136 const ContextNode& ctx, const TermNode& tm)
1137 // NOTE: This is optional, as it is not guaranteed to be saved as
1138 // %ContextHandler in %ReduceCombined.
1139 ImplExpr([&]{
1140 if(const auto p_handler = NPL::TryAccessTerm<const LiteralHandler>(tm))
1141 RegularizeTerm(term, (*p_handler)(ctx));
1142 }())
1143
1148 YB_ATTR_nodiscard YB_PURE inline PDefH(bool, IsCombiningTerm,
1149 const TermNode& term) ynothrow
1150 ImplRet(!(term.empty() || (term.Value
1151 && term.Value.type() != ystdex::type_id<TokenValue>())))
1152
1153
1171 YF_API ReductionStatus
1172 ReduceCombined(TermNode&, ContextNode&);
1173
1179 YF_API ReductionStatus
1180 ReduceCombinedBranch(TermNode&, ContextNode&);
1181
1187 YB_FLATTEN inline PDefH(ReductionStatus, ReduceNextCombinedBranch,
1188 TermNode& term, ContextState& cs)
1189 ImplRet(cs.SetNextTermRef(term), ReduceCombinedBranch(term, cs))
1190
1196 YF_API ReductionStatus
1197 ReduceCombinedReferent(TermNode&, ContextNode&, const TermNode&);
1199
1210 YF_API ReductionStatus
1211 ReduceLeafToken(TermNode&, ContextNode&);
1213
1214
1216
1217
1222 using EnvironmentGuard = ystdex::guard<EnvironmentSwitcher>;
1223
1224
1239 YF_API ReductionStatus
1240 RelayForEval(ContextNode&, TermNode&, EnvironmentGuard&&, bool, Continuation);
1241
1247 YF_API ReductionStatus
1248 RelayForCall(ContextNode&, TermNode&, EnvironmentGuard&&, bool);
1250
1251
1252
1254
1255
1260 template<typename _func>
1262 auto
1263 CheckSymbol(string_view n, _func f) -> decltype(f())
1264 {
1265 if(IsNPLASymbol(n))
1266 return f();
1267 throw ParameterMismatch(ystdex::sfmt(
1268 "Invalid token '%s' found for symbol parameter.", n.data()));
1269 }
1270
1272 template<typename _func>
1273 auto
1274 CheckParameterLeafToken(string_view n, _func f) -> decltype(f())
1275 {
1276 if(n != "#ignore")
1277 CheckSymbol(n, f);
1278 }
1280
1322 YF_API void
1323 MatchParameter(const TermNode&, TermNode&, function<void(TermNode&, TNIter,
1324 const TokenValue&, TermTags, const EnvironmentReference&)>, function<
1325 void(const TokenValue&, TermNode&, TermTags, const EnvironmentReference&)>,
1326 TermTags, const EnvironmentReference&);
1327
1354 YF_API void
1355 BindParameter(const shared_ptr<Environment>&, const TermNode&, TermNode&);
1357
1358
1359
1374 YF_API void
1375 SetupDefaultInterpretation(ContextState&, EvaluationPasses);
1376
1382 YF_API void
1383 SetupTailContext(ContextNode&, TermNode&);
1384
1385
1391 template<typename _fParse>
1393 using GParsedValue = typename ParseResultOf<_fParse>::value_type;
1394
1396 template<typename _fParse>
1397 using GTokenizer = function<TermNode(const GParsedValue<_fParse>&)>;
1399
1404 using Tokenizer = GTokenizer<ByteParser>;
1405
1407 using SourcedTokenizer = GTokenizer<SourcedByteParser>;
1408
1409
1420 YB_ATTR_nodiscard YF_API bool
1421 AddTypeNameTableEntry(const ystdex::type_info&, string_view);
1422
1427 template<typename _type>
1428 inline void
1429 InitializeTypeNameTableEntry(string_view desc)
1430 {
1431 YAssertNonnull(desc.data());
1432
1433 static struct Init final
1434 {
1435 Init(string_view sv)
1436 {
1437 const auto res(AddTypeNameTableEntry(ystdex::type_id<_type>(), sv));
1438
1439 yunused(res);
1440 YAssert(res, "Duplicated name found.");
1441 }
1442 } init(desc);
1443 }
1444
1446 template<class _tTarget, typename _func, typename _fCallable>
1447 YB_ATTR_nodiscard YB_PURE inline _fCallable
1448 NameExpandedHandler(_fCallable&& x, string_view desc)
1449 {
1450 static_assert(std::is_constructible<_tTarget, _fCallable>(),
1451 "Invalid callable type found.");
1452 using expanded_t = ystdex::expanded_caller<_func, _fCallable>;
1453
1454 A1::InitializeTypeNameTableEntry<ystdex::cond_t<ystdex::and_<
1455 ystdex::not_<std::is_constructible<function<_func>, _fCallable>>,
1456 std::is_constructible<expanded_t, _fCallable>>,
1457 expanded_t, ystdex::remove_cvref_t<_fCallable>>>(desc);
1458 return yforward(x);
1459 }
1460
1462 template<typename _fCallable>
1463 YB_ATTR_nodiscard YB_PURE inline _fCallable
1464 NameTypedContextHandler(_fCallable&& x, string_view desc)
1465 {
1466 return A1::NameExpandedHandler<ContextHandler,
1467 ContextHandler::FuncType>(yforward(x), desc);
1468 }
1469
1471 template<typename _type>
1472 YB_ATTR_nodiscard YB_PURE inline _type
1473 NameTypedObject(_type&& x, string_view desc)
1474 {
1475 InitializeTypeNameTableEntry<ystdex::remove_cvref_t<_type>>(desc);
1476 return yforward(x);
1477 }
1478
1480 template<typename _fCallable>
1481 YB_ATTR_nodiscard YB_PURE inline _fCallable
1482 NameTypedReducerHandler(_fCallable&& x, string_view desc)
1483 {
1484 return A1::NameExpandedHandler<Reducer,
1485 ReducerFunctionType>(yforward(x), desc);
1486 }
1488
1504 YB_ATTR_nodiscard YB_PURE YF_API string_view
1505 QueryContinuationName(const Reducer&);
1506
1511 YB_ATTR_nodiscard YB_PURE YF_API observer_ptr<const SourceInformation>
1512 QuerySourceInformation(const ValueObject&);
1513
1521 YB_ATTR_nodiscard YB_PURE YF_API observer_ptr<const ValueObject>
1522 QueryTailOperatorName(const Reducer&);
1523
1528 YB_ATTR_nodiscard YB_PURE YF_API string_view
1529 QueryTypeName(const ystdex::type_info&);
1530
1541 YF_API bool
1542 SetupTailOperatorName(TermNode&, const ContextNode&);
1543
1544
1545 /*
1546 \brief REPL 上下文。
1547 \warning 非虚析构。
1548 \since build 740
1549
1550 REPL 表示读取-求值-输出循环。
1551 每个循环包括一次翻译。
1552 这只是一个基本的可扩展实现。功能通过操作数据成员控制。
1553 */
1554 class YF_API REPLContext
1555 {
1556 public:
1558
1559 enum LoadOption
1561 {
1563 Contextual,
1565 WithSourceLocation,
1567 NoSourceInformation
1568 };
1570 template<LoadOption _vOpt = Contextual>
1571 using LoadOptionTag = std::integral_constant<LoadOption, _vOpt>;
1573
1579 using Loader = function<TermNode(REPLContext&, ContextNode&, string)>;
1580
1581 private:
1582 struct LeafConverter final
1583 {
1584 const REPLContext& Context;
1585
1586 PDefHOp(TermNode, (), const GParsedValue<ByteParser>& val) const
1587 ImplRet(Context.ConvertLeaf(val))
1588 PDefHOp(TermNode, (), const GParsedValue<SourcedByteParser>& val) const
1589 ImplRet(Context.ConvertLeafSourced(val))
1590 };
1591
1592 public:
1597 TermNode::allocator_type Allocator;
1602 ContextState Root;
1612 TermPasses::HandlerType Preprocess{std::allocator_arg, Allocator};
1614
1615
1619 Tokenizer ConvertLeaf;
1624 SourcedTokenizer ConvertLeafSourced;
1626 SourceName CurrentSource{};
1631 bool UseSourceLocation = {};
1633
1640 Loader Load{DefaultLoad};
1641
1652 REPLContext(pmr::memory_resource& = NPL::Deref(pmr::new_delete_resource()));
1657 REPLContext(Tokenizer, SourcedTokenizer,
1658 pmr::memory_resource& = NPL::Deref(pmr::new_delete_resource()));
1660
1668 YB_STATELESS bool
1669 IsAsynchronous() const ynothrow;
1670
1679 YB_ATTR_nodiscard static TermNode
1680 DefaultLoad(REPLContext&, ContextNode&, string);
1681
1682 private:
1684 template<typename _tParam>
1685 YB_ATTR_nodiscard inline ContextNode&
1686 FetchContextParameter(_tParam&&)
1687 {
1688 return Root;
1689 }
1691 template<typename... _tParams>
1692 YB_ATTR_nodiscard inline ContextNode&
1693 FetchContextParameter(NPL::tuple<_tParams..., ContextNode&> args)
1694 {
1695 return NPL::get<sizeof...(_tParams)>(args);
1696 }
1697
1698 public:
1706
1708 template<typename... _tParams>
1709 inline void
1710 LoadFrom(_tParams&&... args)
1711 {
1712 auto term(ReadFrom(yforward(args)...));
1713
1714 Reduce(term,
1715 FetchContextParameter(NPL::forward_as_tuple(yforward(args)...)));
1716 }
1718
1720 template<typename... _tParams>
1721 // XXX: No %YB_ATTR_nodiscard.
1722 inline TermNode
1723 Perform(_tParams&&... args)
1724 {
1725 auto term(ReadFrom(yforward(args)...));
1726
1727 Reduce(term,
1728 FetchContextParameter(NPL::forward_as_tuple(yforward(args)...)));
1729 return term;
1730 }
1732
1743 YB_ATTR_nodiscard PDefH(TermNode, Prepare, TermNode&& term) const
1744 ImplRet(Preprocess(term), std::move(term))
1749 template<typename... _tParams>
1750 YB_ATTR_nodiscard TermNode
1751 Prepare(_tParams&&... args) const
1752 {
1753 return Prepare(SContext::Analyze(std::allocator_arg, Allocator,
1754 LeafConverter{*this}, yforward(args)...));
1755 }
1757
1765 template<class _type>
1766 YB_ATTR_nodiscard inline TermNode
1767 ReadFrom(_type&& input)
1768 {
1769 return ReadFrom(yforward(input), Root);
1770 }
1772 template<class _type>
1773 YB_ATTR_nodiscard inline TermNode
1774 ReadFrom(_type&& input, ReaderState& rs)
1775 {
1776 return ReadFrom(yforward(input), rs, Root);
1777 }
1778 template<class _type>
1779 YB_ATTR_nodiscard inline TermNode
1780 ReadFrom(_type&& input, ContextNode& ctx) const
1781 {
1782 return ReadFrom(LoadOptionTag<>(), yforward(input), ctx);
1783 }
1785 template<class _type>
1786 YB_ATTR_nodiscard inline TermNode
1787 ReadFrom(_type&& input, ReaderState& rs, ContextNode& ctx) const
1788 {
1789 return ReadFrom(LoadOptionTag<>(), yforward(input), rs, ctx);
1790 }
1791 template<LoadOption _vOpt, class _type>
1792 YB_ATTR_nodiscard inline TermNode
1793 ReadFrom(LoadOptionTag<_vOpt> opt, _type&& input)
1794 {
1795 return ReadFrom(opt, yforward(input), Root);
1796 }
1798 template<LoadOption _vOpt, class _type>
1799 YB_ATTR_nodiscard inline TermNode
1800 ReadFrom(LoadOptionTag<_vOpt> opt, _type&& input, ReaderState& rs)
1801 {
1802 return ReadFrom(opt, yforward(input), rs, Root);
1803 }
1808 template<LoadOption _vOpt, typename... _tParams>
1809 YB_ATTR_nodiscard TermNode
1810 ReadFrom(LoadOptionTag<_vOpt> opt, std::istream& is, _tParams&&... args)
1811 const
1812 {
1813 if(is)
1814 {
1815 if(const auto p = is.rdbuf())
1816 return ReadFrom(opt, *p, yforward(args)...);
1817 throw std::invalid_argument("Invalid stream buffer found.");
1818 }
1819 else
1820 throw std::invalid_argument("Invalid stream found.");
1821 }
1822 YB_ATTR_nodiscard TermNode
1823 ReadFrom(LoadOptionTag<>, std::streambuf&, ContextNode&) const;
1825 YB_ATTR_nodiscard TermNode
1826 ReadFrom(LoadOptionTag<>, std::streambuf&, ReaderState&, ContextNode&)
1827 const;
1828 YB_ATTR_nodiscard TermNode
1829 ReadFrom(LoadOptionTag<WithSourceLocation>, std::streambuf&, ContextNode&)
1830 const;
1832 YB_ATTR_nodiscard TermNode
1833 ReadFrom(LoadOptionTag<WithSourceLocation>, std::streambuf&, ReaderState&,
1834 ContextNode&) const;
1835 YB_ATTR_nodiscard TermNode
1836 ReadFrom(LoadOptionTag<NoSourceInformation>, std::streambuf&, ContextNode&)
1837 const;
1839 YB_ATTR_nodiscard TermNode
1840 ReadFrom(LoadOptionTag<NoSourceInformation>, std::streambuf&, ReaderState&,
1841 ContextNode&) const;
1843
1844 YB_ATTR_nodiscard TermNode
1845 ReadFrom(LoadOptionTag<>, string_view, ContextNode&) const;
1846 YB_ATTR_nodiscard TermNode
1847 ReadFrom(LoadOptionTag<WithSourceLocation>, string_view, ContextNode&)
1848 const;
1849 YB_ATTR_nodiscard TermNode
1850 ReadFrom(LoadOptionTag<NoSourceInformation>, string_view, ContextNode&)
1851 const;
1853
1854
1859 template<typename... _tParams>
1860 void
1861 ShareCurrentSource(_tParams&&... args)
1862 {
1863 CurrentSource
1864 = YSLib::allocate_shared<string>(Allocator, yforward(args)...);
1865 }
1866 };
1867
1875 template<typename... _tParams>
1876 YB_NONNULL(2) void
1877 TryLoadSource(REPLContext& context, const char* name, _tParams&&... args)
1878 {
1879 TryExpr(context.LoadFrom(yforward(args)...))
1880 CatchExpr(..., std::throw_with_nested(NPLException(
1881 ystdex::sfmt("Failed loading external unit '%s'.", name))));
1882 }
1883
1884 } // namesapce A1;
1885
1886 } // namespace NPL;
1887
1888 #endif
1889
NPL::A1::Continuation::DefDeCopyMoveCtorAssignment
DefDeCopyMoveCtorAssignment(Continuation) YB_ATTR_nodiscard YB_STATELESS friend PDefHOp(bool
NPL::SourceLocation
源代码位置。
Definition: Lexical.h:87
NPL::A1::ThrowValueCategoryErrorForFirstArgument
void ThrowValueCategoryErrorForFirstArgument(const TermNode &term)
Definition: NPLA1.cpp:790
cast.hpp
C++ 转换模板。
NPL::A1::ValueToken::Null
@ Null
NPL::A1::Continuation::allocator_type
decltype(std::declval< const ContextNode & >().get_allocator()) allocator_type
Definition: NPLA1.h:124
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:112
NPL::A1::RelayForEval
YF_API ReductionStatus RelayForEval(ContextNode &, TermNode &, EnvironmentGuard &&, bool, Continuation)
设置当前项并直接求值规约。
Definition: NPLA1.cpp:1430
NPL::A1::SourcedTokenizer
GTokenizer< SourcedByteParser > SourcedTokenizer
标记器：分析带有源代码位置信息的词素转换为可能包含记号的节点。
Definition: NPLA1.h:1406
NPL::ParameterMismatch
参数不匹配。
Definition: NPLA.h:575
NPL::A1::Tokenizer
GTokenizer< ByteParser > Tokenizer
标记器：分析词素转换为可能包含记号的节点。
Definition: NPLA1.h:1403
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
NPL::A1::Guard
any Guard
作用域守卫类型。
Definition: NPLA1.h:269
NPL::A1::REPLContext::LeafConverter
Definition: NPLA1.h:1582
NPL::A1::EvaluateIdentifier
YF_API ReductionStatus EvaluateIdentifier(TermNode &, const ContextNode &, string_view)
求值标识符。
Definition: NPLA1.cpp:1232
NPL::A1::ReduceArguments
PDefH(ReductionStatus, Continuation::operator(), ContextNode &ctx) const ImplRet(Handler(ContextState YF_API void ReduceArguments(TNIter, TNIter, ContextNode &)
NPLA1 表达式节点规约：调用至少一次求值例程规约子表达式。
Definition: NPLA1.cpp:904
NPL::A1::ReduceCombined
ReductionStatus ReduceCombined(TermNode &term, ContextNode &ctx)
Definition: NPLA1.cpp:1307
NPL::YAssert
YB_ATTR_nodiscard YB_PURE yconstfn YAssert(!buf.empty(), "Invalid buffer found.")
NPL::A1::PDefH
YB_NORETURN PDefH(void, ThrowUnsupportedLiteralError, string_view sv) ImplExpr(ThrowUnsupportedLiteralError(sv.data())) YB_NORETURN YF_API void ThrowValueCategoryErrorForFirstArgument(const TermNode &)
抛出第一参数不符合预期值类别的异常。
NPL::A1::ContextState::ImplRet
ContextNode &ctx ynothrowv ImplRet(ystdex::polymorphic_downcast< ContextState & >(ctx)) YB_ATTR_nodiscard YB_PURE static PDefH(const ContextState &
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:488
NPL::A1::ReduceTail
ContextNode &YF_API ReductionStatus ReduceTail(TermNode &, ContextNode &, TNIter)
移除容器第一个子项到指定迭代器的项后规约。
Definition: NPLA1.cpp:990
NPL::A1::ThrowInsufficientTermsError
YB_NORETURN YF_API void ThrowInsufficientTermsError()
抛出缺少项的异常。
Definition: NPLA1.cpp:759
NPL::A1::WrapContextHandler
YB_ATTR_nodiscard YB_PURE _tDst WrapContextHandler(_func &&h, ystdex::false_)
Definition: NPLA1.h:850
NPL::ReductionStatus::Neutral
@ Neutral
中立规约：规约成功终止，且未指定是否需要保留子项。
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
NPL::A1::ValueToken::OrderedAnchor
@ OrderedAnchor
NPL::A1::FormContextHandler::FormContextHandler
FormContextHandler(_func &&f, size_t n=0)
Definition: NPLA1.h:933
ystdex::make_function_type_t
_t< make_function_type< _tRet, _tTuple > > make_function_type_t
Definition: function.hpp:391
NPL::A1::ReduceCombinedReferent
ReductionStatus ReduceCombinedReferent(TermNode &term, ContextNode &ctx, const TermNode &fm)
Definition: NPLA1.cpp:1399
ystdex::split
void split(_tIn b, _tIn e, _fPred is_delim, _fInsert insert)
以指定分隔符分割序列。
Definition: algorithm.hpp:291
ystdex::retry_on_cond
invoke_result_t< _fCallable, _tParams... > retry_on_cond(_fCond cond, _fCallable &&f, _tParams &&... args)
循环重复调用：代替直接使用 do-while 语句以避免过多引入作用域外的变量。
Definition: functional.hpp:554
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::A1::Continuation::Continuation
Continuation(Continuation &&cont, allocator_type a)
Definition: NPLA1.h:147
NPL::A1::ParseLeaf
YF_API TermNode ParseLeaf(string_view, TermNode::allocator_type)
分析参数指定的叶节点词素。
Definition: NPLA1.cpp:1073
NPL::A1::Internals::term
_fCurrent TermNode &decltype(cur(term, ctx)) term
Definition: NPLA1Internals.h:593
NPL::A1::NPLA1Tag
NPLA1 元标签。
Definition: NPLA1.h:64
NPL::A1::WrappedContextHandler
包装上下文处理器。
Definition: NPLA1.h:813
NPL::A1::EvaluationPasses
GPasses< TermNode &, ContextNode & > EvaluationPasses
求值合并遍。
Definition: NPLA1.h:258
NPL::ReducerFunctionType
ReductionStatus(ContextNode &) ReducerFunctionType
规约器函数原型。
Definition: NPLA.h:2340
NPL::A1::ContextState
NPLA1 上下文状态。
Definition: NPLA1.h:288
NPL::ReaderState
读取器状态：支持解析一个记号或列表的解析器的辅助状态。
Definition: SContext.h:762
NPL::A1::BindParameter
YF_API void BindParameter(const shared_ptr< Environment > &, const TermNode &, TermNode &)
使用操作数结构化匹配并绑定参数。
Definition: NPLA1.cpp:1463
NPL::A1::MatchParameter
YF_API void MatchParameter(const TermNode &, TermNode &, function< void(TermNode &, TNIter, const TokenValue &, TermTags, const EnvironmentReference &)>, function< void(const TokenValue &, TermNode &, TermTags, const EnvironmentReference &)>, TermTags, const EnvironmentReference &)
匹配参数。
Definition: NPLA1.cpp:1452
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:265
NPL::A1::ParseLeafWithSourceInformation
YF_API TermNode ParseLeafWithSourceInformation(string_view, const shared_ptr< string > &, const SourceLocation &, TermNode::allocator_type)
分析参数指定的带有源代码信息和叶节点词素。
Definition: NPLA1.cpp:1109
YB_FLATTEN
#define YB_FLATTEN
标记函数尽可能内联定义内的调用。
Definition: ydef.h:843
TermTags
TermTags
标签：表示引用元数据的位。
Definition: SContext.h:108
ystdex::exclude_self_params_t
enable_if_t< not_< cond_or_t< bool_< sizeof...(_tParams)==1 >, false_, is_same_param, _tSelected, _tParams... > >::value, void > exclude_self_params_t
排除选择类型的特定参数类型的重载。
Definition: type_op.hpp:295
NPL::A1::REPLContext::Loader
function< TermNode(REPLContext &, ContextNode &, string)> Loader
加载器。
Definition: NPLA1.h:1578
NPL::A1::ContextState::~ContextState
~ContextState() override
虚析构：类定义外默认实现。
NPL::A1::ThrowInvalidSyntaxError
YB_NORETURN YF_API void ThrowInvalidSyntaxError(string_view)
Definition: NPLA1.cpp:770
next
tidy_ptr< slink > next
Definition: memory_resource.cpp:223
NPL::A1::ContextHandler
YSLib::GHEvent< ReductionStatus(TermNode &, ContextNode &)> ContextHandler
上下文处理器类型。
Definition: NPLA1.h:72
pfx
ValueObject pfx
Definition: NPLA1.cpp:363
NPL::A1::ValueToken::Undefined
@ Undefined
未定义值。
NPL::A1::NameTypedObject
YB_ATTR_nodiscard YB_PURE _type NameTypedObject(_type &&x, string_view desc)
初始化全局类型名称表项并转发参数。
Definition: NPLA1.h:1472
NPL::ReductionStatus::Clean
@ Clean
纯值规约：规约成功终止，且要求最终清理子项。
YF_API
#define YF_API
Definition: Platform.h:56
NPL::A1::WrappedContextHandler::Handler
_func Handler
Definition: NPLA1.h:815
NPL::A1::TransformNode
YF_API ValueNode TransformNode(const TermNode &)
变换 NPLA1 节点 S 表达式抽象语法树为 NPLA1 语义结构。
Definition: NPLA1.cpp:1035
NPL::A1::Form
@ Form
一般形式：不对参数求值。
Definition: NPLA1.h:1000
NPL::A1::Reduce
ReductionStatus Reduce(TermNode &term, ContextNode &ctx)
Definition: NPLA1.cpp:898
NPL::A1::DefaultEvaluateLeaf
ReductionStatus DefaultEvaluateLeaf(TermNode &term, string_view id)
Definition: NPLA1.cpp:1189
NPL::A1::RegisterForm
void RegisterForm(_tTarget &target, string_view name, _tParams &&... args)
注册一般形式上下文处理器。
Definition: NPLA1.h:1028
NPL::A1::SeparatorTransformer::AddRange
YB_ATTR_nodiscard TermNode AddRange(_func add_range, _tTerm &&term, const ValueObject &pfx, _fPred filter) const
Definition: NPLA1.h:726
CHRLib::f
f(d, s)
NPL::A1::EvaluateLeafToken
YF_API ReductionStatus EvaluateLeafToken(TermNode &, ContextNode &, string_view)
求值叶节点记号。
Definition: NPLA1.cpp:1284
NPL::yunused
yunused(msg)
NPL::A1::ReduceChildren
term ctx YF_API void ReduceChildren(TNIter, TNIter, ContextNode &)
规约子项。
Definition: NPLA1.cpp:916
NPL::A1::ValueToken::Unspecified
@ Unspecified
未指定值。
ystdex::pmr::cpp2017::new_delete_resource
memory_resource * new_delete_resource()
Definition: memory_resource.cpp:64
NPL::A1::RelayForCall
YF_API ReductionStatus RelayForCall(ContextNode &, TermNode &, EnvironmentGuard &&, bool)
函数调用规约（ β-规约）。
Definition: NPLA1.cpp:1441
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: meta.hpp:196
NPL::A1::QueryContinuationName
YB_ATTR_nodiscard YB_PURE YF_API string_view QueryContinuationName(const Reducer &)
查询续延中的名称信息。
Definition: NPLA1.cpp:1616
ystdex::fast_any_of
bool fast_any_of(_tIn first, _tIn last, _fPred pred)
Definition: algorithm.hpp:99
NPL::A1::REPLContext::LoadOption
LoadOption
代码加载选项。
Definition: NPLA1.h:1560
NPL::A1::ThrowNonmodifiableErrorForAssignee
YB_NORETURN YF_API void ThrowNonmodifiableErrorForAssignee()
抛出被赋值操作数不可修改的异常。
Definition: NPLA1.cpp:776
NPL::A1::GParsedValue
typename ParseResultOf< _fParse >::value_type GParsedValue
解析结果元素类型。
Definition: NPLA1.h:1392
NPL::A1::QuerySourceInformation
YB_ATTR_nodiscard YB_PURE YF_API observer_ptr< const SourceInformation > QuerySourceInformation(const ValueObject &)
查询对象中的源代码信息。
Definition: NPLA1.cpp:1639
TNIter
TermNode::iterator TNIter
Definition: SContext.h:501
NPL::A1::CheckSymbol
auto CheckSymbol(string_view n, _func f) -> decltype(f())
检查记号值是符合匹配条件的符号。
Definition: NPLA1.h:1262
NPL::A1::ReduceCombinedBranch
YF_API ReductionStatus ReduceCombinedBranch(TermNode &, ContextNode &)
规约列表合并项：同 ReduceCombined ，但只适用于枝节点。
Definition: NPLA1.cpp:1314
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:877
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:405
ystdex::or_
逻辑或。
Definition: integral_constant.hpp:172
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
NPL::A1::PassesCombiner::operator()
YB_ATTR_nodiscard YB_PURE ReductionStatus operator()(_tIn first, _tIn last) const
Definition: NPLA1.h:231
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::A1::Continuation::Handler
ContextHandler Handler
Definition: NPLA1.h:126
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:1068
NPL::A1::WrappingKind
WrappingKind
包装数种类枚举。
Definition: NPLA1.h:998
ystdex::cpp2017::data
auto data(_tRange &c) -> decltype(c.data())
Definition: range.hpp:581
DefSwap
#define DefSwap(_q, _t,...)
定义交换函数。
Definition: YBaseMacro.h:302
filter
Filter filter
Definition: NPLA1.cpp:360
NPL::A1::NameExpandedHandler
YB_ATTR_nodiscard YB_PURE _fCallable NameExpandedHandler(_fCallable &&x, string_view desc)
初始化作为扩展调用者的全局类型名称表项并转发参数。
Definition: NPLA1.h:1447
scope_guard.hpp
作用域守卫。
NPL::NPLException
NPL 异常基类。
Definition: NPLA.h:445
NPL::EnvironmentReference
环境引用计数检查支持。
Definition: NPLA.h:986
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
NPL::A1::RegisterStrict
void RegisterStrict(_tTarget &target, string_view name, _tParams &&... args)
注册严格上下文处理器。
Definition: NPLA1.h:1036
YSLib::AreEqualHeld
YB_ATTR_nodiscard YB_PURE yconstfn bool AreEqualHeld(const _type1 &x, const _type2 &y)
判断动态泛型的持有值是否相等。
Definition: YObject.h:252
NPL::A1::PassesCombiner
遍合并器：逐次调用序列中的遍直至成功。
Definition: NPLA1.h:224
YSLib::GHEvent< ReductionStatus(TermNode &, ContextNode &)>
NPL::A1::REPLContext
Definition: NPLA1.h:1554
NPL::A1::ReduceChildrenOrdered
term ctx YF_API ReductionStatus ReduceChildrenOrdered(TNIter, TNIter, ContextNode &)
有序规约子项。
Definition: NPLA1.cpp:934
NPL::A1::ValueToken::GroupingAnchor
@ GroupingAnchor
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:73
std
Definition: optional.h:982
ystdex::sfmt
_tString sfmt(const typename string_traits< _tString >::value_type *fmt,...)
以 C 标准输出格式的输出 basic_string 实例的对象。
Definition: string.hpp:2028
YSLib::GCombinerInvoker
结果组合调用器。
Definition: YEvent.hpp:431
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:165
NPL::A1::SeparatorTransformer::ReplaceChildren
static void ReplaceChildren(TermNode &term, const ValueObject &pfx, _fPred filter)
找到子项符合过滤条件的并替换项为添加替换前缀的形式。
Definition: NPLA1.h:761
NPL::ReductionStatus::Retrying
@ Retrying
重规约。
NPL::A1::AddTypeNameTableEntry
YB_ATTR_nodiscard YF_API bool AddTypeNameTableEntry(const ystdex::type_info &, string_view)
添加全局类型名称表项。
Definition: NPLA1.cpp:1605
NPL::A1::WrappedContextHandler::DefDeCopyMoveCtorAssignment
DefDeCopyMoveCtorAssignment(WrappedContextHandler) template< typename... _tParams > ReductionStatus operator()(_tParams &&... args) const
Definition: NPLA1.h:824
NPL::A1::InsertChild
YF_API void InsertChild(ValueNode &&, ValueNode::Container &)
插入 NPLA1 子节点。
Definition: NPLA1.cpp:1028
NPL::A1::Continuation::Continuation
Continuation(_func &&handler, const ContextNode &ctx)
Definition: NPLA1.h:140
YSLib::i
return i
Definition: YCoreUtilities.h:177
NPL::A1::FormContextHandler::Handler
ContextHandler Handler
Definition: NPLA1.h:921
NPL::A1::ContextState::swap
friend swap(x.combining_term_ptr, y.combining_term_ptr)
NPL::A1::SetupTailContext
YF_API void SetupTailContext(ContextNode &, TermNode &)
设置参数指定的上下文为尾上下文。
Definition: NPLA1.cpp:1594
NPL::EnvironmentSwitcher
环境切换器。
Definition: NPLA.h:3068
NPL::A1::to_string
string to_string(ValueToken vt)
Definition: NPLA1.cpp:66
NPL::A1::WrappedContextHandler::WrappedContextHandler
WrappedContextHandler(_tParams &&... args)
Definition: NPLA1.h:820
NPL::A1::SeparatorTransformer
中缀分隔符变换器。
Definition: NPLA1.h:686
NPL
Definition: NPL/Configuration.h:35
NPL::A1::InitializeTypeNameTableEntry
void InitializeTypeNameTableEntry(string_view desc)
初始化全局类型名称表项。
Definition: NPLA1.h:1428
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::ref_eq
引用等价关系仿函数。
Definition: functor.hpp:450
NPL::A1::CheckParameterLeafToken
auto CheckParameterLeafToken(string_view n, _func f) -> decltype(f())
检查记号值是符合匹配条件的参数符号。
Definition: NPLA1.h:1273
NPL::A1::SetupTailOperatorName
YF_API bool SetupTailOperatorName(TermNode &, const ContextNode &)
设置当前尾动作规约的操作符名称。
Definition: NPLA1.cpp:1674
NPL::A1::NameTypedContextHandler
YB_ATTR_nodiscard YB_PURE _fCallable NameTypedContextHandler(_fCallable &&x, string_view desc)
初始化作为上下文处理器的全局类型名称表项并转发参数。
Definition: NPLA1.h:1463
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
NPL::RegularizeTerm
YF_API ReductionStatus RegularizeTerm(TermNode &, ReductionStatus) ynothrow
按规约结果正规化项。
Definition: NPLA.cpp:686
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
ystdex::make_parameter_list_t
_t< make_parameter_list< _fCallable > > make_parameter_list_t
Definition: function.hpp:335
NPL::A1::FormContextHandler::FormContextHandler
FormContextHandler(std::allocator_arg_t, const _tAlloc &a, _func &&f, size_t n=0)
Definition: NPLA1.h:939
NPL::A1::NameTypedReducerHandler
YB_ATTR_nodiscard YB_PURE _fCallable NameTypedReducerHandler(_fCallable &&x, string_view desc)
初始化作为规约器处理器的全局类型名称表项并转发参数。
Definition: NPLA1.h:1481
ystdex::cond_t
_t< cond< _tCond, _tThen, _tElse > > cond_t
Definition: meta.hpp:794
ystdex::expanded_caller
接受冗余参数的可调用对象。
Definition: functional.hpp:574
YModules.h
YSLib 用户界面模块配置文件。
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
NPL::ParseResultOf
ystdex::detected_or_t< LexemeList, MemberParseResult, ParserClassOf< _fParse > > ParseResultOf
取解析器结果类型。
Definition: Lexical.h:449
Context
ContextNode & Context
Definition: NPLA1Forms.cpp:488
NPL::NPLATag
NPLA 元标签。
Definition: NPLA.h:82
NPL::ContextNode
上下文节点。
Definition: NPLA.h:2385
NPL::A1::name
const char * name
Definition: NPLA1.h:1876
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
NPL::A1::SetupTraceDepth
void SetupTraceDepth(ContextState &cs, const string &name)
Definition: NPLA1.cpp:999
NPL::A1::Continuation
NPLA1 一等续延。
Definition: NPLA1.h:120
NPL::A1::Continuation::ImplRet
const Continuation const Continuation &y ynothrow ImplRet(ystdex::ref_eq<>()(x, y)) ReductionStatus operator()(ContextNode &) const
NPL::A1::FormContextHandler
形式上下文处理器。
Definition: NPLA1.h:919
NPL::A1::RegisterHandler
void RegisterHandler(_tTarget &target, string_view name, _tParams &&... args)
注册一般形式上下文处理器。
Definition: NPLA1.h:1013
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
NPL::A1::ContextState::Access
Access
Definition: NPLA1.h:341
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
NPL::A1::Continuation::Continuation
Continuation(const Continuation &cont, allocator_type a)
Definition: NPLA1.h:143
NPL::A1::FormContextHandler::Wrapping
size_t Wrapping
包装数。
Definition: NPLA1.h:928
NPL::A1::end
term end()
NPL::A1::GTokenizer
function< TermNode(const GParsedValue< _fParse > &)> GTokenizer
泛型标记器：分析解析结果元素转换为可能包含记号的节点。
Definition: NPLA1.h:1396
ystdex::make_obj_using_allocator
_type make_obj_using_allocator(const _tAlloc &a, _tParams &&... args)
Definition: allocator.hpp:343
NPL::A1::SeparatorTransformer::Process
static YB_ATTR_nodiscard TermNode Process(_tTerm &&term, const ValueObject &pfx, _fPred filter)
Definition: NPLA1.h:747
NPL::A1::SetupDefaultInterpretation
YF_API void SetupDefaultInterpretation(ContextState &, EvaluationPasses)
设置默认解释：解释使用的公共处理遍。
Definition: NPLA1.cpp:1546
NPL::A1::QueryTypeName
YB_ATTR_nodiscard YB_PURE YF_API string_view QueryTypeName(const ystdex::type_info &)
查询全局类型名称表。
Definition: NPLA1.cpp:1662
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
NPL::Access
YB_ATTR_nodiscard YB_PURE const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow ImplRet(!term.Value) using YSLib YB_ATTR_nodiscard YB_PURE _type & Access(TermNode &term)
Definition: SContext.h:555
NPL::A1::ContextState::DefDeCopyMoveAssignment
DefDeCopyMoveAssignment(ContextState) YB_ATTR_nodiscard YB_PURE static PDefH(ContextState &
访问实例。
NPL::A1::tm
tm
Definition: NPLA1.h:593
NPL::swap
void swap(ContextNode &x, ContextNode &y) ynothrow
Definition: NPLA.cpp:1188
platform::p
return p p
Definition: YCLib/FileSystem.h:209
NPL::A1::ValueToken
ValueToken
值记号：节点中的值的占位符。
Definition: NPLA1.h:83
NPL::A1::ReduceOrdered
ReductionStatus ReduceOrdered(TermNode &term, ContextNode &ctx)
Definition: NPLA1.cpp:965
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
NPL::AsTermNode
typename _tParams YB_ATTR_nodiscard YB_PURE ystdex::enable_if_t< ystdex::not_< ystdex::cond_or_t< ystdex::bool_<(sizeof...(_tParams) >=1)>, ystdex::false_, std::is_convertible, ystdex::decay_t< _tParams >..., TermNode::allocator_type > >::value, TermNode > AsTermNode(_tParams &&... args)
Definition: SContext.h:601
ystdex::not_
逻辑非。
Definition: integral_constant.hpp:193
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
NPL::A1::ReduceOnce
YF_API ReductionStatus ReduceOnce(TermNode &, ContextNode &)
NPLA1 表达式节点一次规约：转发调用到 NPLA1 表达式节点一次规约续延并调用。
Definition: NPLA1.cpp:959
NPL::A1::ThrowUnsupportedLiteralError
void ThrowUnsupportedLiteralError(const char *id)
Definition: NPLA1.cpp:782
NPL::A1::ReduceFirst
term ctx YF_API ReductionStatus ReduceFirst(TermNode &, ContextNode &)
规约第一个子项。
Definition: NPLA1.cpp:951
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
NPL::A1::REPLContext::LoadOptionTag
std::integral_constant< LoadOption, _vOpt > LoadOptionTag
代码加载选项标签类型。
Definition: NPLA1.h:1570
NPL::A1::Continuation::Continuation
Continuation(_func &&handler, allocator_type a)
Definition: NPLA1.h:133
NPL::A1::string_view
YB_ATTR_nodiscard YB_PURE term string_view
Definition: NPLA1.h:1072
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
ystdex::remove_cvref_t
_t< remove_cvref< _type > > remove_cvref_t
Definition: meta.hpp:236
NPL::A1::ReduceLeafToken
YB_FLATTEN ContextNode const TermNode &YF_API ReductionStatus ReduceLeafToken(TermNode &, ContextNode &)
规约提取名称的叶节点记号。
Definition: NPLA1.cpp:1411
NPL::yimpl
yimpl(using) Reducer
规约器：和绑定上下文以外参数的求值遍的处理器具有等价签名的多态函数。
NPL::A1::YB_NONNULL
YB_NORETURN YF_API YB_NONNULL(1) void ThrowInvalidSyntaxError(const char *)
抛出参数指定消息的语法错误异常。
NPL::SContext::Analyze
void Analyze(TermNode &root, const _tParseResult &parse_result)
分析指定源，取抽象语法树储存至指定值类型节点。
Definition: SContext.h:1127
NPL::A1::SeparatorTransformer::operator()
YB_ATTR_nodiscard TermNode operator()(_func trans, _tTerm &&term, const ValueObject &pfx, _fPred filter) const
最后两个参数分别指定替换添加的前缀和判断被替换的项的过滤条件。
Definition: NPLA1.h:691
NPL::ReductionStatus
ReductionStatus
规约状态：某个项上的一遍规约可能的中间结果。
Definition: NPLA.h:1520
NPL::A1::args
const char _tParams && args
Definition: NPLA1.h:1877
ystdex::cpp2017::begin
auto begin(_tRange &c) -> decltype(c.begin())
Definition: range.hpp:323
YSLib::UI::Styles::Handler
function< void(PaintEventArgs &&)> Handler
样式处理器。
Definition: YStyle.h:383
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
NPL::_tParam
_tParam
Definition: NPLA.h:2367
NPL::SourceName
shared_ptr< string > SourceName
可选的源代码名称。
Definition: Lexical.h:80
NPL::A1::QueryTailOperatorName
YB_ATTR_nodiscard YB_PURE YF_API observer_ptr< const ValueObject > QueryTailOperatorName(const Reducer &)
查询续延指定的当前尾动作规约的操作符名称项。
Definition: NPLA1.cpp:1649
ystdex::guard
作用域守卫：析构时调用保存的函数对象或引用。
Definition: scope_guard.hpp:48
NPL::A1::Strict
@ Strict
严格求值形式：对参数求值 1 次。
Definition: NPLA1.h:1002
ystdex::and_
逻辑操作元函数。
Definition: integral_constant.hpp:151
NPL::ImplRet
YB_ATTR_nodiscard YB_PURE PDefH(TermNode &, ReferenceTerm, TermNode &term) ynoexcept_spec(std YB_ATTR_nodiscard YB_PURE yconstfn const TermReference &ref ynothrow ImplRet(ref.IsMovable()) template< typename _tPointer > YB_ATTR_nodiscard YB_PURE inline auto IsMovable(_tPointer p) ynothrow -> decltype(!bool(p)||NPL::IsMovable(*p))
Definition: NPLA.h:1296
algorithm.hpp
泛型算法。