YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
SContext.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
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/SContext.h"
29 
30 using namespace YSLib;
31 
33 
34 Session::Session(const string& line)
35  : llex()
36 {
37  for(const auto& c : line)
38  llex.ParseByte(c);
39 }
41 {
43 
44  while(!tf.CheckEOF())
45  {
47  throw LoggedEvent("Bad Source!", 0x40);
48  llex.ParseByte(*i);
49  ++i;
50  }
51 }
52 
53 
54 YSL_BEGIN_NAMESPACE(SContext)
55 
56 TLCIter
58 {
59  while(b != e && *b != ")")
60  if(*b == "(")
61  {
62  auto res(Validate(++b, e));
63 
64  if(res == e || *res != ")")
65  throw LoggedEvent("Redundant '(' found.", 0x20);
66  b = ++res;
67  }
68  else
69  ++b;
70  return b;
71 }
72 
73 TLCIter
75 {
76  while(b != e && *b != ")")
77  if(*b == "(")
78  {
79  auto nd(MakeNode(to_string(node.GetSize())));
80  auto res(Reduce(nd, ++b, e));
81 
82  if(res == e || *res != ")")
83  throw LoggedEvent("Redundant '(' found.", 0x20);
84  node += std::move(nd);
85  b = ++res;
86  }
87  else
88  node += {0, to_string(node.GetSize()), *b++};
89  return b;
90 }
91 
92 void
93 Analyze(ValueNode& root, const TokenList& token_list)
94 {
95 #if 0
96  if(token_list.empty())
97  throw LoggedEvent("Empty token list found;", 0x20);
98 #endif
99  if(Validate(token_list.begin(), token_list.end()) != token_list.end())
100  throw LoggedEvent("Redundant ')' found.", 0x20);
101 
102  const auto res(Reduce(root, token_list.begin(), token_list.end()));
103 
104  yassume(res == token_list.end());
105 }
106 void
107 Analyze(ValueNode& root, const Session& session)
108 {
109  Analyze(root, session.GetTokenList());
110 }
111 void
112 Analyze(ValueNode& root, const string& unit)
113 {
114  Analyze(root, Session(unit).GetTokenList());
115 }
116 
117 YSL_END_NAMESPACE(SContext)
118 
120