yidabu 2007-5-5 08:23
用D语言正则表达式自动生成SciTe自动完成文件
用D语言正则表达式自动生成SciTe自动完成文件知识若不分享 实在没有意义 http://www.d-programming-language-china.org 20070504点击下面网址查看原文:http://www.d-programming-language-china.orgtag:d language ide,D语言IDE,d language tutorial 开始学习一门程序语言比较好的方式是用它来自动化一些小应用。 SciTe是非常好的文本编辑器,D语言IDe目前暂时没有,SciTE应该是最好的选择。这几天 http://bbs.d-programming-language-china.org刚好开始学习D语言正则表达式,就学着用D语言正则表达式来自动生成 SciTE自动完成文件。 [Copy to clipboard] [ - ]CODE: //比较完整的编辑器自动完成文件(使用正则自动提取) //D语言论坛 http://www.d-programming-language-china.org 提示: //使用时,只要更改help,api,lex的路径成你的实际即可。 //DMD 版本 1.014 import std.stdio : writefln; import std.file; //for read append import std.string : replace; import std.regexp; void main(char[][] args) { try { sciteApi(); } catch(Exception e) { printf("catch %.*s\n", e.msg); } } void sciteApi() { char[] help = r"D:\dmd\html\d\phobos\"; //标准库帮助文件所在目录 char[] api = r"D:\SciTe\api\d.api"; //自动完成文件,用于Scite或其他编辑器 char[] lex = r"D:\dmd\html\d\lex.html"; //用于取D语言关键词 //断言, assert(isdir(help),"help path wrong"); assert(isfile(api),"api path wrong"); assert(isfile(lex),"lex path wrong"); auto d_help_files = std.file.listdir(help, "*.html"); char[] source; //html源文件 char[] patternH1 = r"<h1>\s*(.+?[.].+?)\s*</h1>"; //匹配形如 std.file //匹配方法名字,包括返回值类型 //<dt><big>void[] <u>read</u>(char[] <i>name</i>); char[] patternFunc =r"<dt><big>[^\r\n]+?\s+<u>\w+</u>\([^\r\n()]+?\);"; char[][] h1; //保存模块文件名,如std.file char[][] func; //保存方法名 foreach (d; d_help_files) { source = cast(char[])read(d); if ( auto m = std.regexp.search(source,patternH1,"ig") ) {h1 ~= m.match(1);} if ( auto m = std.regexp.search(source,patternFunc,"ig") ) { func ~= RegExp(patternFunc,"ig").match(source)[];} } foreach (int i,char[] d;func) { d = sub(d,"<[^<>]+>","","g"); //去掉html标签 if (auto m = std.regexp.search(d,r"(.+?)(\w+\(.+)")) { d = m.match(2) ~ " " ~ m.match(1); func[i] = d ; } } //把数组内容写到文件,可以作为SciTE的自动提示api文件 char[] temp; foreach (d;h1) { temp ~= d ~ "\r\n"; } append(api,temp); foreach (d;func) { temp ~= d ~ "\r\n"; } append(api,temp); //D语言正则表达式.不能匹配新行符 source = cast(char[]) read(lex); //提取D语言关键词 char[] patternKeys = r"<b>abstract</b>(.|\s)+?<b>with</b>"; if ( auto m = std.regexp.search(source,patternKeys,"img") ) { source = m.match(0); source = std.string.replace(source,"<b>",""); source = sub(source,r"</b>\s*","\r\n","g"); append(api,source); } else {writefln("failed lex");} } 下面是 D语言论坛 http://www.d-programming-language-china.org 所用的D语言词法文件d.properties: QUOTE: # Define SciTE settings for D # date: April 21, 2007 # author: yidabu d语言中文论坛 http://www.d-programming-language-china.org # *** Specify here your D program directory *** # 注:先定义一个变量,然后就可以用$(ddir)的方式引用。 # 如果不存在$(ddir)\dmd\bin 目录,说明设置错误。 ddir=D:\d file.patterns.d=*.d filter.d=D (d)|$(file.patterns.d)| lexer.$(file.patterns.d)=d # d语言中文论坛 http://www.d-programming-language-china.org # 要加上.才能支持std.c.windows这样的自动提示 word.chars.d=.$(chars.alpha)$(chars.numeric)_# word.characters.$(file.patterns.d)=$(word.chars.d) #~ word.characters.$(file.patterns.cs)=$(word.chars.d) calltip.d.word.characters=$(word.chars.d) api.$(file.patterns.d)=$(SciteDefaultHome)\api\d.api;$(SciteDefaultHome)\api\d.user.calltips.api;$(SciteDefaultHome)\api\common.api # author: yidabu d语言中文论坛 http://www.d-programming-language-china.org # 不设置自动完成开始字符就不能启用自动完成 autocomplete.d.start.characters=$(word.chars.d) calltip.d.ignorecase=1 calltip.d.parameters.start=( calltip.d.parameters.end=) calltip.d.end.definition=; calltip.d.parameters.separators=, #comment.block.at.line.start.d=1 comment.block.d=//~ comment.stream.start.d=/+ comment.stream.end.d=+/ comment.box.start.d=/* comment.box.middle.d= * comment.box.end.d= */ #lexer.d.fold.at.else=1 statement.indent.$(file.patterns.d)=6 case catch class debug default do else \ finally for foreach foreach_reverse if private protected public scope struct \ try union while with statement.end.$(file.patterns.d)=13 ; statement.lookback.$(file.patterns.d)=20 block.start.$(file.patterns.d)=13 { block.end.$(file.patterns.d)=13 } # D keywords # 自动提示文件位置 d.api是d语言关键词,函数名,d.user.calltips.api是自定义自动提示 import d.keywords # style 6 keywords.$(file.patterns.d)=$(d.keywords.keywords) # style 7 keywords2.$(file.patterns.d)=$(d.keywords.functions) # keywords3 are intended for doxygen keywords3.$(file.patterns.d)=a addindex addtogroup anchor arg attention \ author b brief bug c class code date def defgroup deprecated dontinclude \ e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \ f$ f[ f] file fn hideinitializer htmlinclude htmlonly \ if image include ingroup internal invariant interface latexonly li line link \ mainpage name namespace nosubgrouping note overload \ p page par param post pre ref relates remarks return retval \ sa section see showinitializer since skip skipline struct subsection \ test throw todo typedef union until \ var verbatim verbinclude version warning weakgroup $ @ \ & < > # { } # keywords4 are intended for syntax driven or custom highlighting # Styles # 0 - whitespace # 1, 2, 3, 4 - comments: /* */, //, /** */ or /*! */, /+ +/ # 5 - number # 6, 7, 8, 9 - keywords: standard, secondary, doc keywords, typedefs and aliases # 10 - string # 11 - string not closed # 12 - char # 13 - operator # 14 - identifier # 15, 16, 17 - Doc comments: line doc /// or //!, doc keyword, doc keyword err style.d.32=$(font.base) style.d.0=fore:#808080 style.d.1=$(colour.code.comment.box),$(font.code.comment.box) style.d.2=$(colour.code.comment.line),$(font.code.comment.line) style.d.3=$(colour.code.comment.doc),$(font.code.comment.doc) style.d.4=$(colour.code.comment.nested),$(font.code.comment.nested) style.d.5=$(colour.number) style.d.6=fore:#0000FF,bold style.d.7=fore:#000090,bold,italics style.d.8=$(colour.keyword),bold style.d.9=$(colour.keyword),bold style.d.10=$(colour.string) style.d.11=fore:#000000,$(font.monospace),back:#E0C0E0,eolfilled style.d.12=$(colour.char) style.d.13=$(colour.operator),bold style.d.14= style.d.15=$(colour.code.comment.doc),$(font.code.comment.doc) style.d.16=fore:#3060A0,$(font.code.comment.doc) style.d.17=fore:#804020,$(font.code.comment.doc) # breaces must be operator style to allow matching braces.d.style=13 # 编译DFL GUI command.6.$(file.patterns.d)=$(ddir)\dmd\bin\dfl.exe -gui $(FilePath) command.name.6.$(file.patterns.d)=DFL Build command.save.before.6.$(file.patterns.d)=1 # http://bbs.d-programming-language-china.org 注:用快捷键Ctrl+Alt+F调用,用F是因为DFL的第二个字母是F command.shortcut.6.$(file.patterns.d)=Ctrl+Alt+F command.7.$(file.patterns.d)=$(FileName).exe command.name.7.$(file.patterns.d)=DFL Run command.save.before.7.$(file.patterns.d)=1 command.subsystem.7.$(file.patterns.d)=2 command.quiet.7.$(file.patterns.d)=1 # http://bbs.d-programming-language-china.org 注:用快捷键Ctrl+Alt+Shift+F运行,用F是因为DFL的第二个字母是F command.shortcut.7.$(file.patterns.d)=Ctrl+Alt+Shift+F # Commands to for Help F1 command.help.$(file.patterns.d)=$(CurrentWord)!$(ddir)\tools\d1011.chm command.help.subsystem.$(file.patterns.d)=4 #~ command.compile.*.d=$(ddir)\dmd\bin\dmd.exe -O -odobject $(FileNameExt) win32.lib uuid.lib ole32.lib command.compile.*.d=$(ddir)\dmd\bin\dmd.exe -O -odobject $(FileNameExt) $(FileName).def make.command=make command.build.*.d=$(ddir)\dmd\bin\bud.exe -DCPATH$(ddir)\dm\bin\make $(FileNameExt) command.go.*.d=$(FileName) command.go.subsystem.$(file.patterns.d)=1 ( lastupdate:20070505 最新文章请访问http://www.d-programming-language-china.org )关于一大步成功社区:yidabu提倡在交流中学习,在分享中提高收集感兴趣的知识,写下心得,通过网络与别人一起分享理解一点就实践一步,收获什么就分享什么,成功就是这样一点点一步步累积起来的网络只是一个工具,只有自己身心提高才是实实在在的。d-programming-language-china.org为大家提供一个学习交流各种知识的平台
sleets 2008-3-13 14:32
似乎scite1.75出来了,楼主的scite4d还是1.74
yidabu 2008-3-13 15:37
是的,scite1.75出来了,你有没有用过scite 1.75?