diff --git a/autotests/folding/example.rmd.fold b/autotests/folding/example.rmd.fold --- a/autotests/folding/example.rmd.fold +++ b/autotests/folding/example.rmd.fold @@ -1,15 +1,15 @@ --- -title: "test" -author: "me" -date: "07.10.2014" +title: "test" +author: "me" +date: "07.10.2014" output: html_document --- This is a simple test document. It shows syntax highlighting switches between YAML (above), R blocks ```{r, echo=FALSE} -for (i in 1:10) { +for (i in 1:10) { if(i>=10) print(i) -} +} # two blank lines below sessionInfo() diff --git a/autotests/folding/highlight.js.fold b/autotests/folding/highlight.js.fold --- a/autotests/folding/highlight.js.fold +++ b/autotests/folding/highlight.js.fold @@ -1,18 +1,18 @@ -/* test.js - test for javascript.xml syntax file */ +/* test.js - test for javascript.xml syntax file */ // Note: this script will not, and is not supposed to, compile in any js engine. -/* +/* NOTE: The words "todo", "fixme" and "note" should be rendered in a different style within comments, match should be caseless (to test for regexp insensitive attribute). - The regex used for this rule is */ + The regex used for this rule is */ String = /\b(?:fixme|todo|note)\b/ - /* Thus, for example "Notebook" is not caught by + /* Thus, for example "Notebook" is not caught by this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time saving a backref, which is not used for anything. I do not know if the overhead of parsing that is greater than the time saved by not capturing the text...) The rule for catching these words is placed in a context "Comment common", which is used by both comment contexts (single line, multiline) using the new "IncludeRules" item. -*/ +*/ // test if regex support works - nice with new fallthrough prop in context:) somestring.replace( /dooh/ , "bah!"); @@ -33,15 +33,15 @@ re = //; re = /a|b/; -/* +/* Tests for the regex parser. It will parse classes, quanitfiers, special characters and regex operaters, as specified in the netscape documentation for javascript. Regexps are only parsed in their clean form, as the RegExp(string) constructor is using a quoted string. TODO: Find out if more regex feats should be supported. Consider using more itemDatas - assertion, quantifier are options. -*/ +*/ re = /^text\s+\d+\s*$/; re = /a pattern with caret \(^\) in it/; @@ -58,15 +58,15 @@ var p = />/ // a test if #pop back from a comment will work -re = /*/foo/*/ /bar/; +re = /*/foo/*/ /bar/; // ^ POP // ^ we got back after pop in comment, if there is regexp attribs here :-) -/* +/* Some tests if the fallthrough works. The fallthrough happens if a regexp is not found in a possible (!) position, which is after "search(" or "replace(" or "=" or "?" or ":" in version 0.1 of the xml file -*/ +*/ var foo = 'bar'; // ^ fallthrough! @@ -77,11 +77,11 @@ something.method = - function ( a, b, c ) { /* ... */ } + function ( a, b, c ) { /* ... */ } // ^ fallthrough ?! something.other = -function ( d, e, f ) { /* ... */ } +function ( d, e, f ) { /* ... */ } // fallthrough expected at col 0 ("function" should be bold) var ary = new Array(5); @@ -98,9 +98,9 @@ // guess... -/* +/* Normal program flow... -*/ +*/ if (something) dostuff(); @@ -137,3 +137,25 @@ default: break; } + +// Numerics +var a = 0xA; +var b = 0b1; +var c = 0o7; +var d = 1.1E+3; +var e = 1.E+3; +var f = .1E+3; +var g = 1E+3; +var h = 1.1; +var i = 1.; +var j = .1; +var k = 1; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; +// Invalid numbers +var l = 0xA1t; +var m = 0b0123; +var n = 0o29; diff --git a/autotests/folding/highlight.jsp.fold b/autotests/folding/highlight.jsp.fold --- a/autotests/folding/highlight.jsp.fold +++ b/autotests/folding/highlight.jsp.fold @@ -89,22 +89,22 @@ <%-- Display our list of random Integers (shows code folding). --%> <% - if (intList != null && intList.size() > 0) { + if (intList != null && intList.size() > 0) { %> <% Iterator intListIt = intList.iterator(); - while (intListIt.hasNext()) { + while (intListIt.hasNext()) { Integer i = (Integer) intListIt.next(); %> <% - } - } else { + } + } else { %> <% - } + } %>
Here are the elements of intList...
<%=i.toString()%>
Oooops, we forgot to initialize intList!
@@ -142,7 +142,7 @@ <%! - /* A place for class variables and functions... */ + /* A place for class variables and functions... */ // Define some sample parameter names that this page might understand. private static final String PARAMETER_1 = "p1"; @@ -152,22 +152,22 @@ private static final String PARAMETER_5 = "p5"; // Returns str trimmed, or an empty string if str is null. - private static String noNull(String str) { + private static String noNull(String str) { String retStr; if (str == null) retStr = ""; else retStr = str.trim(); return retStr; - } + } // Returns a list of Integers with listSize elements. - private static List getIntList(int listSize) { + private static List getIntList(int listSize) { ArrayList retList = new ArrayList(listSize); for (int i = 0; i < listSize; i++) retList.add(new Integer( (int) (Math.random() * 100) )); return retList; - } + } %> diff --git a/autotests/folding/highlight.php.fold b/autotests/folding/highlight.php.fold --- a/autotests/folding/highlight.php.fold +++ b/autotests/folding/highlight.php.fold @@ -16,10 +16,10 @@ > - .inputText { + .inputText { width: px; text-indent: 10px; - } + } > @@ -29,31 +29,31 @@ > type="text/babel"> - > > /* aaa */ ?> >> - function a(i) { + > > /* aaa */ ?> >> + function a(i) { - return >{ i + j }>; - } + return >{ i + j }>; + } > type="text/typescript"> - class DateTime { + class DateTime { info: string; - constructor() { this.info = ; } - get() { return this.info; } - } + constructor() { this.info = ; } + get() { return this.info; } + } > type="x-tmpl-mustache"> - {{! }} - {{#movie}} - > + {{! }} + {{#movie}} + >

{{title}}

{{title}} - {{ratings.critics_rating}} -
> - {{/movie}} +
> + {{/movie}}
> diff --git a/autotests/folding/test.htm.fold b/autotests/folding/test.htm.fold --- a/autotests/folding/test.htm.fold +++ b/autotests/folding/test.htm.fold @@ -19,46 +19,46 @@ type="text/typescript"> - class Student { + class Student { fullName: string; - constructor(public firstName: string, public middleInitial: string, public lastName: string) { + constructor(public firstName: string, public middleInitial: string, public lastName: string) { this.fullName = firstName + " " + middleInitial + " " + lastName; - } - } + } + } let a: null = null; let b: number = 12___3; > src="https://unpkg.com/babel-standalone@6/babel.min.js">> type="text/babel"> ReactDOM.render( - >Hello, world!>, + >Hello, world!>, document.getElementById('root') ); - function Story(props) { - const SpecificStory = components[props.storyType]; - return story={ props.story } attr2="&ref;" attr3="Hello\n" />; - } + function Story(props) { + const SpecificStory = components[props.storyType]; + return story={ props.story } attr2="&ref;" attr3="Hello\n" />; + } > type="x-tmpl-mustache"> - {{#movie}} - > + {{#movie}} + >

{{title}}

{{title}} -
> - > + > + > Rating - {{ratings.critics_rating}} - > - {{/movie}} - {{^movie}} - > + > + {{/movie}} + {{^movie}} + > Movie Does Not Exist :( - > - {{/movie}} - {{! comment }} +
> + {{/movie}} + {{! comment }}
> diff --git a/autotests/folding/test.coffee.fold b/autotests/folding/test.coffee.fold --- a/autotests/folding/test.coffee.fold +++ b/autotests/folding/test.coffee.fold @@ -69,3 +69,7 @@ alert(`Hello ${name}!`); ``` ` String.raw\`String ${x} \` ` + +` // Regular Expression after template + const a = \`6\` / 2; /*comment*/ + \`template\` /regex/ ` diff --git a/autotests/folding/test.js.fold b/autotests/folding/test.js.fold --- a/autotests/folding/test.js.fold +++ b/autotests/folding/test.js.fold @@ -1,11 +1,11 @@ #! shebang #! no-shebang -/* comment */ +/* comment */ function fun() { - var boo = { 'key': [ 1, 2.0, 3.0e1, 004, 0x5 ] }; + var boo = { 'key': [ 1, 2.0, 3.0e1, 004, 0x5 ] }; } class MyClass; // reserved keywords @@ -19,8 +19,25 @@ var octal = 0o124; var bin = 0b1010; -ლಠ益ಠლ.ñá = 42; -δ /No-RegExp/ +日本語().ლಠ益ಠლ.ñá = 42; +δ /No-Regex/ -/* Modelines: finish comment in incomplete Modeline: - * kate: replace-tabs */ normal text +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 + +// Built-in +const os = require('os'); +JSON.stringify("hello"); +console.error("hello"); +Math.LOG10E; +Number.MAX_SAFE_INTEGER; diff --git a/autotests/folding/test.jsx.fold b/autotests/folding/test.jsx.fold --- a/autotests/folding/test.jsx.fold +++ b/autotests/folding/test.jsx.fold @@ -1,96 +1,98 @@ // JavaScript React -/** @author Willy - * @url https://reactjs.org/ **/ +/** @author Willy + * @url https://reactjs.org/ **/ import React from 'react'; -import { PhotoStory, VideoStory } from './stories'; +import { PhotoStory, VideoStory } from './stories'; -function Story(props) { - const SpecificStory = components[props.storyType]; - return story={ props.story } attr2="&ref;" attr3="Hello\n" />; -} +function Story(props) { + const SpecificStory = components[props.storyType]; + return story={ props.story } attr2="&ref;" attr3="Hello\n" />; +} function - attr1={ /> function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> - /* no comment*/ function /> return class var 0x123 &ref; hello() React.Component() - ./> anyWord /> - { function return class var 0x123 hello() React.Component() } -> + attr1={ /> function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> + /* no comment*/ function /> return class var 0x123 &ref; hello() React.Component() + ./> anyWord /> + { function return class var 0x123 hello() React.Component() } +> -> > -> > -> > +> > +> > +> > -/*comment*/attr1/*comment*/= /*comment*/"value"/*comment*/attr2 /*comment*/attr3='a' key/*comment*/key2 /> +/*comment*/attr1/*comment*/= /*comment*/"value"/*comment*/attr2 /*comment*/attr3='a' key/*comment*/key2 /> // Detect Valid tags -/* comment */ >> -{ /* comment - */ /> - word . } -return /* comment - multiline */ /> /* comment */ /> -&& /*comment*/ /> -& /*comment*/ - - /> -{ >Hello> } -? />; -[ /> ( /> -,/> =/> -&&/> ||/> -return /> ; -default/> ; -> > /> > return > +/* comment */ >> +{ /* comment + */ /> + word . } +return /* comment + multiline */ /> /* comment */ /> +&& /*comment*/ /> +& /*comment*/ + + /> +{ >Hello> } +? />; +[ /> ( /> ] +,/> =/> +&&/> ||/> +return /> ; +default/> ; +> > /> > return > anyWord -anyWord/*comment*/ +anyWord/*comment*/ . & | -% /* comment*/ - -/> -> > - -/> +% /* comment*/ // Non-ASCII tag name & attribute -<日本語>>; - 本本:本-本 aa本:本 aa:aa /> +<日本語>>; + 本本:本-本 aa本:本 aa:aa /> - />; - { ... x } y -={2 } z />; + />; + { ... x } y +={2 } z />; -let k1 = > > Hello > > world >>; -let k2 = > > Hello > >; +let k1 = > > Hello > > world >>; +let k2 = > > Hello > >; // Empty tags -<>; // no whitespace -< >; // lots of whitespace -< /*starting wrap*/ >/*ending wrap*/>; // comments in the tags -<>hi; // text inside -<>>hi>>bye>; // children -<>>1><>>2.1>>2.2>>3>; // nested fragments -<>#; // # would cause scanning error if not in jsxtext +<>; // no whitespace +< >; // lots of whitespace +< /*starting wrap*/ >/*ending wrap*/>; // comments in the tags +<>hi; // text inside +<>>hi>>bye>; // children +<>>1><>>2.1>>2.2>>3>; // nested fragments +<>#; // # would cause scanning error if not in jsxtext // Tags after substitutions in templates -`aaa${>>//comment - /*comment*//>}` +`aaa${>>//comment + /*comment*//>}` // Don't highlight tags within variable declaration let myIdentity: (arg: T) => T = identity; var myIdentity: (arg: U) => U = identity; -const myIdentity: {<T>(arg: T): T} = identity; +const myIdentity: {<T>(arg: T): T} = identity; // Don't highlight tags within interfaces and classes -interface GenericIdentityFn { +interface GenericIdentityFn { (arg: T): T; -} -class Handler { +} +class Handler { info: (arg: T): T ; - > > -} + > > +} + +// Check character after tag name, do not highlight invalid tags +/* comment */ ? +/*comment*/# diff --git a/autotests/folding/test.markdown.fold b/autotests/folding/test.markdown.fold --- a/autotests/folding/test.markdown.fold +++ b/autotests/folding/test.markdown.fold @@ -127,19 +127,19 @@ bold code -> +> a b - > + >
  • c
  • d
  • -
    > +
    > e -
    > +
    > normal text *italic* @@ -295,19 +295,19 @@ package fibsandlies; import java.util.HashMap; -/** +/** * This is an example of a Javadoc comment; Javadoc can compile documentation * from this text. Javadoc comments must immediately precede the class, method, or field being documented. - */ -public class FibCalculator extends Fibonacci implements Calculator { + */ +public class FibCalculator extends Fibonacci implements Calculator { private static Map memoized = new HashMap(); - public static void main(String[] args) { + public static void main(String[] args) { memoized.put(1, 1); memoized.put(2, 1); System.out.println(fibonacci(12)); - } -} + } +} ``` ## JavaScript @@ -324,21 +324,21 @@ ## JavaScript React (JSX) ```jsx - /> -function Story(props) { - const SpecificStory = components[props.storyType]; - return story={ props.story } attr2="&ref;" attr3="Hello\n" />; -} + /> +function Story(props) { + const SpecificStory = components[props.storyType]; + return story={ props.story } attr2="&ref;" attr3="Hello\n" />; +} ``` ## JSON ```json -[{ +[{ "hello": "world", "count": 1, "bool": true -}] +}] ``` ## Matlab @@ -360,25 +360,25 @@ ## Mustache/Handlebars ```handlebars -{{#movie}} - > +{{#movie}} + >

    {{title}}

    {{title}} -
    > - > + > + > Rating - {{ratings.critics_rating}} - > -{{/movie}} +
    > +{{/movie}} ``` ## Perl ```perl my $var = shift; -$var =~ s/bla/foo/igs; -$var =~ s!bla!foo!igs; -$var =~ s#bla#foo#igs; +$var =~ s/bla/foo/igs; +$var =~ s!bla!foo!igs; +$var =~ s#bla#foo#igs; ``` ## PHP @@ -389,56 +389,56 @@ use Zend\Mvc\Controller\AbstractActionController; class IndexController extends AbstractActionController -{ -} +{ +} ``` ## Python ```python -def addXToY(x, y): +def addXToY(x, y): total = x + y print total ``` ## QML ```qml -Text { +Text { id: hello width: 100 text: "Hello world!" -} +} ``` ## R ```r # Declare function “f” with parameters “x”, “y“ # that returns a linear combination of x and y. -f <- function(x, y) { +f <- function(x, y) { z <- 3 * x + 4 * y return(z) -} +} ``` ## Ruby ```ruby require 'Config' - def CGI::escape(string) - string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do + def CGI::escape(string) + string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do '%' + $1.unpack('H2' * $1.size).join('%').upcase - end.tr(' ', '+') - end + end.tr(' ', '+') + end ``` ## Rust ```rust -fn main() { +fn main() { println!("Hello world!"); -} +} ``` ## MySQL @@ -454,20 +454,20 @@ ## TypeScript ```ts -class Student { +class Student { fullName: string; - constructor(public firstName: string, public middleInitial: string, public lastName: string) { + constructor(public firstName: string, public middleInitial: string, public lastName: string) { this.fullName = firstName + " " + middleInitial + " " + lastName; - } -} + } +} ``` ## XML ```xml - attribute="3"> - /> -> + attribute="3"> + /> +> ``` ## reStructuredText @@ -522,7 +522,7 @@

    Hello world!

    -``` +``` ``````` ~~~bash @@ -532,7 +532,7 @@ ~~~ ~~~~~~~~~python -def addXToY(x, y): +def addXToY(x, y): total = x + y print total ~~~ # <= doesn't end here diff --git a/autotests/folding/test.qml.fold b/autotests/folding/test.qml.fold --- a/autotests/folding/test.qml.fold +++ b/autotests/folding/test.qml.fold @@ -1,6 +1,6 @@ -/* +/* * multi line comment - */ + */ // single line comment @@ -19,5 +19,6 @@ width: 0x10 height: 007 objectName: 'single quote' + objectName2: a ? b : c; } } diff --git a/autotests/folding/test.ts.fold b/autotests/folding/test.ts.fold --- a/autotests/folding/test.ts.fold +++ b/autotests/folding/test.ts.fold @@ -20,9 +20,13 @@ let user = new Student("Jane", "M.", "User"); -document.body.innerHTML = greeter(user); +// Built-in +document.body.innerHTML = greeter(user); to JSON.stringify() console.log("Hello world"); +const os = require('os'); +Math.LOG10E; +Number.MAX_SAFE_INTEGER; import http = require("http"); import path = require("path"); @@ -158,9 +162,9 @@ string ) // Don't highlight aa: string interface a { - aa: /* comment - */ string, - bb: /* comment */ + aa: /* comment + */ string, + bb: /* comment */ number, cc: // comment void, @@ -205,3 +209,16 @@ export declare function assert(value: unknown, message?: string): asserts value; export declare function assertDefined(value: T): asserts value is NonNullable; } + +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 diff --git a/autotests/folding/test.tsx.fold b/autotests/folding/test.tsx.fold --- a/autotests/folding/test.tsx.fold +++ b/autotests/folding/test.tsx.fold @@ -1,10 +1,10 @@ // TypeScript React -/** @author Willy - * @url https://reactjs.org/ **/ +/** @author Willy + * @url https://reactjs.org/ **/ import React from 'react'; -import { PhotoStory, VideoStory } from './stories'; +import { PhotoStory, VideoStory } from './stories'; function Story(props) { const SpecificStory = components[props.storyType]; @@ -22,37 +22,37 @@ > > > > -/*comment*/attr1/*comment*/= /*comment*/"value"/*comment*/attr2 /*comment*/attr3='a' key/*comment*/key2 /> +/*comment*/attr1/*comment*/= /*comment*/"value"/*comment*/attr2 /*comment*/attr3='a' key/*comment*/key2 /> // Detect Valid tags -/* comment */ >> -{ /* comment - */ /> +/* comment */ >> +{ /* comment + */ /> word . } -return /* comment - multiline */ /> /* comment */ /> -&& /*comment*/ /> -& /*comment*/ +return /* comment + multiline */ /> /* comment */ /> +&& /*comment*/ /> +& /*comment*/ /> { >Hello> } ? />; -[ /> ( /> +[ /> ( /> ,/> =/> &&/> ||/> return /> ; default/> ; > > /> > return > anyWord -anyWord/*comment*/ +anyWord/*comment*/ . & | -% /* comment*/ +% /* comment*/ // TODO: Fix this (comment before the tag name): -var x = </**/div>; +var x = </**/div>; // Tag after ":" annotation: /> @@ -66,9 +66,9 @@ /> // Non-ASCII tag name & attribute -<日本語>>; +<日本語>>; 本本:本-本 aa本:本 aa:aa /> -<aaaa:ñ /> + /> />; { ... x } y @@ -104,15 +104,15 @@ <>; // no whitespace < >; // lots of whitespace -< /*starting wrap*/ >/*ending wrap*/>; // comments in the tags +< /*starting wrap*/ >/*ending wrap*/>; // comments in the tags <>hi; // text inside <>>hi>>bye>; // children <>>1><>>2.1>>2.2>>3>; // nested fragments <>#; // # would cause scanning error if not in jsxtext // Tags after substitutions in templates `aaa${>>//comment - /*comment*//>}` + /*comment*//>}` // Don't highlight tags within type declaration type T12 = ReturnType<(() => T)>; @@ -144,3 +144,10 @@ return a } > text extends I/> > // Here "" is a tag + +// Check character after tag name, do not highlight invalid tags +/* comment */ ? +/*comment*/# diff --git a/autotests/html/highlight.js.html b/autotests/html/highlight.js.html --- a/autotests/html/highlight.js.html +++ b/autotests/html/highlight.js.html @@ -11,7 +11,7 @@ NOTE: The words "todo", "fixme" and "note" should be rendered in a different style within comments, match should be caseless (to test for regexp insensitive attribute). The regex used for this rule is */ - String = /\b(?:fixme|todo|note)\b/ + String = /\b(?:fixme|todo|note)\b/ /* Thus, for example "Notebook" is not caught by this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time saving a backref, which is not used for anything. I do not know if the overhead of parsing @@ -21,10 +21,10 @@ */ // test if regex support works - nice with new fallthrough prop in context:) -somestring.replace( /dooh/ , "bah!"); +somestring.replace( /dooh/ , "bah!"); re=/foo/ig; // hehe -somestring.search( +somestring.search( /^foo\w+\s\d{0,15}$/ ); @@ -78,19 +78,19 @@ // ^ fallthrough! -somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1"); +somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1"); // ^ fallthrough expected. ("new" whould be bold) -something.method = +something.method = function ( a, b, c ) { /* ... */ } // ^ fallthrough ?! -something.other = +something.other = function ( d, e, f ) { /* ... */ } // fallthrough expected at col 0 ("function" should be bold) -var ary = new Array(5); +var ary = new Array(5); // ^ fallthrough ? (if keyword is correctly rendered) var b = a ? 1 : 0; @@ -109,20 +109,20 @@ */ if (something) - dostuff(); + dostuff(); else - dont(); + dont(); return; -try { bla() } catch (e) { alert("ERROR! : " + e) } +try { bla() } catch (e) { alert("ERROR! : " + e) } for (int i=0; i < j; i++) - document.write("i is" + i + "<br>"); + document.write("i is" + i + "<br>"); while (something) { - block(); + block(); picky: if (!1) break; @@ -132,15 +132,37 @@ with (a) { do { - stuff( b ); // a.b if it exists + stuff( b ); // a.b if it exists } while (itmakessense); } switch (i) { case 0: - f(); + f(); break; default: break; } + +// Numerics +var a = 0xA; +var b = 0b1; +var c = 0o7; +var d = 1.1E+3; +var e = 1.E+3; +var f = .1E+3; +var g = 1E+3; +var h = 1.1; +var i = 1.; +var j = .1; +var k = 1; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; +// Invalid numbers +var l = 0xA1t; +var m = 0b0123; +var n = 0o29; diff --git a/autotests/html/highlight.jsp.html b/autotests/html/highlight.jsp.html --- a/autotests/html/highlight.jsp.html +++ b/autotests/html/highlight.jsp.html @@ -32,12 +32,12 @@ <title>A Sample Jsp</title> <head> <script language="javascript"><!-- - function doAlert1() { - alert("This is the first javascript example."); + function doAlert1() { + alert("This is the first javascript example."); } - function doAlert2() { - alert("This is the second javascript example."); + function doAlert2() { + alert("This is the second javascript example."); } //--></script> <style type="text/css"> diff --git a/autotests/html/highlight.php.html b/autotests/html/highlight.php.html --- a/autotests/html/highlight.php.html +++ b/autotests/html/highlight.php.html @@ -36,7 +36,7 @@ <!-- JavaScript React --> <script type="text/babel"> <Hello> <?php echo("Hello, hello!"); ?> </Hello> <?php /* aaa */ ?> <div></div> - function a(i) { + function a(i) { <?php echo "var j = 1;"; ?> return <p>{ i + j }</p>; } diff --git a/autotests/html/highlight.qml.html b/autotests/html/highlight.qml.html --- a/autotests/html/highlight.qml.html +++ b/autotests/html/highlight.qml.html @@ -15,52 +15,52 @@ signalA: bla property string label signal clicked - radius: 5; border.color: "black" - color: mouse.pressed ? "steelblue" : "lightsteelblue" + radius: 5; border.color: "black" + color: mouse.pressed ? "steelblue" : "lightsteelblue" gradient: Gradient { - GradientStop { position: mouse.pressed ? 1.0 : 0.0; color: "steelblue" } - GradientStop { position: mouse.pressed ? 0.0 : 1.0; color: "lightsteelblue" } + GradientStop { position: mouse.pressed ? 1.0 : 0.0; color: "steelblue" } + GradientStop { position: mouse.pressed ? 0.0 : 1.0; color: "lightsteelblue" } } - MouseRegion { id: mouse; anchors.fill: parent; onClicked: container.clicked() } - Text { anchors.fill: parent; text: container.label; anchors.centerIn: parent } + MouseRegion { id: mouse; anchors.fill: parent; onClicked: container.clicked() } + Text { anchors.fill: parent; text: container.label; anchors.centerIn: parent } } Rectangle { Script { - function calculateMyHeight() { - return Math.max(otherItem.height, thirdItem.height); + function calculateMyHeight() { + return Math.max(otherItem.height, thirdItem.height); } } - anchors.centerIn: parent - width: Math.min(otherItem.width, 10) - height: calculateMyHeight() + anchors.centerIn: parent + width: Math.min(otherItem.width, 10) + height: calculateMyHeight() color: { if (width > 10) "blue"; else "red" } } Rectangle { default property color innerColor: "black" property color innerColor: "black" - property alias text: textElement.text - property alias aliasXYZ: testElement.text + property alias text: textElement.text + property alias aliasXYZ: testElement.text signal bar signal bar(var blah, string yxcv) width: 240; height: 320; width: 100; height: 30; source: "images/toolbutton.sci" ListView { - anchors.fill: parent + anchors.fill: parent model: contactModel delegate: Component { Text { - text: modelData.firstName + " " + modelData.lastName + text: modelData.firstName + " " + modelData.lastName } } } } Item { - function say(text) { - console.log("You said " + text); + function say(text) { + console.log("You said " + text); } } diff --git a/autotests/html/test.htm.html b/autotests/html/test.htm.html --- a/autotests/html/test.htm.html +++ b/autotests/html/test.htm.html @@ -20,7 +20,7 @@ <!-- JavaScript code --> <script> - document.body.appendChild(document.createTextNode('Hello World!')); // comment + document.body.appendChild(document.createTextNode('Hello World!')); // comment </script> <!-- TypeScript code --> @@ -38,13 +38,13 @@ <!-- JSX code --> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> <script type="text/babel"> - ReactDOM.render( + ReactDOM.render( <h1>Hello, world!</h1>, - document.getElementById('root') + document.getElementById('root') ); - function Story(props) { - const SpecificStory = components[props.storyType]; - return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; + function Story(props) { + const SpecificStory = components[props.storyType]; + return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; } </script> diff --git a/autotests/html/test.coffee.html b/autotests/html/test.coffee.html --- a/autotests/html/test.coffee.html +++ b/autotests/html/test.coffee.html @@ -70,9 +70,13 @@ ``` // Comment - var array = new Array(500); + var array = new Array(500); var name = "Willy"; - alert(`Hello ${name}!`); + alert(`Hello ${name}!`); ``` ` String.raw\`String ${x} \` ` + +` // Regular Expression after template + const a = \`6\` / 2; /*comment*/ + \`template\` /regex/ ` diff --git a/autotests/html/test.js.html b/autotests/html/test.js.html --- a/autotests/html/test.js.html +++ b/autotests/html/test.js.html @@ -9,25 +9,42 @@ /* comment */ -function fun() +function fun() { var boo = { 'key': [ 1, 2.0, 3.0e1, 004, 0x5 ] }; } class MyClass; // reserved keywords // Member objects: text after "." -object.property instanceof Number; -iden1.iden2 . iden3.class class; +object.property instanceof Number; +iden1.iden2 . iden3.class class; var escapes = "aa\b\n\0a\"a\x12a\32a\u{123}a\$\%\ \#\y\aaa\ aaa"; var octal = 0o124; var bin = 0b1010; -ლಠ益ಠლ.ñá = 42; -δ /No-RegExp/ +日本語().ლಠ益ಠლ.ñá = 42; +δ /No-Regex/ -/* Modelines: finish comment in incomplete Modeline: - * kate: replace-tabs */ normal text +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 + +// Built-in +const os = require('os'); +JSON.stringify("hello"); +console.error("hello"); +Math.LOG10E; +Number.MAX_SAFE_INTEGER; diff --git a/autotests/html/test.jsx.html b/autotests/html/test.jsx.html --- a/autotests/html/test.jsx.html +++ b/autotests/html/test.jsx.html @@ -12,16 +12,16 @@ import React from 'react'; import { PhotoStory, VideoStory } from './stories'; -function Story(props) { - const SpecificStory = components[props.storyType]; - return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; +function Story(props) { + const SpecificStory = components[props.storyType]; + return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; } function -<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> +<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> /* no comment*/ function <tag/> return class var 0x123 &ref; hello() React.Component() .<tag/> anyWord <tag/> - { function <tag> return class var 0x123 hello() React.Component() } + { function <tag> return class var 0x123 hello() React.Component() } </Tag> <tag1> </tag1> @@ -44,7 +44,7 @@ <tag/> { <hello>Hello</hello> } ?<Tag />; -[ <tag /> ( <tag /> +[ <tag /> ( <tag /> ] ,<Tag/> =<Tag/> &&<tag/> ||<tag/> return <tag/> ; @@ -57,11 +57,6 @@ &<notag> | <noTag/> % /* comment*/ <noTag/> -<C<number>/> -<C<number>> </C> -<C -<error /> - // Non-ASCII tag name & attribute <日本語></日本語>; <Component 本本:本-本 aa本:本 aa:aa /> @@ -100,4 +95,11 @@ info: <T>(arg: T): T <noTag />; <tag> </tag> } + +// Check character after tag name, do not highlight invalid tags +<noTag ? +<noTag , +<noTag /* comment */ ? +<noTag# +<noTag/*comment*/# diff --git a/autotests/html/test.markdown.html b/autotests/html/test.markdown.html --- a/autotests/html/test.markdown.html +++ b/autotests/html/test.markdown.html @@ -319,21 +319,21 @@ ## JavaScript ```js -function factorial(n) { +function factorial(n) { if (n === 0) { return 1; // 0! = 1 } - return n * factorial(n - 1); + return n * factorial(n - 1); } ``` ## JavaScript React (JSX) ```jsx <hello /> -function Story(props) { - const SpecificStory = components[props.storyType]; - return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; +function Story(props) { + const SpecificStory = components[props.storyType]; + return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; } ``` diff --git a/autotests/html/test.qml.html b/autotests/html/test.qml.html --- a/autotests/html/test.qml.html +++ b/autotests/html/test.qml.html @@ -25,6 +25,7 @@ width: 0x10 height: 007 objectName: 'single quote' + objectName2: a ? b : c; } } diff --git a/autotests/html/test.ts.html b/autotests/html/test.ts.html --- a/autotests/html/test.ts.html +++ b/autotests/html/test.ts.html @@ -21,37 +21,41 @@ } function greeter(person : Person) { - return "Hello, " + person.firstName + " " + person.lastName; + return "Hello, " + person.firstName + " " + person.lastName; } let user = new Student("Jane", "M.", "User"); -document.body.innerHTML = greeter(user); +// Built-in +document.body.innerHTML = greeter(user); to JSON.stringify() console.log("Hello world"); +const os = require('os'); +Math.LOG10E; +Number.MAX_SAFE_INTEGER; import http = require("http"); import path = require("path"); -import URL = url.URL; +import URL = url.URL; import { Readable, Writable } from "stream"; import { isBuffer, isString, isObject } from "util"; const port = 8__88___8; const baseUrl = new URL(`http://localhost:${port}/`); -const rootDir = path.dirname(__dirname); +const rootDir = path.dirname(__dirname); -const defaultBrowser = os.platform() === "win32" ? "edge" : "chrome"; +const defaultBrowser = os.platform() === "win32" ? "edge" : "chrome"; let browser: "edge" | "chrome" | "none" = defaultBrowser; let grep: string | undefined; interface FileBasedTestConfiguration { [setting: string]: string; } function swapCase(s: string): string { - return s.replace(/\w/g, (ch) => { - const up = ch.toUpperCase(); - return ch === up ? ch.toLowerCase() : up; + return s.replace(/\w/g, (ch) => { + const up = ch.toUpperCase(); + return ch === up ? ch.toLowerCase() : up; }); } @@ -145,7 +149,7 @@ const query = createQuery<[number[]], Table<Columns>>(` some SQL here `) - return database.execute(query) + return database.execute(query) } aa: <sdf/> string ?<ssd/> string @@ -211,4 +215,17 @@ export declare function assert(value: unknown, message?: string): asserts value; export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>; } + +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 diff --git a/autotests/html/test.tsx.html b/autotests/html/test.tsx.html --- a/autotests/html/test.tsx.html +++ b/autotests/html/test.tsx.html @@ -13,15 +13,15 @@ import { PhotoStory, VideoStory } from './stories'; function Story(props) { - const SpecificStory = components[props.storyType]; - return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; + const SpecificStory = components[props.storyType]; + return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; } function -<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> +<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> /* no comment*/ function <tag/> return class var 0x123 &ref; hello() React.Component() .<tag/> anyWord <tag/> - { function <tag> return class var 0x123 hello() React.Component() } + { function <tag> return class var 0x123 hello() React.Component() } </Tag> <tag1> </tag1> @@ -91,16 +91,16 @@ {(name: string) => <div> My name {name} </div>} </Comp>; -let k3 = <GenericComponent initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error +let k3 = <GenericComponent initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error // OK let k1 = <Comp a={10} b="hi"><></><Button /><AnotherButton /></Comp>; let k2 = <Comp a={10} b="hi"><><Button /></><AnotherButton /></Comp>; let k3 = <Comp a={10} b="hi"><><Button /><AnotherButton /></></Comp>; let k4 = <SingleChildComp a={10} b="hi"><><Button /><AnotherButton /></></SingleChildComp>; // OK let k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; -let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; +let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; let k3 = <div> {1} {"That is a number"} </div>; let k4 = <Button> <h2> Hello </h2> </Button>; @@ -150,4 +150,11 @@ return a } <tag> text <T extends I/> </tag> // Here "<T extends I/>" is a tag + +// Check character after tag name, do not highlight invalid tags +<noTag ? +<noTag , +<noTag /* comment */ ? +<noTag# +<noTag/*comment*/# diff --git a/autotests/input/highlight.js b/autotests/input/highlight.js --- a/autotests/input/highlight.js +++ b/autotests/input/highlight.js @@ -137,3 +137,25 @@ default: break; } + +// Numerics +var a = 0xA; +var b = 0b1; +var c = 0o7; +var d = 1.1E+3; +var e = 1.E+3; +var f = .1E+3; +var g = 1E+3; +var h = 1.1; +var i = 1.; +var j = .1; +var k = 1; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; +// Invalid numbers +var l = 0xA1t; +var m = 0b0123; +var n = 0o29; diff --git a/autotests/input/test.coffee b/autotests/input/test.coffee --- a/autotests/input/test.coffee +++ b/autotests/input/test.coffee @@ -69,3 +69,7 @@ alert(`Hello ${name}!`); ``` ` String.raw\`String ${x} \` ` + +` // Regular Expression after template + const a = \`6\` / 2; /*comment*/ + \`template\` /regex/ ` diff --git a/autotests/input/test.js b/autotests/input/test.js --- a/autotests/input/test.js +++ b/autotests/input/test.js @@ -19,8 +19,25 @@ var octal = 0o124; var bin = 0b1010; -ლಠ益ಠლ.ñá = 42; -δ /No-RegExp/ +日本語().ლಠ益ಠლ.ñá = 42; +δ /No-Regex/ -/* Modelines: finish comment in incomplete Modeline: - * kate: replace-tabs */ normal text +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 + +// Built-in +const os = require('os'); +JSON.stringify("hello"); +console.error("hello"); +Math.LOG10E; +Number.MAX_SAFE_INTEGER; diff --git a/autotests/input/test.jsx b/autotests/input/test.jsx --- a/autotests/input/test.jsx +++ b/autotests/input/test.jsx @@ -38,7 +38,7 @@ { Hello } ?; -[ ( +[ ( ] , = && || return ; @@ -51,11 +51,6 @@ & | % /* comment*/ -/> -> - - // Non-ASCII tag name & attribute <日本語>; @@ -94,3 +89,10 @@ info: (arg: T): T ; } + +// Check character after tag name, do not highlight invalid tags +(value: T): asserts value is NonNullable; } + +// Only highlight valid regular expressions, of a single line, after strings +// See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786 +"text" /No-Regex +"text" /Regex[:)]*/; +const a = "6" / 2; /*comment*/ const b = 5; +console.log("4" / "2"); // 2 +// Single quote +const a = '6' / 2; /*comment*/ const b = 5; +console.log('4' / '2'); // 2 +// Template +const a = `6` / 2; /*comment*/ const b = 5; +console.log(`4` / `2`); // 2 diff --git a/autotests/input/test.tsx b/autotests/input/test.tsx --- a/autotests/input/test.tsx +++ b/autotests/input/test.tsx @@ -144,3 +144,10 @@ return a } text // Here "" is a tag + +// Check character after tag name, do not highlight invalid tags + NOTE: The words "todo", "fixme" and "note" should be rendered in a different style
    within comments, match should be caseless (to test for regexp insensitive attribute).
    The regex used for this rule is */
    - String = /\b(?:fixme|todo|note)\b/
    + String = /\b(?:fixme|todo|note)\b/
    /* Thus, for example "Notebook" is not caught by
    this rule. (the "?:" in the subpattern is there to avoid the regex engine wasting time
    saving a backref, which is not used for anything. I do not know if the overhead of parsing
    @@ -15,10 +15,10 @@ */

    // test if regex support works - nice with new fallthrough prop in context:)
    -somestring.replace( /dooh/ , "bah!");
    +somestring.replace( /dooh/ , "bah!");
    re=/foo/ig; // hehe

    -somestring.search(
    +somestring.search(
    /^foo\w+\s\d{0,15}$/
    );

    @@ -53,9 +53,9 @@ re = /a|b/;

    // the following are not regexps in E4X (=xml embedded into JavaScript)
    -var p = <p>Hello World>
    +var p = <p>Hello Worldp>
    var p = /
    -var p = />/
    +var p = />/

    // a test if #pop back from a comment will work
    re = /*/foo/*/ /bar/;
    @@ -72,19 +72,19 @@ // ^ fallthrough!


    -somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1");
    +somestring.replace( new RegExp("\\b\\w+\\b"), "word: $1");
    // ^ fallthrough expected. ("new" whould be bold)


    -something.method =
    - function ( a, b, c ) { /* ... */ }
    +something.method =
    + function ( a, b, c ) { /* ... */ }
    // ^ fallthrough ?!

    -something.other =
    -function ( d, e, f ) { /* ... */ }
    +something.other =
    +function ( d, e, f ) { /* ... */ }
    // fallthrough expected at col 0 ("function" should be bold)

    -var ary = new Array(5);
    +var ary = new Array(5);
    // ^ fallthrough ? (if keyword is correctly rendered)

    var b = a ? 1 : 0;
    @@ -103,37 +103,59 @@ */

    if (something)
    - dostuff();
    + dostuff();
    else
    - dont();
    + dont();

    return;

    -try { bla() } catch (e) { alert("ERROR! : " + e) }
    +try { bla() } catch (e) { alert("ERROR! : " + e) }

    for (int i=0; i < j; i++)
    - document.write("i is" + i + "
    "
    );
    + document.write("i is" + i + "
    "
    );

    while (something)
    -{
    - block();
    +{
    + block();
    picky:
    if (!1)
    break;
    else
    continue;
    -}
    +}

    -with (a) {
    - do {
    - stuff( b ); // a.b if it exists
    - } while (itmakessense);
    -}
    +with (a) {
    + do {
    + stuff( b ); // a.b if it exists
    + } while (itmakessense);
    +}

    -switch (i) {
    +switch (i) {
    case 0:
    - f();
    + f();
    break;
    default:
    break;
    -}
    +}
    +
    +// Numerics
    +var a = 0xA;
    +var b = 0b1;
    +var c = 0o7;
    +var d = 1.1E+3;
    +var e = 1.E+3;
    +var f = .1E+3;
    +var g = 1E+3;
    +var h = 1.1;
    +var i = 1.;
    +var j = .1;
    +var k = 1;
    +// Bigint
    +const binBig = 0b101n;
    +const octBig = 0o567n;
    +const hexBig = 0xC0Bn;
    +const decBig = 123n;
    +// Invalid numbers
    +var l = 0xA1t;
    +var m = 0b0123;
    +var n = 0o29;
    diff --git a/autotests/reference/highlight.jsp.ref b/autotests/reference/highlight.jsp.ref --- a/autotests/reference/highlight.jsp.ref +++ b/autotests/reference/highlight.jsp.ref @@ -26,13 +26,13 @@ A Sample Jsp