-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for ANTLR4. Languages embedded via actions are not highlighted.
- Loading branch information
1 parent
7db0cab
commit aaaa29a
Showing
18 changed files
with
572 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Prism.languages.antlr4 = { | ||
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, | ||
'string': { | ||
pattern: /'(?:\\.|[^\\'\r\n])*'/, | ||
greedy: true | ||
}, | ||
'character-class': { | ||
pattern: /\[(?:\\.|[^\\\]\r\n])*\]/, | ||
greedy: true, | ||
alias: 'regex', | ||
inside: { | ||
'range': { | ||
pattern: /([^[]|(?:^|[^\\])(?:\\\\)*\\\[)-(?!\])/, | ||
lookbehind: true, | ||
alias: 'punctuation' | ||
}, | ||
'escape': /\\(?:u(?:[a-fA-F\d]{4}|\{[a-fA-F\d]+\})|[pP]\{[=\w-]+\}|[^\r\nupP])/, | ||
'punctuation': /[\[\]]/ | ||
} | ||
}, | ||
'action': { | ||
pattern: /\{(?:[^{}]|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*\}/, | ||
greedy: true, | ||
inside: { | ||
'content': { | ||
// this might be C, C++, Python, Java, C#, or any other language ANTLR4 compiles to | ||
pattern: /(\{)[\s\S]+(?=\})/, | ||
lookbehind: true | ||
}, | ||
'punctuation': /[{}]/ | ||
} | ||
}, | ||
'command': { | ||
pattern: /(->\s*)(?:\s*(?:,\s*)?[a-z]\w*(?:\s*\([^()\r\n]*\))?)+(?=\s*;)/i, | ||
lookbehind: true, | ||
inside: { | ||
'function': /\b\w+(?=\s*(?:[,(]|$))/, | ||
'punctuation': /[,()]/ | ||
} | ||
}, | ||
'annotation': { | ||
pattern: /@\w+(?:::\w+)*/, | ||
alias: 'keyword' | ||
}, | ||
'label': { | ||
pattern: /#[ \t]*\w+/, | ||
alias: 'punctuation' | ||
}, | ||
'keyword': /\b(?:catch|channels|finally|fragment|grammar|import|lexer|locals|mode|options|parser|returns|throws|tokens)\b/, | ||
'definition': [ | ||
{ | ||
pattern: /\b[a-z]\w*(?=\s*:)/, | ||
alias: ['rule', 'class-name'] | ||
}, | ||
{ | ||
pattern: /\b[A-Z]\w*(?=\s*:)/, | ||
alias: ['token', 'constant'] | ||
}, | ||
], | ||
'constant': /\b[A-Z][A-Z_]*\b/, | ||
'operator': /\.\.|->|[|~]|[*+?]\??/, | ||
'punctuation': /[;:()=]/ | ||
}; | ||
|
||
Prism.languages.g4 = Prism.languages.antlr4; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
options { superClass = LexerAdaptor; } | ||
|
||
@lexer::header { | ||
import { Token } from 'antlr4ts/Token'; | ||
import { CommonToken } from 'antlr4ts/CommonToken'; | ||
import { Python3Parser } from './Python3Parser'; | ||
} | ||
|
||
END : 'end' {System.out.println("found an end");} ; | ||
|
||
@header { | ||
from LexerAdaptor import LexerAdaptor | ||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "options"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["content", " superClass = LexerAdaptor; "], | ||
["punctuation", "}"] | ||
]], | ||
["annotation", "@lexer::header"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["content", "\n import { Token } from 'antlr4ts/Token';\n import { CommonToken } from 'antlr4ts/CommonToken';\n import { Python3Parser } from './Python3Parser';\n"], | ||
["punctuation", "}"] | ||
]], | ||
["definition", "END"], | ||
["punctuation", ":"], | ||
["string", "'end'"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["content", "System.out.println(\"found an end\");"], | ||
["punctuation", "}"] | ||
]], | ||
["punctuation", ";"], | ||
["annotation", "@header"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["content", "\nfrom LexerAdaptor import LexerAdaptor\n"], | ||
["punctuation", "}"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for actions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@header {} | ||
@lexer::header {} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["annotation", "@header"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["punctuation", "}"] | ||
]], | ||
["annotation", "@lexer::header"], | ||
["action", [ | ||
["punctuation", "{"], | ||
["punctuation", "}"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for annotations. |
Oops, something went wrong.