From 9f4e7db2254a34f62a5024c6e3f8348386c1a6b8 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 14:15:41 +0100 Subject: [PATCH 1/7] Support for IETF ABNF (RFC 5234 and extensions) --- src/lang-ietfabnf.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/lang-ietfabnf.js diff --git a/src/lang-ietfabnf.js b/src/lang-ietfabnf.js new file mode 100644 index 00000000..b7037ecf --- /dev/null +++ b/src/lang-ietfabnf.js @@ -0,0 +1,39 @@ +/** + * @license + * Copyright (C) 2008 Julian Reschke + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview + * Registers a language handler for IETF ABNF, as specified in RFC 5234, + * and extended in RFCs 7230 and 7405. + */ + +PR['registerLangHandler']( + PR['createSimpleLexer']( + [ + // comment + [PR['PR_COMMENT'], /;[^\r\n]*/, null, ";"], + ], + [ + // string, binary, decimal and hex literals + [PR['PR_LITERAL'], /((\%s)?"[^"]*"|(\%x[A-Za-z0-9]+(-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*))|(\%d[0-9]+(-[0-9]+|[\.[0-9]+]*))|(\%b[01]+(-[01]+|[\.[01]+]*)))/, null], + // prose rule + [PR['PR_PLAIN'], /<[^<>]*>/, null], + // rule name + [PR['PR_KEYWORD'], /([A-Za-z][A-Za-z0-9-]*)/, null], + [PR['PR_PUNCTUATION'], /[=\(\)\*\/\[\]#]/, null], + ]), + ['ietfabnf']); From acd3dfee679ac1e63eb5e584e09dd184d72a6c71 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 14:41:33 +0100 Subject: [PATCH 2/7] make base URI point to clone --- src/run_prettify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run_prettify.js b/src/run_prettify.js index f71fc192..787b2b62 100644 --- a/src/run_prettify.js +++ b/src/run_prettify.js @@ -228,7 +228,7 @@ var IN_GLOBAL_SCOPE = false; // This only works if this script is loaded via https : something // over which we exercise no control. var LOADER_BASE_URL = - 'https://cdn.rawgit.com/google/code-prettify/master/loader'; + 'https://cdn.rawgit.com/reschke/code-prettify/master/src/'; for (var i = 0, n = langs.length; i < n; ++i) (function (lang) { var script = doc.createElement("script"); From 567f9a9bf4dff93f03c2b3fb1e0c3a92ab20b135 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 15:49:38 +0100 Subject: [PATCH 3/7] Revert "make base URI point to clone" This reverts commit acd3dfee679ac1e63eb5e584e09dd184d72a6c71. --- src/run_prettify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run_prettify.js b/src/run_prettify.js index 787b2b62..f71fc192 100644 --- a/src/run_prettify.js +++ b/src/run_prettify.js @@ -228,7 +228,7 @@ var IN_GLOBAL_SCOPE = false; // This only works if this script is loaded via https : something // over which we exercise no control. var LOADER_BASE_URL = - 'https://cdn.rawgit.com/reschke/code-prettify/master/src/'; + 'https://cdn.rawgit.com/google/code-prettify/master/loader'; for (var i = 0, n = langs.length; i < n; ++i) (function (lang) { var script = doc.createElement("script"); From e245b3f2b679ede1e14bd55ec4f5c0fadc78da65 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 19:03:45 +0100 Subject: [PATCH 4/7] add comments on the nature of the extensions, and also support %i in addition to %s --- src/lang-ietfabnf.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lang-ietfabnf.js b/src/lang-ietfabnf.js index b7037ecf..2f531200 100644 --- a/src/lang-ietfabnf.js +++ b/src/lang-ietfabnf.js @@ -18,7 +18,7 @@ /** * @fileoverview * Registers a language handler for IETF ABNF, as specified in RFC 5234, - * and extended in RFCs 7230 and 7405. + * and extended in RFCs 7230 (list production) and 7405 (%s and %i). */ PR['registerLangHandler']( @@ -29,11 +29,11 @@ PR['registerLangHandler']( ], [ // string, binary, decimal and hex literals - [PR['PR_LITERAL'], /((\%s)?"[^"]*"|(\%x[A-Za-z0-9]+(-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*))|(\%d[0-9]+(-[0-9]+|[\.[0-9]+]*))|(\%b[01]+(-[01]+|[\.[01]+]*)))/, null], + [PR['PR_LITERAL'], /((\%s|\%i)?"[^"]*"|(\%x[A-Za-z0-9]+(-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*))|(\%d[0-9]+(-[0-9]+|[\.[0-9]+]*))|(\%b[01]+(-[01]+|[\.[01]+]*)))/, null], // prose rule [PR['PR_PLAIN'], /<[^<>]*>/, null], // rule name [PR['PR_KEYWORD'], /([A-Za-z][A-Za-z0-9-]*)/, null], [PR['PR_PUNCTUATION'], /[=\(\)\*\/\[\]#]/, null], ]), - ['ietfabnf']); + ['ietf_abnf']); From d8a2671d424142f07dec1c64f6d4cb8cf858a607 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 19:46:03 +0100 Subject: [PATCH 5/7] slightly improve range/concatenation expressions --- src/lang-ietfabnf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang-ietfabnf.js b/src/lang-ietfabnf.js index 2f531200..fac76880 100644 --- a/src/lang-ietfabnf.js +++ b/src/lang-ietfabnf.js @@ -29,7 +29,7 @@ PR['registerLangHandler']( ], [ // string, binary, decimal and hex literals - [PR['PR_LITERAL'], /((\%s|\%i)?"[^"]*"|(\%x[A-Za-z0-9]+(-[A-Za-z0-9]+|[\.[A-Za-z0-9]+]*))|(\%d[0-9]+(-[0-9]+|[\.[0-9]+]*))|(\%b[01]+(-[01]+|[\.[01]+]*)))/, null], + [PR['PR_LITERAL'], /((\%s|\%i)?"[^"]*"|(\%x[A-Za-z0-9]+((-[A-Za-z0-9]+)|(\.[A-Za-z0-9]+)*))|(\%d[0-9]+((-[0-9]+)|(\.[0-9]+)*))|(\%b[01]+((-[01]+)|(\.[01]+)*)))/, null], // prose rule [PR['PR_PLAIN'], /<[^<>]*>/, null], // rule name From 2606f27f03f0d5a60466b389b85fbf9983ce6d9a Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 14 May 2018 19:47:46 +0100 Subject: [PATCH 6/7] fix date --- src/lang-ietfabnf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang-ietfabnf.js b/src/lang-ietfabnf.js index fac76880..29755351 100644 --- a/src/lang-ietfabnf.js +++ b/src/lang-ietfabnf.js @@ -1,6 +1,6 @@ /** * @license - * Copyright (C) 2008 Julian Reschke + * Copyright (C) 2018 Julian Reschke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 7616def06c20a819c450a15c1d075bf35f17319f Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 15 May 2018 11:24:37 +0100 Subject: [PATCH 7/7] - refactor literal parsing - detect control characters in string literals and prose - tune character classes --- src/lang-ietfabnf.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lang-ietfabnf.js b/src/lang-ietfabnf.js index 29755351..24ad5e7a 100644 --- a/src/lang-ietfabnf.js +++ b/src/lang-ietfabnf.js @@ -25,15 +25,21 @@ PR['registerLangHandler']( PR['createSimpleLexer']( [ // comment - [PR['PR_COMMENT'], /;[^\r\n]*/, null, ";"], + [PR['PR_COMMENT'], /^;[^\x00-\x1f]*/, null, ";"], ], [ - // string, binary, decimal and hex literals - [PR['PR_LITERAL'], /((\%s|\%i)?"[^"]*"|(\%x[A-Za-z0-9]+((-[A-Za-z0-9]+)|(\.[A-Za-z0-9]+)*))|(\%d[0-9]+((-[0-9]+)|(\.[0-9]+)*))|(\%b[01]+((-[01]+)|(\.[01]+)*)))/, null], + // string literals + [PR['PR_STRING'], /^(\%s|\%i)?"[^"\x00-\x1f]*"/, null], + // binary literals + [PR['PR_LITERAL'], /^\%b[01]+((-[01]+)|(\.[01]+)*)/, null], + // decimal literals + [PR['PR_LITERAL'], /^\%d[0-9]+((-[0-9]+)|(\.[0-9]+)*)/, null], + // hex literals + [PR['PR_LITERAL'], /^(\%x[A-Za-z0-9]+((-[A-Za-z0-9]+)|(\.[A-Za-z0-9]+)*))/, null], // prose rule - [PR['PR_PLAIN'], /<[^<>]*>/, null], + [PR['PR_NOCODE'], /^<[^>\x00-\x1f]*>/, null], // rule name - [PR['PR_KEYWORD'], /([A-Za-z][A-Za-z0-9-]*)/, null], - [PR['PR_PUNCTUATION'], /[=\(\)\*\/\[\]#]/, null], + [PR['PR_TYPE'], /^([A-Za-z][A-Za-z0-9-]*)/, null], + [PR['PR_PUNCTUATION'], /^[=\(\)\*\/\[\]#]/, null], ]), ['ietf_abnf']);