YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Lexical.h
浏览该文件的文档.
1 /*
2  © 2012-2014 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 YF_INC_NPL_Lexical_h_
29 #define YF_INC_NPL_Lexical_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Adaptor_YContainer
33 #include <cctype> // for std::isgraph;
34 
35 namespace NPL
36 {
37 
39 
40 using ystdex::byte;
41 using YSLib::list;
42 using YSLib::string;
44 
71 {
72 public:
77  static yconstexpr size_t MaxEscapeLength = 8;
78 
79 private:
85  size_t esc;
90  char escs[MaxEscapeLength];
95  char ld;
99  string cbuf;
103  list<size_t> qlist;
104 
105 public:
106  LexicalAnalyzer();
107 
108  DefGetter(const ynothrow, const string&, Buffer, cbuf)
109  DefGetter(const ynothrow, const list<size_t>&, Quotes, qlist)
110 
111 private:
112  void
113  HandleEscape();
114 
115  void
116  PushEscape();
117 
118 public:
119  /*
120  \brief 解析单个字符并添加至字符解析结果。
121  */
122  void
123  ParseByte(byte);
124 
129  list<string>
130  Literalize() const;
131 };
132 
133 
140 YF_API char
141 CheckLiteral(const string&);
142 
148 YF_API string
149 Deliteralize(const string&);
150 
156 YF_API string
157 MakeEscape(const string&);
158 
159 
164 yconstfn bool
166 {
167 // return std::ispunct(c);
168  return c == '(' || c == ')' || c == ':' || c == ',' || c == ';'
169  || c == '#' || c == '%' || c == '!';
170 }
171 
176 yconstfn bool
178 {
179  return byte(c) < 0x80 && (!std::isgraph(c) || IsGraphicalDelimeter(c));
180 }
181 
182 
187 YF_API list<string>
188 Decompose(const string&);
189 
195 YF_API list<string>
196 Tokenize(const list<string>&);
197 
198 } // namespace NPL;
199 
200 #endif
201 
YF_API string MakeEscape(const string &)
转义字符串:替换指定字符串中的可转义字符。
Definition: Lexical.cpp:191
YF_API list< string > Tokenize(const list< string > &)
记号化:提取字符串列表中的记号。
Definition: Lexical.cpp:252
YF_API string Deliteralize(const string &)
去除字面量边界分隔符。
Definition: Lexical.cpp:185
char ld
字面分隔符状态:表示正在处理字面量中的有效字符。
Definition: Lexical.h:95
#define YF_API
Definition: Platform.h:64
unsigned char byte
字节类型。
Definition: ydef.h:555
yconstfn bool IsGraphicalDelimeter(char c)
判断是否为 NPL 图形分隔符。
Definition: Lexical.h:165
list< size_t > qlist
字符解析中间结果中非转义的引号出现的位置的有序列表。
Definition: Lexical.h:103
string cbuf
字符解析中间结果。
Definition: Lexical.h:99
词法分析器。
Definition: Lexical.h:70
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
YF_API list< string > Decompose(const string &)
分解字符串为记号。
Definition: Lexical.cpp:229
size_t esc
转义状态:表示是否正在处理的有效转义序列的长度。
Definition: Lexical.h:85
YF_API char CheckLiteral(const string &)
检查指定字符串是否为字面量。
Definition: Lexical.cpp:173
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
yconstfn bool IsDelimeter(char c)
判断是否为 NPL 分隔符。
Definition: Lexical.h:177
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462