Lua注释的解析方法
来源:互联网 发布:报纸数据库 编辑:程序博客网 时间:2024/05/21 02:36
之前实验室一个学长跟我一起研究lua的注释格式,特此写了一个lua的注释解析小代码练手,顺便练习递归文法解析。
lua注释格式为 -- XXXX +'\n'或者为 --[n个=[XXX]n个=]
--Lua注释解析--case1:从--开始 若--后面不为[ 则解析到\n为注释--case2:从--开始 若--后面为[ 则必须为[==[XXX]==]的形式 中间等号数相等可为O--str=[[ --[==[sadsadasdas]==] ]]function GetChar(i)return string.sub(str,i,i);endfunction StrMatch(i,j,pattern)return string.sub(s,i,j)==pattern;endfunction EscapeWhiteSpaces(i)local strlen=string.len(str);local e=i;while e<strlen doif GetChar(i)==' ' thene=e+1;elsebreak;endendendfunction EscapeComments(i)local strlen=string.len(str);if StrMatch(i,i+3,"--[") thenlocal e=i+3;if StrMatch(e,e+1,"[") thenlocal right="]"..string.sub(str,i+3,e).."]";local len=e-i-1;e=e+1;while e+len<= strlen and string.sub(str,e,e+len)==right doe=e+1;endif e+len>strlen thenprint("comment error!");elsereturn e+lenendelsewhile e<strlen and GetChar(e)~='\n' doe=e+1;endreturn e+1;endelselocal e=i+2;while e<strlen and GetChar(e)~='\n' doe=e+1;endreturn e+1;endendfunction Escape(i)local strlen=string.len(str);while i<strlen doi=EscapeWhiteSpaces(i);if StrMatch(i,i+2,"--") theni=EscapeComments(i);elsebreak;endendend
- Lua注释的解析方法
- lua的注释
- lua的注释
- cocos-Lua解析消息的方法
- 注释方法解析
- Lua多行注释和取消多行注释的方法
- 在Unity3d中解析Lua脚本的方法
- 在Unity3d中解析Lua脚本的方法
- lua注释
- Lua注释
- 【Lua】lua的解析技术有哪些?
- 注释块的方法
- perl的注释方法
- Android注释的方法
- matlab注释的方法
- JSP注释的方法
- 修改lua的代码解析
- 简单解析Lua的堆栈
- Android控件 动态初始化 动态加载 EditText显示光标 隐藏键盘
- Handler---Handler异步方式详解及其使用
- 排序算法之归并排序
- Android手机开发ubuntu系统中常用的搜索命令
- hdu 4649 Professor Tian
- Lua注释的解析方法
- 匈牙利命名法——命名规范(知道这些再看Windows程序就轻松多了)
- 网站关键词排名11位的五个原因
- poj 1979 搜索
- 约瑟夫环
- php获取正确的当前时间
- hdu 1086 You can Solve a Geometry Problem too 线段相交
- 非天然的链接的分析
- Easy Binary Compatible Interfaces Across Compilers in C++