2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

www/codemirror/fhem.js: Added codemirror Keyword 'defmod'. Forum #20444

git-svn-id: https://svn.fhem.de/fhem/trunk@11288 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rapster 2016-04-20 08:25:19 +00:00
parent 157d12ab9d
commit 80ff9a281c
2 changed files with 9 additions and 6 deletions

View File

@ -1,3 +1,5 @@
/* $Id$ */
CodeMirror.defineMode("fhem",function(){function d(a,c,d,f,b){c.chain=null;c.style=null;c.tail=null;c.tokenize=function(a,c){for(var h=!1,l,k=0;l=a.next();){if(l===d[k]&&!h){void 0!==d[++k]?(c.chain=d[k],c.style=f,c.tail=b):b&&a.eatWhile(b);c.tokenize=n;break}h=!h&&"\\"==l}return f};return c.tokenize(a,c)}function h(a,c,d){c.tokenize=function(a,b){a.string==d&&(b.tokenize=n);a.skipToEnd();return"string"};return c.tokenize(a,c)}function n(a,c){if(a.eatSpace())return null;if(c.chain)return d(a,c,c.chain,
c.style,c.tail);if(a.match(/^\-?[\d\.]/,!1)&&a.match(/^(\-?(\d*\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F]+|0b[01]+|\d+(e[+-]?\d+)?)/))return"number";if(a.match(/^<<(?=\w)/))return a.eatWhile(/\w/),h(a,c,a.current().substr(2));if(a.sol()&&a.match(/^\=item(?!\w)/))return h(a,c,"=cut");var g=a.next();if('"'==g||"'"==g){if(a.prefix(3)=="<<"+g){var m=a.pos;a.eatWhile(/\w/);var b=a.current().substr(1);if(b&&a.eat(g))return h(a,c,b);a.pos=m}return d(a,c,[g],"string")}if("q"==g&&(b=a.look(-2),!b||!/\w/.test(b)))if(b=
a.look(0),"x"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string-2",f);if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string-2",f);if("{"==b)return a.eatSuffix(2),d(a,c,["}"],"string-2",f);if("<"==b)return a.eatSuffix(2),d(a,c,[">"],"string-2",f);if(/[\^'"!~\/]/.test(b))return a.eatSuffix(1),d(a,c,[a.eat(b)],"string-2",f)}else if("q"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string");if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string");if("{"==b)return a.eatSuffix(2),
@ -16,13 +18,13 @@ $RS:5,"$/":5,$OUTPUT_RECORD_SEPARATOR:5,$ORS:5,"$\\":5,$OUTPUT_AUTOFLUSH:5,"$|":
endprotoent:1,endpwent:1,endservent:1,eof:1,eval:1,exec:1,exists:1,exit:1,exp:1,fcntl:1,fileno:1,flock:1,fork:1,format:1,formline:1,getc:1,getgrent:1,getgrgid:1,getgrnam:1,gethostbyaddr:1,gethostbyname:1,gethostent:1,getlogin:1,getnetbyaddr:1,getnetbyname:1,getnetent:1,getpeername:1,getpgrp:1,getppid:1,getpriority:1,getprotobyname:1,getprotobynumber:1,getprotoent:1,getpwent:1,getpwnam:1,getpwuid:1,getservbyname:1,getservbyport:1,getservent:1,getsockname:1,getsockopt:1,given:1,glob:1,gmtime:1,"goto":1,
grep:1,hex:1,"import":1,index:1,"int":1,ioctl:1,join:1,keys:1,kill:1,last:1,lc:1,lcfirst:1,length:1,link:1,listen:1,local:2,localtime:1,lock:1,log:1,lstat:1,m:null,map:1,mkdir:1,msgctl:1,msgget:1,msgrcv:1,msgsnd:1,my:2,"new":1,next:1,no:1,oct:1,open:1,opendir:1,ord:1,our:2,pack:1,"package":1,pipe:1,pop:1,pos:1,print:1,printf:1,prototype:1,push:1,q:null,qq:null,qr:null,quotemeta:null,qw:null,qx:null,rand:1,read:1,readdir:1,readline:1,readlink:1,readpipe:1,recv:1,redo:1,ref:1,rename:1,require:1,reset:1,
"return":1,reverse:1,rewinddir:1,rindex:1,rmdir:1,s:null,say:1,scalar:1,seek:1,seekdir:1,select:1,semctl:1,semget:1,semop:1,send:1,setgrent:1,sethostent:1,setnetent:1,setpgrp:1,setpriority:1,setprotoent:1,setpwent:1,setservent:1,setsockopt:1,shift:1,shmctl:1,shmget:1,shmread:1,shmwrite:1,shutdown:1,sin:1,sleep:1,socket:1,socketpair:1,sort:1,splice:1,split:1,sprintf:1,sqrt:1,srand:1,stat:1,state:1,study:1,sub:1,substr:1,symlink:1,syscall:1,sysopen:1,sysread:1,sysseek:1,system:1,syswrite:1,tell:1,telldir:1,
tie:1,tied:1,time:1,times:1,tr:null,truncate:1,uc:1,ucfirst:1,umask:1,undef:1,unlink:1,unpack:1,unshift:1,untie:1,use:1,utime:1,values:1,vec:1,wait:1,waitpid:1,wantarray:1,warn:1,when:1,write:1,define:2,attr:2,at:2,notify:2,set:2,ReadingsVal:1,Value:1,fhem:1,IF:2,DOIF:2,DOELSE:2,DOELSEIF:2,y:null};keywords.foreach(function(a,c){p[c]=2});var f=/[goseximacplud]/;return{startState:function(){return{tokenize:n,chain:null,style:null,tail:null}},token:function(a,c){return(c.tokenize||n)(a,c)},electricChars:"{}"}});
CodeMirror.defineMIME("text/x-fhem","fhem");CodeMirror.StringStream.prototype.look=function(d){return this.string.charAt(this.pos+(d||0))};CodeMirror.StringStream.prototype.prefix=function(d){if(d){var h=this.pos-d;return this.string.substr(0<=h?h:0,d)}return this.string.substr(0,this.pos-1)};CodeMirror.StringStream.prototype.suffix=function(d){var h=this.string.length,n=h-this.pos+1;return this.string.substr(this.pos,d&&d<h?d:n)};
tie:1,tied:1,time:1,times:1,tr:null,truncate:1,uc:1,ucfirst:1,umask:1,undef:1,unlink:1,unpack:1,unshift:1,untie:1,use:1,utime:1,values:1,vec:1,wait:1,waitpid:1,wantarray:1,warn:1,when:1,write:1,define:2,defmod:2,attr:2,at:2,notify:2,set:2,ReadingsVal:1,Value:1,fhem:1,IF:2,DOIF:2,DOELSE:2,DOELSEIF:2,y:null};keywords.foreach(function(a,c){p[c]=2});var f=/[goseximacplud]/;return{startState:function(){return{tokenize:n,chain:null,style:null,tail:null}},token:function(a,c){return(c.tokenize||n)(a,c)},
electricChars:"{}"}});CodeMirror.defineMIME("text/x-fhem","fhem");CodeMirror.StringStream.prototype.look=function(d){return this.string.charAt(this.pos+(d||0))};CodeMirror.StringStream.prototype.prefix=function(d){if(d){var h=this.pos-d;return this.string.substr(0<=h?h:0,d)}return this.string.substr(0,this.pos-1)};CodeMirror.StringStream.prototype.suffix=function(d){var h=this.string.length,n=h-this.pos+1;return this.string.substr(this.pos,d&&d<h?d:n)};
CodeMirror.StringStream.prototype.nsuffix=function(d){var h=this.pos;d=d||this.string.length-this.pos+1;this.pos+=d;return this.string.substr(h,d)};CodeMirror.StringStream.prototype.eatSuffix=function(d){d=this.pos+d;var h;0>=d?this.pos=0:d>=(h=this.string.length-1)?this.pos=h:this.pos=d};Array.prototype.foreach=function(d){for(var h=0;h<this.length;h++)d(h,this[h])};CodeMirror.commands.autocomplete=function(d){CodeMirror.showHint(d,CodeMirror.hint.fhem,{async:!0})};
var keywords="at attr define delete deleteattr deletereading IF DOIF DOELSEIF DOELSE displayattr fhem get getstate list modify notify set setdefaultattr setreading setstate trigger AttrVal OldTimestamp OldValue ReadingsVal ReadingsTimestamp Value".split(" "),variables="$defs $hms $hour $isdst $mday $min $month $sec $wday $we $yday $year".split(" "),devices=[];
var keywords="at attr define defmod delete deleteattr deletereading IF DOIF DOELSEIF DOELSE displayattr fhem get getstate list modify notify set setdefaultattr setreading setstate trigger AttrVal OldTimestamp OldValue ReadingsVal ReadingsTimestamp Value".split(" "),variables="$defs $hms $hour $isdst $mday $min $month $sec $wday $we $yday $year".split(" "),devices=[];
CodeMirror.registerHelper("hint","fhem",function hintfhem(h,n,p){function f(a){var b=[];null!=a&&(a.PossibleAttrs.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function a(a){var b=[];null!=a&&(a.PossibleSets.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function c(a){var b=[];if(null!=a){for(var c in a.Readings)b.push(c);
b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())})}return b}function g(a,b){var c=0,e=a.length-1,f=Math.floor((e+c)/2),g=null;for(b=b.toLowerCase();(g=a[f].Name.toLowerCase())!=b&&c<e;)b<g?e=f-1:b>g&&(c=f+1),f=Math.floor((e+c)/2);return g!=b?null:a[f]}function m(a,b,c,e){var f=[];a.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintkeyword"})});b.foreach(function(a,b){0==b.Name.lastIndexOf(e,0)&&(b.Attributes&&null!=b.Attributes.alias?f.push({text:b.Name,
displayText:b.Name+" # "+b.Attributes.alias}):f.push(b.Name))});c.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintvariable"})});n({list:f,from:CodeMirror.Pos(u.line,t),to:CodeMirror.Pos(u.line,r)})}if(0==devices.length)$.getJSON("/fhem?cmd=jsonlist2&XHR=1",function(a){0==devices.length&&(a.Results.foreach(function(a,b){devices.push(b)}),devices.sort(function(a,b){return a.Name.toLowerCase().localeCompare(b.Name.toLowerCase())}),hintfhem(h,n,p))});else{var b=keywords,e=variables,
q=devices,u=h.getCursor(),l=h.getTokenAt(u),k=l.string,t=l.start,r=l.end;/[^\w$_-]/.test(k)&&(k="",t=r=u.ch);l=h.getLine(u.line).substr(0,r);/([\w_\.]+)$/.test(l)&&(k=RegExp.$1,t=r-k.length);/^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(l)?b=e=[]:/^[ \t]*(attr|deleteattr|displayattr)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=f(e)):/^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??([\w_\.]+):\??([\w-]*)$/.test(l)?
q=devices,u=h.getCursor(),l=h.getTokenAt(u),k=l.string,t=l.start,r=l.end;/[^\w$_-]/.test(k)&&(k="",t=r=u.ch);l=h.getLine(u.line).substr(0,r);/([\w_\.]+)$/.test(l)&&(k=RegExp.$1,t=r-k.length);/^[ \t]*(attr|set|get|defmod|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(l)?b=e=[]:/^[ \t]*(attr|deleteattr|displayattr)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=f(e)):/^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??([\w_\.]+):\??([\w-]*)$/.test(l)?
(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(deletereading|setreading)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(set|get)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=a(e)):/.*(AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,t=r-k.length,e=g(devices,e),e=f(e)):/.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?
(b=q=e=[],e=RegExp.$2,k=RegExp.$3,t=r-k.length,e=g(devices,e),e=c(e)):/.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)$/.test(l)&&(b=e=[],k=RegExp.$2,t=r-k.length);m(b,q,e,k)}});

View File

@ -465,6 +465,7 @@ CodeMirror.defineMode("fhem",function(){
write :1, // - print a picture record
// FHEM Keywords ////////////////////////
define :2,
defmod :2,
attr :2,
at :2,
notify :2,
@ -844,7 +845,7 @@ CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.fhem, {async:true});
}
var keywords = ["at","attr","define","delete","deleteattr","deletereading","IF","DOIF","DOELSEIF","DOELSE","displayattr","fhem","get","getstate",
var keywords = ["at","attr","define","defmod","delete","deleteattr","deletereading","IF","DOIF","DOELSEIF","DOELSE","displayattr","fhem","get","getstate",
"list","modify","notify","set","setdefaultattr","setreading","setstate","trigger",
"AttrVal","OldTimestamp","OldValue","ReadingsVal","ReadingsTimestamp","Value"];
var variables = ["$defs","$hms","$hour","$isdst","$mday","$min","$month","$sec","$wday","$we","$yday","$year"];
@ -882,7 +883,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
start = end - word.length;
}
// only device names
if( /^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(line) ) {
if( /^[ \t]*(attr|set|get|defmod|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(line) ) {
_key = _var = [];
}
// only device attribute names