简体   繁体   English

为什么此javascript代码段触发“意外令牌非法”?

[英]Why is this javascript snippet triggering “Unexpected token ILLEGAL”?

One line of the minified google-code-prettify javascript lib triggers "Unexpected token ILLEGAL". 缩小的google-code-prettify javascript库的一行触发了“意外令牌非法”。 If I remove it the lib works fine. 如果我删除它,lib可以正常工作。 I tried to remove special chars, expecting encoding to be the code but it seems it's not. 我试图删除特殊字符,希望编码成为代码,但事实并非如此。

PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\r \xa0\u2028\u2029]+/,null,"\t\n\r Â\xa0

"],["str",/^(?:["\u201c\u201d](?:[^"\u201c\u201d]|["\u201c\u201d]{2})(?:["\u201c\u201d]c|$)|["\u201c\u201d](?:[^"\u201c\u201d]|["\u201c\u201d]{2})*(?:["\u201c\u201d]|$))/i,null,'"“â€'],["com",/^['\u2018\u2019].*/,null,"'‘’"]],[["kwd",/^(?:addhandler|addressof|alias|and|andalso|ansi|as|assembly|auto|boolean|byref|byte|byval|call|case|catch|cbool|cbyte|cchar|cdate|cdbl|cdec|char|cint|class|clng|cobj|const|cshort|csng|cstr|ctype|date|decimal|declare|default|delegate|dim|directcast|do|double|each|else|elseif|end|endif|enum|erase|error|event|exit|finally|for|friend|function|get|gettype|gosub|goto|handles|if|implements|imports|in|inherits|integer|interface|is|let|lib|like|long|loop|me|mod|module|mustinherit|mustoverride|mybase|myclass|namespace|new|next|not|notinheritable|notoverridable|object|on|option|optional|or|orelse|overloads|overridable|overrides|paramarray|preserve|private|property|protected|public|raiseevent|readonly|redim|removehandler|resume|return|select|set|shadows|shared|short|single|static|step|stop|string|structure|sub|synclock|then|throw|to|try|typeof|unicode|until|variant|wend|when|while|with|withevents|writeonly|xor|endif|gosub|let|variant|wend)\b/i,null],["com",/^rem.*/i],["lit",/^(?:true\b|false\b|nothing\b|\d+(?:e[+-]?\d+[dfr]?|[dfilrs])?|(?:&h[\da-f]+|&o[0-7]+)[ils]?|\d*\.\d+(?:e[+-]?\d+)?[dfr]?|#\s+(?:\d+[/-]\d+[/-]\d+(?:\s+\d+:\d+(?::\d+)?(\s*(?:am|pm))?)?|\d+:\d+(?::\d+)?(\s*(?:am|pm))?)\s+#)/i],["pln",/^(?:(?:[a-z]|_\w)\w*|\[(?:[a-z]|_\w)\w*])/i],["pun",/^[^\w\t\n\r "'[\]\xa0\u2018\u2019\u201c\u201d\u2028\u2029]+/],["pun",/^(?:\[|])/]]),["vb","vbs"]);

I tried to change ["pun",/^(?:\\[|])/]]) to ["pun",/^(?:\\[|])/]) but no luck. 我试图将["pun",/^(?:\\[|])/]])更改为["pun",/^(?:\\[|])/])但是没有运气。

EDIT: 编辑:

I could identify that the "\\t\\n\\r Â\\xa0

" is causin it, but I can't tell why. 我可以确定“ \\ t \\ n \\ r \\ xa0”是其原因,但我不能说出原因。

This is most probably an encoding problem, because removing ¨â from "\\t\\n\\r Â\\xa0

" solves the problem. 这是最有可能的编码问题,因为删除¨â"\\t\\n\\r Â\\xa0

"解决了这个问题。 Be removing one of the 2 characters won't. 删除2个字符之一不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM