From a4542c4d3754eea1e49e801930672ef07fc54df4 Mon Sep 17 00:00:00 2001 From: Bart Kiers Date: Thu, 28 Apr 2016 22:41:11 +0200 Subject: [PATCH 1/2] Added an ANTLR v4 highlighter --- README.md | 1 + src/lang-antlr4.js | 0 2 files changed, 1 insertion(+) create mode 100644 src/lang-antlr4.js diff --git a/README.md b/README.md index baa69d86..8f965b1d 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Smalltalk, OCaml, etc. without a language extension. Other languages are supported via extensions: +[ANTLR 4](src/lang-antlr4.js); [Apollo](src/lang-apollo.js); [Basic](src/lang-basic.js); [Clojure](src/lang-clj.js); diff --git a/src/lang-antlr4.js b/src/lang-antlr4.js new file mode 100644 index 00000000..e69de29b From db3c2133b1fc64e1ead35744f721ebaf7bffbc13 Mon Sep 17 00:00:00 2001 From: Bart Kiers Date: Thu, 28 Apr 2016 22:45:09 +0200 Subject: [PATCH 2/2] The actual JS file now... --- src/lang-antlr4.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/lang-antlr4.js b/src/lang-antlr4.js index e69de29b..7c983270 100644 --- a/src/lang-antlr4.js +++ b/src/lang-antlr4.js @@ -0,0 +1,59 @@ +/** + * @license + * Copyright (C) 2016 Bart Kiers + * + * 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 ANTLR 4. + * + * To use, include prettify.js and this file in your HTML page. + * Then enclose your code in an HTML tag like so: + *
[your ANTLR grammar]
+ * + * Note that embedded code blocks, like `@members::` blocks, are not + * highlighted. These blocks can contain arbitrary target code, containing + * a large amount of nested curly braces: impossible to define with a (JS) + * regex. + * + * @author Bart Kiers + */ +PR['registerLangHandler']( + PR['createSimpleLexer']([], [ + + [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/], + + // Comments + [PR['PR_COMMENT'], /^\/\/[^\r\n]*/], + [PR['PR_COMMENT'], /^\/\*[\s\S]*?(?:\*\/|$)/], + + // Literal tokens: single quoted strings and character sets + [PR['PR_STRING'], /^'(?:\\.|[^\\'\r\n])+'/], + [PR['PR_STRING'], /^\[(?:\\.|[^\\\[\]])+]/], + + // Keywords: https://github.com/antlr/grammars-v4/blob/master/antlr4/ANTLRv4Lexer.g4 + [PR['PR_KEYWORD'], /^(?:options|tokens|import|fragment|lexer|parser|grammar\s+\w+|protected|public|private|returns|locals|throws|catch|finally|mode)\b/], + + // Predicates + [PR['PR_SOURCE'], /^\{.*?}\?/], + + // Lexer- and parser-rules + [PR['PR_TYPE'], /^[A-Z]\w*/], + [PR['PR_LITERAL'], /^[a-z]\w*/], + + // Fall through rule matching any char as a 'plain' char + [PR['PR_PLAIN'], /./] + ]), + ['antlr4']); \ No newline at end of file