diff --git a/loader/lang-eiffel.js b/loader/lang-eiffel.js new file mode 100644 index 00000000..31133a2f --- /dev/null +++ b/loader/lang-eiffel.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018-2020 Alexander Kogtenkov + * + * 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. + */ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^\s+/u,null,' \r\n\t\xA0'],["str",/^(?:'''|'[^']+')/,null,"'"],["str",/^"(?:(?:%[ \t\v]*[\r\n]\s*%|%"|[^"\r\n])*|\[(?=\s*[\r\n])[\s\S]*[\r\n]\s*\]|\{(?=\s*[\r\n])[\s\S]*[\r\n]\s*\})"/,null,'"'],["lit",/^0[bcx][a-f\d](?:[_a-f\d]*[a-f\d])?|(?:\d(?:[_\d]*\d)?(?:\.(?:\d(?:[_\d]*\d)?)?(?:e[-+]?\d+)?)?)/i,null,'0123456789']],[["com",/^--[^\r\n]*/],["kwd",/^\b(?:across|agent|alias|all|and|as|assign|attached|attribute|check|class|convert|create|debug|deferred|detachable|do|else|elseif|end|ensure|expanded|export|external|feature|from|frozen|if|implies|inherit|inspect|invariant|like|local|loop|not|note|obsolete|old|once|only|or|redefine|rename|require|rescue|retry|select|separate|some|then|undefine|until|variant|when|xor)\b/i],["kwd",/^\b(?:Current|Precursor|Result)\b/i],["kwd",/^[\u2200\u2203\xA6\u27F3\u27F2]/iu],["lit",/^\b(?:False|True|Void)\b/i],["typ",/^[A-Z][_A-Z\d]*/],["lit",/^\.\d(?:[_\d]*\d)?(?:e[-+]?\d+)?/i],["pln",/^[a-z]\w*/iu],["pun",/^[^\s\xA0\w'"\u2200\u2203\xA6\u27F3\u27F2]+/]]),['eiffel','e']); diff --git a/src/lang-eiffel.js b/src/lang-eiffel.js new file mode 100644 index 00000000..472e371d --- /dev/null +++ b/src/lang-eiffel.js @@ -0,0 +1,61 @@ +/** + * @license + * Copyright (C) 2018-2020 Alexander Kogtenkov + * + * 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 Eiffel. + * + * To use, include prettify.js and this file in your HTML page. + * Then put your code in an HTML tag like + *
(my Eiffel code)+ * + * @author Alexander Kogtenkov + */ + +PR.registerLangHandler( + PR.createSimpleLexer( + [ // shortcutStylePatterns + // Whitespace + [PR['PR_PLAIN'], /^\s+/u, null, ' \r\n\t\xA0'], + // Character + [PR['PR_STRING'], /^(?:'''|'[^']+')/, null, "'"], + // String + [PR['PR_STRING'], /^"(?:(?:%[ \t\v]*[\r\n]\s*%|%"|[^"\r\n])*|\[(?=\s*[\r\n])[\s\S]*[\r\n]\s*\]|\{(?=\s*[\r\n])[\s\S]*[\r\n]\s*\})"/, null, '"'], + // Integer or real starting from a digit + [PR['PR_LITERAL'], /^0[bcx][a-f\d](?:[_a-f\d]*[a-f\d])?|(?:\d(?:[_\d]*\d)?(?:\.(?:\d(?:[_\d]*\d)?)?(?:e[-+]?\d+)?)?)/i, null, '0123456789'] + ], + [ // fallthroughStylePatterns + // A line comment + [PR['PR_COMMENT'], /^--[^\r\n]*/], + // Keyword + [PR['PR_KEYWORD'], /^\b(?:across|agent|alias|all|and|as|assign|attached|attribute|check|class|convert|create|debug|deferred|detachable|do|else|elseif|end|ensure|expanded|export|external|feature|from|frozen|if|implies|inherit|inspect|invariant|like|local|loop|not|note|obsolete|old|once|only|or|redefine|rename|require|rescue|retry|select|separate|some|then|undefine|until|variant|when|xor)\b/i], + // A reserved word: entity + [PR['PR_KEYWORD'], /^\b(?:Current|Precursor|Result)\b/i], + // A reserved symbol: syntax (for_all, there_exists, broken_bar, clockwise_gapped_circle_arrow, anticlockwise_gapped_circle_arrow) + [PR['PR_KEYWORD'], /^[\u2200\u2203\xA6\u27F3\u27F2]/iu], + // A reserved word: value + [PR['PR_LITERAL'], /^\b(?:False|True|Void)\b/i], + // Treat an upper case identifier as a type + [PR['PR_TYPE'], /^[A-Z][_A-Z\d]*/], + // Real starting from a dot + [PR['PR_LITERAL'], /^\.\d(?:[_\d]*\d)?(?:e[-+]?\d+)?/i], + // Identifier + [PR['PR_PLAIN'], /^[a-z]\w*/iu], + // Other symbols + [PR['PR_PUNCTUATION'], /^[^\s\xA0\w'"\u2200\u2203\xA6\u27F3\u27F2]+/] + ]), + ['eiffel','e']); diff --git a/tests/prettify_test_2.html b/tests/prettify_test_2.html index c62e032b..69dd4e24 100644 --- a/tests/prettify_test_2.html +++ b/tests/prettify_test_2.html @@ -25,6 +25,7 @@ 'lang-clj.js', 'lang-css.js', 'lang-dart.js', + 'lang-eiffel.js', 'lang-ex.js', 'lang-kotlin.js', 'lang-lisp.js', @@ -1201,5 +1202,65 @@
+note + description: "[ + A test class with "string" literals, numbers, etc. + ]" + usage: "[testing %"quotes%"]" + +class POLYGON + +inherit + ANY + rename + default_create as make + redefine + make, + out + end + +feature {NONE} -- Creation + + make + -- Set coordinates to (0, 0). + do + x_offset := 0 + y_offset := 123 - 0c124 + 0b001 + 1.0 + 1. - .0 + .1e3 - 1.e03 + (1_234.567_8 - 12_345.678e-1) + end + +feature -- Access + + x_offset, y_offset: INTEGER_64 + -- Offset of the polygon. + + mask: NATURAL_8 = 0xA5 + -- A color mask. + +feature -- Output + + out: STRING + -- <Precursor> + do + Result := + "An old-style % + %multi-line string with " + + "% + %%"quotes%"% + %" + + "{ + and a "new"-style one. + }" + Result.precede ('=') + Result.append_boolean (∀ x: Result ¦ x >= ' ') + ensure then + result_attached: Result /= Void + end + +end ++