From aa97241058e5889c6e2eb4d60331b0caa4166dc2 Mon Sep 17 00:00:00 2001 From: Sam Chen Date: Tue, 11 Aug 2020 19:37:13 +0800 Subject: [PATCH] Update `prism` to `1.21.0` See: --- index.js | 17 ++ lang/agda.js | 30 +++ lang/al.js | 30 +++ lang/antlr4.js | 2 +- lang/apl.js | 4 +- lang/applescript.js | 2 +- lang/asciidoc.js | 2 +- lang/asm6502.js | 6 +- lang/aspnet.js | 3 +- lang/autohotkey.js | 30 +-- lang/bash.js | 2 +- lang/batch.js | 4 +- lang/c.js | 25 ++- lang/cpp.js | 79 ++++++-- lang/csharp.js | 25 ++- lang/csp.js | 2 +- lang/css-extras.js | 17 +- lang/css.js | 20 +- lang/cypher.js | 40 ++++ lang/d.js | 2 +- lang/dart.js | 2 +- lang/dhall.js | 72 +++++++ lang/diff.js | 13 +- lang/docker.js | 5 +- lang/ebnf.js | 2 +- lang/editorconfig.js | 33 ++++ lang/eiffel.js | 4 +- lang/ejs.js | 3 +- lang/elixir.js | 2 +- lang/erb.js | 4 +- lang/etlua.js | 2 + lang/excel-formula.js | 6 +- lang/ftl.js | 4 +- lang/glsl.js | 14 +- lang/graphql.js | 20 +- lang/groovy.js | 3 +- lang/haml.js | 3 +- lang/hcl.js | 8 +- lang/hlsl.js | 26 +++ lang/hpkp.js | 4 +- lang/hsts.js | 4 +- lang/iecst.js | 37 ++++ lang/ignore.js | 28 +++ lang/io.js | 2 +- lang/j.js | 2 +- lang/java.js | 9 +- lang/javadoc.js | 102 +++++++--- lang/javascript.js | 8 +- lang/jq.js | 4 +- lang/jsdoc.js | 22 ++- lang/json.js | 11 +- lang/json5.js | 2 +- lang/jsstacktrace.js | 47 +++++ lang/jsx.js | 4 +- lang/julia.js | 30 ++- lang/kotlin.js | 4 +- lang/latte.js | 2 + lang/lilypond.js | 5 +- lang/livescript.js | 4 +- lang/lolcode.js | 2 +- lang/markdown.js | 22 +-- lang/markup.js | 55 ++++-- lang/neon.js | 2 +- lang/objectivec.js | 3 +- lang/ocaml.js | 2 +- lang/opencl.js | 2 - lang/oz.js | 8 +- lang/parigp.js | 2 +- lang/pascal.js | 2 +- lang/peoplecode.js | 46 +++++ lang/php.js | 6 +- lang/phpdoc.js | 2 + lang/powershell.js | 6 +- lang/protobuf.js | 23 ++- lang/pug.js | 4 +- lang/pure.js | 6 +- lang/purebasic.js | 72 +++++++ lang/python.js | 4 +- lang/q.js | 2 +- lang/qml.js | 2 +- lang/racket.js | 75 ++++++++ lang/regex.js | 79 +++++--- lang/renpy.js | 3 +- lang/rip.js | 4 +- lang/robotframework.js | 4 +- lang/ruby.js | 85 +++------ lang/rust.js | 179 ++++++++++++------ lang/sas.js | 44 +++-- lang/scheme.js | 50 ++++- lang/shell-session.js | 9 +- lang/smali.js | 87 +++++++++ lang/solidity.js | 3 +- lang/sql.js | 2 +- lang/stylus.js | 45 ++++- lang/t4-cs.js | 2 + lang/t4-vb.js | 6 +- lang/tap.js | 3 +- lang/textile.js | 98 +++++----- lang/toml.js | 25 +-- lang/tt2.js | 2 +- lang/turtle.js | 2 +- lang/typescript.js | 40 +++- lang/unrealscript.js | 46 +++++ lang/visual-basic.js | 5 +- lang/warpscript.js | 28 +++ lang/xml-doc.js | 42 ++++ lang/xquery.js | 6 +- lang/yang.js | 27 +++ package.json | 2 +- readme.md | 33 +++- script/languages.js | 21 +- test/fixtures/js-keywords/output.html | 4 +- test/fixtures/jsx-advanced/output.html | 4 +- test/fixtures/jsx/output.html | 2 +- .../fixtures/markdown-sublanguage/output.html | 2 +- .../markup-character-entity/output.html | 2 +- test/fixtures/rust-comments/output.html | 4 +- test/fixtures/rust-numbers/output.html | 4 +- test/fixtures/rust-strings/output.html | 4 +- test/fixtures/rust-traits/output.html | 6 +- test/fixtures/xml-large/output.html | 4 +- 121 files changed, 1740 insertions(+), 525 deletions(-) create mode 100644 lang/agda.js create mode 100644 lang/al.js create mode 100644 lang/cypher.js create mode 100644 lang/dhall.js create mode 100644 lang/editorconfig.js create mode 100644 lang/hlsl.js create mode 100644 lang/iecst.js create mode 100644 lang/ignore.js create mode 100644 lang/jsstacktrace.js create mode 100644 lang/peoplecode.js create mode 100644 lang/purebasic.js create mode 100644 lang/racket.js create mode 100644 lang/smali.js create mode 100644 lang/unrealscript.js create mode 100644 lang/warpscript.js create mode 100644 lang/xml-doc.js create mode 100644 lang/yang.js diff --git a/index.js b/index.js index c1591c0..a28798b 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,8 @@ refractor.register(require('./lang/abap.js')) refractor.register(require('./lang/abnf.js')) refractor.register(require('./lang/actionscript.js')) refractor.register(require('./lang/ada.js')) +refractor.register(require('./lang/agda.js')) +refractor.register(require('./lang/al.js')) refractor.register(require('./lang/antlr4.js')) refractor.register(require('./lang/apacheconf.js')) refractor.register(require('./lang/apl.js')) @@ -40,14 +42,17 @@ refractor.register(require('./lang/crystal.js')) refractor.register(require('./lang/csharp.js')) refractor.register(require('./lang/csp.js')) refractor.register(require('./lang/css-extras.js')) +refractor.register(require('./lang/cypher.js')) refractor.register(require('./lang/d.js')) refractor.register(require('./lang/dart.js')) refractor.register(require('./lang/dax.js')) +refractor.register(require('./lang/dhall.js')) refractor.register(require('./lang/diff.js')) refractor.register(require('./lang/django.js')) refractor.register(require('./lang/dns-zone-file.js')) refractor.register(require('./lang/docker.js')) refractor.register(require('./lang/ebnf.js')) +refractor.register(require('./lang/editorconfig.js')) refractor.register(require('./lang/eiffel.js')) refractor.register(require('./lang/ejs.js')) refractor.register(require('./lang/elixir.js')) @@ -77,11 +82,14 @@ refractor.register(require('./lang/handlebars.js')) refractor.register(require('./lang/haskell.js')) refractor.register(require('./lang/haxe.js')) refractor.register(require('./lang/hcl.js')) +refractor.register(require('./lang/hlsl.js')) refractor.register(require('./lang/hpkp.js')) refractor.register(require('./lang/hsts.js')) refractor.register(require('./lang/http.js')) refractor.register(require('./lang/ichigojam.js')) refractor.register(require('./lang/icon.js')) +refractor.register(require('./lang/iecst.js')) +refractor.register(require('./lang/ignore.js')) refractor.register(require('./lang/inform7.js')) refractor.register(require('./lang/ini.js')) refractor.register(require('./lang/io.js')) @@ -98,6 +106,7 @@ refractor.register(require('./lang/jsdoc.js')) refractor.register(require('./lang/json.js')) refractor.register(require('./lang/json5.js')) refractor.register(require('./lang/jsonp.js')) +refractor.register(require('./lang/jsstacktrace.js')) refractor.register(require('./lang/jsx.js')) refractor.register(require('./lang/julia.js')) refractor.register(require('./lang/keyman.js')) @@ -138,6 +147,7 @@ refractor.register(require('./lang/parser.js')) refractor.register(require('./lang/pascal.js')) refractor.register(require('./lang/pascaligo.js')) refractor.register(require('./lang/pcaxis.js')) +refractor.register(require('./lang/peoplecode.js')) refractor.register(require('./lang/perl.js')) refractor.register(require('./lang/php-extras.js')) refractor.register(require('./lang/php.js')) @@ -152,11 +162,13 @@ refractor.register(require('./lang/protobuf.js')) refractor.register(require('./lang/pug.js')) refractor.register(require('./lang/puppet.js')) refractor.register(require('./lang/pure.js')) +refractor.register(require('./lang/purebasic.js')) refractor.register(require('./lang/python.js')) refractor.register(require('./lang/q.js')) refractor.register(require('./lang/qml.js')) refractor.register(require('./lang/qore.js')) refractor.register(require('./lang/r.js')) +refractor.register(require('./lang/racket.js')) refractor.register(require('./lang/reason.js')) refractor.register(require('./lang/regex.js')) refractor.register(require('./lang/renpy.js')) @@ -172,6 +184,7 @@ refractor.register(require('./lang/scala.js')) refractor.register(require('./lang/scheme.js')) refractor.register(require('./lang/scss.js')) refractor.register(require('./lang/shell-session.js')) +refractor.register(require('./lang/smali.js')) refractor.register(require('./lang/smalltalk.js')) refractor.register(require('./lang/smarty.js')) refractor.register(require('./lang/solidity.js')) @@ -195,6 +208,7 @@ refractor.register(require('./lang/tt2.js')) refractor.register(require('./lang/turtle.js')) refractor.register(require('./lang/twig.js')) refractor.register(require('./lang/typescript.js')) +refractor.register(require('./lang/unrealscript.js')) refractor.register(require('./lang/vala.js')) refractor.register(require('./lang/vbnet.js')) refractor.register(require('./lang/velocity.js')) @@ -202,10 +216,13 @@ refractor.register(require('./lang/verilog.js')) refractor.register(require('./lang/vhdl.js')) refractor.register(require('./lang/vim.js')) refractor.register(require('./lang/visual-basic.js')) +refractor.register(require('./lang/warpscript.js')) refractor.register(require('./lang/wasm.js')) refractor.register(require('./lang/wiki.js')) refractor.register(require('./lang/xeora.js')) +refractor.register(require('./lang/xml-doc.js')) refractor.register(require('./lang/xojo.js')) refractor.register(require('./lang/xquery.js')) refractor.register(require('./lang/yaml.js')) +refractor.register(require('./lang/yang.js')) refractor.register(require('./lang/zig.js')) diff --git a/lang/agda.js b/lang/agda.js new file mode 100644 index 0000000..e1e340d --- /dev/null +++ b/lang/agda.js @@ -0,0 +1,30 @@ +'use strict' + +module.exports = agda +agda.displayName = 'agda' +agda.aliases = [] +function agda(Prism) { + ;(function (Prism) { + Prism.languages.agda = { + comment: /\{-[\s\S]*?(?:-\}|$)|--.*/, + string: { + pattern: /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/, + greedy: true + }, + punctuation: /[(){}⦃⦄.;@]/, + 'class-name': { + pattern: /((?:data|record) +)\S+/, + lookbehind: true + }, + function: { + pattern: /(^[ \t]*)[^:\r\n]+?(?=:)/m, + lookbehind: true + }, + operator: { + pattern: /(^\s*|\s)(?:[=|:∀→λ\\?_]|->)(?=\s)/, + lookbehind: true + }, + keyword: /\b(?:Set|abstract|constructor|data|eta-equality|field|forall|forall|hiding|import|in|inductive|infix|infixl|infixr|instance|let|macro|module|mutual|no-eta-equality|open|overlap|pattern|postulate|primitive|private|public|quote|quoteContext|quoteGoal|quoteTerm|record|renaming|rewrite|syntax|tactic|unquote|unquoteDecl|unquoteDef|using|variable|where|with)\b/ + } + })(Prism) +} diff --git a/lang/al.js b/lang/al.js new file mode 100644 index 0000000..2f0ca60 --- /dev/null +++ b/lang/al.js @@ -0,0 +1,30 @@ +'use strict' + +module.exports = al +al.displayName = 'al' +al.aliases = [] +function al(Prism) { + // based on https://github.com/microsoft/AL/blob/master/grammar/alsyntax.tmlanguage + Prism.languages.al = { + comment: /\/\/.*|\/\*[\s\S]*?\*\//, + string: { + pattern: /'(?:''|[^'\r\n])*'(?!')|"(?:""|[^"\r\n])*"(?!")/, + greedy: true + }, + function: { + pattern: /(\b(?:event|procedure|trigger)\s+|(?:^|[^.])\.\s*)[a-z_]\w*(?=\s*\()/i, + lookbehind: true + }, + keyword: [ + // keywords + /\b(?:array|asserterror|begin|break|case|do|downto|else|end|event|exit|for|foreach|function|if|implements|in|indataset|interface|internal|local|of|procedure|program|protected|repeat|runonclient|securityfiltering|suppressdispose|temporary|then|to|trigger|until|var|while|with|withevents)\b/i, // objects and metadata that are used like keywords + /\b(?:action|actions|addafter|addbefore|addfirst|addlast|area|assembly|chartpart|codeunit|column|controladdin|cuegroup|customizes|dataitem|dataset|dotnet|elements|enum|enumextension|extends|field|fieldattribute|fieldelement|fieldgroup|fieldgroups|fields|filter|fixed|grid|group|key|keys|label|labels|layout|modify|moveafter|movebefore|movefirst|movelast|page|pagecustomization|pageextension|part|profile|query|repeater|report|requestpage|schema|separator|systempart|table|tableelement|tableextension|textattribute|textelement|type|usercontrol|value|xmlport)\b/i + ], + number: /\b(?:0x[\da-f]+|(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(?:F|U(?:LL?)?|LL?)?\b/i, + boolean: /\b(?:false|true)\b/i, + variable: /\b(?:Curr(?:FieldNo|Page|Report)|RequestOptionsPage|x?Rec)\b/, + 'class-name': /\b(?:automation|biginteger|bigtext|blob|boolean|byte|char|clienttype|code|completiontriggererrorlevel|connectiontype|database|dataclassification|datascope|date|dateformula|datetime|decimal|defaultlayout|dialog|dictionary|dotnetassembly|dotnettypedeclaration|duration|errorinfo|errortype|executioncontext|executionmode|fieldclass|fieldref|fieldtype|file|filterpagebuilder|guid|httpclient|httpcontent|httpheaders|httprequestmessage|httpresponsemessage|instream|integer|joker|jsonarray|jsonobject|jsontoken|jsonvalue|keyref|list|moduledependencyinfo|moduleinfo|none|notification|notificationscope|objecttype|option|outstream|pageresult|record|recordid|recordref|reportformat|securityfilter|sessionsettings|tableconnectiontype|tablefilter|testaction|testfield|testfilterfield|testpage|testpermissions|testrequestpage|text|textbuilder|textconst|textencoding|time|transactionmodel|transactiontype|variant|verbosity|version|view|views|webserviceactioncontext|webserviceactionresultcode|xmlattribute|xmlattributecollection|xmlcdata|xmlcomment|xmldeclaration|xmldocument|xmldocumenttype|xmlelement|xmlnamespacemanager|xmlnametable|xmlnode|xmlnodelist|xmlprocessinginstruction|xmlreadoptions|xmltext|xmlwriteoptions)\b/i, + operator: /\.\.|:[=:]|[-+*/]=?|<>|[<>]=?|=|\b(?:and|div|mod|not|or|xor)\b/i, + punctuation: /[()\[\]{}:.;,]/ + } +} diff --git a/lang/antlr4.js b/lang/antlr4.js index 0647648..5408c21 100644 --- a/lang/antlr4.js +++ b/lang/antlr4.js @@ -37,7 +37,7 @@ function antlr4(Prism) { } }, command: { - pattern: /(->\s*)(?:\s*(?:,\s*)?[a-z]\w*(?:\s*\([^()\r\n]*\))?)+(?=\s*;)/i, + pattern: /(->\s*)(?:\s*(?:,\s*)?\b[a-z]\w*(?:\s*\([^()\r\n]*\))?)+(?=\s*;)/i, lookbehind: true, inside: { function: /\b\w+(?=\s*(?:[,(]|$))/, diff --git a/lang/apl.js b/lang/apl.js index 5cfa7a4..07fd6fa 100644 --- a/lang/apl.js +++ b/lang/apl.js @@ -10,7 +10,7 @@ function apl(Prism) { pattern: /'(?:[^'\r\n]|'')*'/, greedy: true }, - number: /¯?(?:\d*\.?\d+(?:e[+¯]?\d+)?|¯|∞)(?:j¯?(?:\d*\.?\d+(?:e[+¯]?\d+)?|¯|∞))?/i, + number: /¯?(?:\d*\.?\b\d+(?:e[+¯]?\d+)?|¯|∞)(?:j¯?(?:\d*\.?\d+(?:e[+¯]?\d+)?|¯|∞))?/i, statement: /:[A-Z][a-z][A-Za-z]*\b/, 'system-function': { pattern: /⎕[A-Z]+/i, @@ -23,7 +23,7 @@ function apl(Prism) { alias: 'operator' }, 'dyadic-operator': { - pattern: /[.⍣⍠⍤∘⌸@⌺]/, + pattern: /[.⍣⍠⍤∘⌸@⌺⍥]/, alias: 'operator' }, assignment: { diff --git a/lang/applescript.js b/lang/applescript.js index 98e510b..84e260f 100644 --- a/lang/applescript.js +++ b/lang/applescript.js @@ -7,7 +7,7 @@ function applescript(Prism) { Prism.languages.applescript = { comment: [ // Allow one level of nesting - /\(\*(?:\(\*[\s\S]*?\*\)|[\s\S])*?\*\)/, + /\(\*(?:\(\*(?:[^*]|\*(?!\)))*\*\)|(?!\(\*)[\s\S])*?\*\)/, /--.+/, /#.+/ ], diff --git a/lang/asciidoc.js b/lang/asciidoc.js index cb39d77..a039c44 100644 --- a/lang/asciidoc.js +++ b/lang/asciidoc.js @@ -141,7 +141,7 @@ Then we handle the unconstrained quotes. Those do not have the restrictions of the constrained quotes. They are, in order: __emphasis__, **strong**, ++monospace++, +++passthrough+++, ##unquoted##, $$passthrough$$, ~subscript~, ^superscript^, {attribute-reference}, [[anchor]], [[[bibliography anchor]]], <>, (((indexes))) and ((indexes)) */ - pattern: /(^|[^\\])(?:(?:\B\[(?:[^\]\\"]|(["'])(?:(?!\2)[^\\]|\\.)*\2|\\.)*\])?(?:\b_(?!\s)(?: _|[^_\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: _|[^_\\\r\n]|\\.)+)*_\b|\B``(?!\s).+?(?:(?:\r?\n|\r).+?)*''\B|\B`(?!\s)(?: ['`]|.)+?(?:(?:\r?\n|\r)(?: ['`]|.)+?)*['`]\B|\B(['*+#])(?!\s)(?: \3|(?!\3)[^\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: \3|(?!\3)[^\\\r\n]|\\.)+)*\3\B)|(?:\[(?:[^\]\\"]|(["'])(?:(?!\4)[^\\]|\\.)*\4|\\.)*\])?(?:(__|\*\*|\+\+\+?|##|\$\$|[~^]).+?(?:(?:\r?\n|\r).+?)*\5|\{[^}\r\n]+\}|\[\[\[?.+?(?:(?:\r?\n|\r).+?)*\]?\]\]|<<.+?(?:(?:\r?\n|\r).+?)*>>|\(\(\(?.+?(?:(?:\r?\n|\r).+?)*\)?\)\)))/m, + pattern: /(^|[^\\])(?:(?:\B\[(?:[^\]\\"]|(["'])(?:(?!\2)[^\\]|\\.)*\2|\\.)*\])?(?:\b_(?!\s)(?: _|[^_\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: _|[^_\\\r\n]|\\.)+)*_\b|\B``(?!\s).+?(?:(?:\r?\n|\r).+?)*''\B|\B`(?!\s)(?:[^`'\s]|\s+\S)+['`]\B|\B(['*+#])(?!\s)(?: \3|(?!\3)[^\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: \3|(?!\3)[^\\\r\n]|\\.)+)*\3\B)|(?:\[(?:[^\]\\"]|(["'])(?:(?!\4)[^\\]|\\.)*\4|\\.)*\])?(?:(__|\*\*|\+\+\+?|##|\$\$|[~^]).+?(?:(?:\r?\n|\r).+?)*\5|\{[^}\r\n]+\}|\[\[\[?.+?(?:(?:\r?\n|\r).+?)*\]?\]\]|<<.+?(?:(?:\r?\n|\r).+?)*>>|\(\(\(?.+?(?:(?:\r?\n|\r).+?)*\)?\)\)))/m, lookbehind: true, inside: { attributes: attributes, diff --git a/lang/asm6502.js b/lang/asm6502.js index 7b1d311..8dd6b43 100644 --- a/lang/asm6502.js +++ b/lang/asm6502.js @@ -16,15 +16,15 @@ function asm6502(Prism) { alias: 'property' }, hexnumber: { - pattern: /#?\$[\da-f]{2,4}/i, + pattern: /#?\$[\da-f]{2,4}\b/i, alias: 'string' }, binarynumber: { - pattern: /#?%[01]+/, + pattern: /#?%[01]+\b/, alias: 'string' }, decimalnumber: { - pattern: /#?\d+/, + pattern: /#?\b\d+\b/, alias: 'string' }, register: { diff --git a/lang/aspnet.js b/lang/aspnet.js index 6797440..5abc551 100644 --- a/lang/aspnet.js +++ b/lang/aspnet.js @@ -1,9 +1,10 @@ 'use strict' - +var refractorCsharp = require('./csharp.js') module.exports = aspnet aspnet.displayName = 'aspnet' aspnet.aliases = [] function aspnet(Prism) { + Prism.register(refractorCsharp) Prism.languages.aspnet = Prism.languages.extend('markup', { 'page-directive': { pattern: /<%\s*@.*%>/i, diff --git a/lang/autohotkey.js b/lang/autohotkey.js index 5385357..c70bb47 100644 --- a/lang/autohotkey.js +++ b/lang/autohotkey.js @@ -6,25 +6,31 @@ autohotkey.aliases = [] function autohotkey(Prism) { // NOTES - follows first-first highlight method, block is locked after highlight, different from SyntaxHl Prism.languages.autohotkey = { - comment: { - pattern: /(^[^";\n]*(?:"[^"\n]*?"[^"\n]*?)*)(?:;.*$|^\s*\/\*[\s\S]*\n\*\/)/m, - lookbehind: true - }, + comment: [ + { + pattern: /(^|\s);.*/, + lookbehind: true + }, + { + pattern: /(^\s*)\/\*[^\r\n]*(?:[\r\n](?![ \t]*\*\/)|[^\r\n])*(?:[\r\n][ \t]*\*\/)?/m, + lookbehind: true, + greedy: true + } + ], string: /"(?:[^"\n\r]|"")*"/m, - function: /[^(); \t,\n+*\-=?>:\\\/<&%\[\]]+?(?=\()/m, - //function - don't use .*\) in the end bcoz string locks it tag: /^[ \t]*[^\s:]+?(?=:(?:[^:]|$))/m, //labels variable: /%\w+%/, number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/, operator: /\?|\/\/?=?|:=|\|[=|]?|&[=&]?|\+[=+]?|-[=-]?|\*[=*]?|<(?:<=?|>|=)?|>>?=?|[.^!=~]=?|\b(?:AND|NOT|OR)\b/, - punctuation: /[{}[\]():,]/, boolean: /\b(?:true|false)\b/, - selector: /\b(?:AutoTrim|BlockInput|Break|Click|ClipWait|Continue|Control|ControlClick|ControlFocus|ControlGet|ControlGetFocus|ControlGetPos|ControlGetText|ControlMove|ControlSend|ControlSendRaw|ControlSetText|CoordMode|Critical|DetectHiddenText|DetectHiddenWindows|Drive|DriveGet|DriveSpaceFree|EnvAdd|EnvDiv|EnvGet|EnvMult|EnvSet|EnvSub|EnvUpdate|Exit|ExitApp|FileAppend|FileCopy|FileCopyDir|FileCreateDir|FileCreateShortcut|FileDelete|FileEncoding|FileGetAttrib|FileGetShortcut|FileGetSize|FileGetTime|FileGetVersion|FileInstall|FileMove|FileMoveDir|FileRead|FileReadLine|FileRecycle|FileRecycleEmpty|FileRemoveDir|FileSelectFile|FileSelectFolder|FileSetAttrib|FileSetTime|FormatTime|GetKeyState|Gosub|Goto|GroupActivate|GroupAdd|GroupClose|GroupDeactivate|Gui|GuiControl|GuiControlGet|Hotkey|ImageSearch|IniDelete|IniRead|IniWrite|Input|InputBox|KeyWait|ListHotkeys|ListLines|ListVars|Loop|Menu|MouseClick|MouseClickDrag|MouseGetPos|MouseMove|MsgBox|OnExit|OutputDebug|Pause|PixelGetColor|PixelSearch|PostMessage|Process|Progress|Random|RegDelete|RegRead|RegWrite|Reload|Repeat|Return|Run|RunAs|RunWait|Send|SendEvent|SendInput|SendMessage|SendMode|SendPlay|SendRaw|SetBatchLines|SetCapslockState|SetControlDelay|SetDefaultMouseSpeed|SetEnv|SetFormat|SetKeyDelay|SetMouseDelay|SetNumlockState|SetScrollLockState|SetStoreCapslockMode|SetTimer|SetTitleMatchMode|SetWinDelay|SetWorkingDir|Shutdown|Sleep|Sort|SoundBeep|SoundGet|SoundGetWaveVolume|SoundPlay|SoundSet|SoundSetWaveVolume|SplashImage|SplashTextOff|SplashTextOn|SplitPath|StatusBarGetText|StatusBarWait|StringCaseSense|StringGetPos|StringLeft|StringLen|StringLower|StringMid|StringReplace|StringRight|StringSplit|StringTrimLeft|StringTrimRight|StringUpper|Suspend|SysGet|Thread|ToolTip|Transform|TrayTip|URLDownloadToFile|WinActivate|WinActivateBottom|WinClose|WinGet|WinGetActiveStats|WinGetActiveTitle|WinGetClass|WinGetPos|WinGetText|WinGetTitle|WinHide|WinKill|WinMaximize|WinMenuSelectItem|WinMinimize|WinMinimizeAll|WinMinimizeAllUndo|WinMove|WinRestore|WinSet|WinSetTitle|WinShow|WinWait|WinWaitActive|WinWaitClose|WinWaitNotActive)\b/i, - constant: /\b(?:a_ahkpath|a_ahkversion|a_appdata|a_appdatacommon|a_autotrim|a_batchlines|a_caretx|a_carety|a_computername|a_controldelay|a_cursor|a_dd|a_ddd|a_dddd|a_defaultmousespeed|a_desktop|a_desktopcommon|a_detecthiddentext|a_detecthiddenwindows|a_endchar|a_eventinfo|a_exitreason|a_formatfloat|a_formatinteger|a_gui|a_guievent|a_guicontrol|a_guicontrolevent|a_guiheight|a_guiwidth|a_guix|a_guiy|a_hour|a_iconfile|a_iconhidden|a_iconnumber|a_icontip|a_index|a_ipaddress1|a_ipaddress2|a_ipaddress3|a_ipaddress4|a_isadmin|a_iscompiled|a_iscritical|a_ispaused|a_issuspended|a_isunicode|a_keydelay|a_language|a_lasterror|a_linefile|a_linenumber|a_loopfield|a_loopfileattrib|a_loopfiledir|a_loopfileext|a_loopfilefullpath|a_loopfilelongpath|a_loopfilename|a_loopfileshortname|a_loopfileshortpath|a_loopfilesize|a_loopfilesizekb|a_loopfilesizemb|a_loopfiletimeaccessed|a_loopfiletimecreated|a_loopfiletimemodified|a_loopreadline|a_loopregkey|a_loopregname|a_loopregsubkey|a_loopregtimemodified|a_loopregtype|a_mday|a_min|a_mm|a_mmm|a_mmmm|a_mon|a_mousedelay|a_msec|a_mydocuments|a_now|a_nowutc|a_numbatchlines|a_ostype|a_osversion|a_priorhotkey|programfiles|a_programfiles|a_programs|a_programscommon|a_screenheight|a_screenwidth|a_scriptdir|a_scriptfullpath|a_scriptname|a_sec|a_space|a_startmenu|a_startmenucommon|a_startup|a_startupcommon|a_stringcasesense|a_tab|a_temp|a_thisfunc|a_thishotkey|a_thislabel|a_thismenu|a_thismenuitem|a_thismenuitempos|a_tickcount|a_timeidle|a_timeidlephysical|a_timesincepriorhotkey|a_timesincethishotkey|a_titlematchmode|a_titlematchmodespeed|a_username|a_wday|a_windelay|a_windir|a_workingdir|a_yday|a_year|a_yweek|a_yyyy|clipboard|clipboardall|comspec|errorlevel)\b/i, - builtin: /\b(?:abs|acos|asc|asin|atan|ceil|chr|class|cos|dllcall|exp|fileexist|Fileopen|floor|il_add|il_create|il_destroy|instr|substr|isfunc|islabel|IsObject|ln|log|lv_add|lv_delete|lv_deletecol|lv_getcount|lv_getnext|lv_gettext|lv_insert|lv_insertcol|lv_modify|lv_modifycol|lv_setimagelist|mod|onmessage|numget|numput|registercallback|regexmatch|regexreplace|round|sin|tan|sqrt|strlen|sb_seticon|sb_setparts|sb_settext|strsplit|tv_add|tv_delete|tv_getchild|tv_getcount|tv_getnext|tv_get|tv_getparent|tv_getprev|tv_getselection|tv_gettext|tv_modify|varsetcapacity|winactive|winexist|__New|__Call|__Get|__Set)\b/i, + selector: /\b(?:AutoTrim|BlockInput|Break|Click|ClipWait|Continue|Control|ControlClick|ControlFocus|ControlGet|ControlGetFocus|ControlGetPos|ControlGetText|ControlMove|ControlSend|ControlSendRaw|ControlSetText|CoordMode|Critical|DetectHiddenText|DetectHiddenWindows|Drive|DriveGet|DriveSpaceFree|EnvAdd|EnvDiv|EnvGet|EnvMult|EnvSet|EnvSub|EnvUpdate|Exit|ExitApp|FileAppend|FileCopy|FileCopyDir|FileCreateDir|FileCreateShortcut|FileDelete|FileEncoding|FileGetAttrib|FileGetShortcut|FileGetSize|FileGetTime|FileGetVersion|FileInstall|FileMove|FileMoveDir|FileRead|FileReadLine|FileRecycle|FileRecycleEmpty|FileRemoveDir|FileSelectFile|FileSelectFolder|FileSetAttrib|FileSetTime|FormatTime|GetKeyState|Gosub|Goto|GroupActivate|GroupAdd|GroupClose|GroupDeactivate|Gui|GuiControl|GuiControlGet|Hotkey|ImageSearch|IniDelete|IniRead|IniWrite|Input|InputBox|KeyWait|ListHotkeys|ListLines|ListVars|Loop|Menu|MouseClick|MouseClickDrag|MouseGetPos|MouseMove|MsgBox|OnExit|OutputDebug|Pause|PixelGetColor|PixelSearch|PostMessage|Process|Progress|Random|RegDelete|RegRead|RegWrite|Reload|Repeat|Return|Run|RunAs|RunWait|Send|SendEvent|SendInput|SendMessage|SendMode|SendPlay|SendRaw|SetBatchLines|SetCapslockState|SetControlDelay|SetDefaultMouseSpeed|SetEnv|SetFormat|SetKeyDelay|SetMouseDelay|SetNumlockState|SetRegView|SetScrollLockState|SetStoreCapslockMode|SetTimer|SetTitleMatchMode|SetWinDelay|SetWorkingDir|Shutdown|Sleep|Sort|SoundBeep|SoundGet|SoundGetWaveVolume|SoundPlay|SoundSet|SoundSetWaveVolume|SplashImage|SplashTextOff|SplashTextOn|SplitPath|StatusBarGetText|StatusBarWait|StringCaseSense|StringGetPos|StringLeft|StringLen|StringLower|StringMid|StringReplace|StringRight|StringSplit|StringTrimLeft|StringTrimRight|StringUpper|Suspend|SysGet|Thread|ToolTip|Transform|TrayTip|URLDownloadToFile|WinActivate|WinActivateBottom|WinClose|WinGet|WinGetActiveStats|WinGetActiveTitle|WinGetClass|WinGetPos|WinGetText|WinGetTitle|WinHide|WinKill|WinMaximize|WinMenuSelectItem|WinMinimize|WinMinimizeAll|WinMinimizeAllUndo|WinMove|WinRestore|WinSet|WinSetTitle|WinShow|WinWait|WinWaitActive|WinWaitClose|WinWaitNotActive)\b/i, + constant: /\b(?:a_ahkpath|a_ahkversion|a_appdata|a_appdatacommon|a_autotrim|a_batchlines|a_caretx|a_carety|a_computername|a_controldelay|a_cursor|a_dd|a_ddd|a_dddd|a_defaultmousespeed|a_desktop|a_desktopcommon|a_detecthiddentext|a_detecthiddenwindows|a_endchar|a_eventinfo|a_exitreason|a_fileencoding|a_formatfloat|a_formatinteger|a_gui|a_guievent|a_guicontrol|a_guicontrolevent|a_guiheight|a_guiwidth|a_guix|a_guiy|a_hour|a_iconfile|a_iconhidden|a_iconnumber|a_icontip|a_index|a_ipaddress1|a_ipaddress2|a_ipaddress3|a_ipaddress4|a_is64bitos|a_isadmin|a_iscompiled|a_iscritical|a_ispaused|a_issuspended|a_isunicode|a_keydelay|a_language|a_lasterror|a_linefile|a_linenumber|a_loopfield|a_loopfileattrib|a_loopfiledir|a_loopfileext|a_loopfilefullpath|a_loopfilelongpath|a_loopfilename|a_loopfileshortname|a_loopfileshortpath|a_loopfilesize|a_loopfilesizekb|a_loopfilesizemb|a_loopfiletimeaccessed|a_loopfiletimecreated|a_loopfiletimemodified|a_loopreadline|a_loopregkey|a_loopregname|a_loopregsubkey|a_loopregtimemodified|a_loopregtype|a_mday|a_min|a_mm|a_mmm|a_mmmm|a_mon|a_mousedelay|a_msec|a_mydocuments|a_now|a_nowutc|a_numbatchlines|a_ostype|a_osversion|a_priorhotkey|a_priorkey|programfiles|a_programfiles|a_programs|a_programscommon|a_ptrsize|a_regview|a_screendpi|a_screenheight|a_screenwidth|a_scriptdir|a_scriptfullpath|a_scripthwnd|a_scriptname|a_sec|a_space|a_startmenu|a_startmenucommon|a_startup|a_startupcommon|a_stringcasesense|a_tab|a_temp|a_thisfunc|a_thishotkey|a_thislabel|a_thismenu|a_thismenuitem|a_thismenuitempos|a_tickcount|a_timeidle|a_timeidlephysical|a_timesincepriorhotkey|a_timesincethishotkey|a_titlematchmode|a_titlematchmodespeed|a_username|a_wday|a_windelay|a_windir|a_workingdir|a_yday|a_year|a_yweek|a_yyyy|clipboard|clipboardall|comspec|errorlevel)\b/i, + builtin: /\b(?:abs|acos|asc|asin|atan|ceil|chr|class|comobjactive|comobjarray|comobjconnect|comobjcreate|comobjerror|comobjflags|comobjget|comobjquery|comobjtype|comobjvalue|cos|dllcall|exp|fileexist|Fileopen|floor|format|il_add|il_create|il_destroy|instr|substr|isfunc|islabel|IsObject|ln|log|lv_add|lv_delete|lv_deletecol|lv_getcount|lv_getnext|lv_gettext|lv_insert|lv_insertcol|lv_modify|lv_modifycol|lv_setimagelist|ltrim|rtrim|mod|onmessage|numget|numput|registercallback|regexmatch|regexreplace|round|sin|tan|sqrt|strlen|strreplace|sb_seticon|sb_setparts|sb_settext|strsplit|tv_add|tv_delete|tv_getchild|tv_getcount|tv_getnext|tv_get|tv_getparent|tv_getprev|tv_getselection|tv_gettext|tv_modify|varsetcapacity|winactive|winexist|__New|__Call|__Get|__Set)\b/i, symbol: /\b(?:alt|altdown|altup|appskey|backspace|browser_back|browser_favorites|browser_forward|browser_home|browser_refresh|browser_search|browser_stop|bs|capslock|ctrl|ctrlbreak|ctrldown|ctrlup|del|delete|down|end|enter|esc|escape|f1|f10|f11|f12|f13|f14|f15|f16|f17|f18|f19|f2|f20|f21|f22|f23|f24|f3|f4|f5|f6|f7|f8|f9|home|ins|insert|joy1|joy10|joy11|joy12|joy13|joy14|joy15|joy16|joy17|joy18|joy19|joy2|joy20|joy21|joy22|joy23|joy24|joy25|joy26|joy27|joy28|joy29|joy3|joy30|joy31|joy32|joy4|joy5|joy6|joy7|joy8|joy9|joyaxes|joybuttons|joyinfo|joyname|joypov|joyr|joyu|joyv|joyx|joyy|joyz|lalt|launch_app1|launch_app2|launch_mail|launch_media|lbutton|lcontrol|lctrl|left|lshift|lwin|lwindown|lwinup|mbutton|media_next|media_play_pause|media_prev|media_stop|numlock|numpad0|numpad1|numpad2|numpad3|numpad4|numpad5|numpad6|numpad7|numpad8|numpad9|numpadadd|numpadclear|numpaddel|numpaddiv|numpaddot|numpaddown|numpadend|numpadenter|numpadhome|numpadins|numpadleft|numpadmult|numpadpgdn|numpadpgup|numpadright|numpadsub|numpadup|pgdn|pgup|printscreen|ralt|rbutton|rcontrol|rctrl|right|rshift|rwin|rwindown|rwinup|scrolllock|shift|shiftdown|shiftup|space|tab|up|volume_down|volume_mute|volume_up|wheeldown|wheelleft|wheelright|wheelup|xbutton1|xbutton2)\b/i, - important: /#\b(?:AllowSameLineComments|ClipboardTimeout|CommentFlag|ErrorStdOut|EscapeChar|HotkeyInterval|HotkeyModifierTimeout|Hotstring|IfWinActive|IfWinExist|IfWinNotActive|IfWinNotExist|Include|IncludeAgain|InstallKeybdHook|InstallMouseHook|KeyHistory|LTrim|MaxHotkeysPerInterval|MaxMem|MaxThreads|MaxThreadsBuffer|MaxThreadsPerHotkey|NoEnv|NoTrayIcon|Persistent|SingleInstance|UseHook|WinActivateForce)\b/i, - keyword: /\b(?:Abort|AboveNormal|Add|ahk_class|ahk_group|ahk_id|ahk_pid|All|Alnum|Alpha|AltSubmit|AltTab|AltTabAndMenu|AltTabMenu|AltTabMenuDismiss|AlwaysOnTop|AutoSize|Background|BackgroundTrans|BelowNormal|between|BitAnd|BitNot|BitOr|BitShiftLeft|BitShiftRight|BitXOr|Bold|Border|Button|ByRef|Checkbox|Checked|CheckedGray|Choose|ChooseString|Close|Color|ComboBox|Contains|ControlList|Count|Date|DateTime|Days|DDL|Default|DeleteAll|Delimiter|Deref|Destroy|Digit|Disable|Disabled|DropDownList|Edit|Eject|Else|Enable|Enabled|Error|Exist|Expand|ExStyle|FileSystem|First|Flash|Float|FloatFast|Focus|Font|for|global|Grid|Group|GroupBox|GuiClose|GuiContextMenu|GuiDropFiles|GuiEscape|GuiSize|Hdr|Hidden|Hide|High|HKCC|HKCR|HKCU|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG|HKEY_CURRENT_USER|HKEY_LOCAL_MACHINE|HKEY_USERS|HKLM|HKU|Hours|HScroll|Icon|IconSmall|ID|IDLast|If|IfEqual|IfExist|IfGreater|IfGreaterOrEqual|IfInString|IfLess|IfLessOrEqual|IfMsgBox|IfNotEqual|IfNotExist|IfNotInString|IfWinActive|IfWinExist|IfWinNotActive|IfWinNotExist|Ignore|ImageList|in|Integer|IntegerFast|Interrupt|is|italic|Join|Label|LastFound|LastFoundExist|Limit|Lines|List|ListBox|ListView|local|Lock|Logoff|Low|Lower|Lowercase|MainWindow|Margin|Maximize|MaximizeBox|MaxSize|Minimize|MinimizeBox|MinMax|MinSize|Minutes|MonthCal|Mouse|Move|Multi|NA|No|NoActivate|NoDefault|NoHide|NoIcon|NoMainWindow|norm|Normal|NoSort|NoSortHdr|NoStandard|Not|NoTab|NoTimers|Number|Off|Ok|On|OwnDialogs|Owner|Parse|Password|Picture|Pixel|Pos|Pow|Priority|ProcessName|Radio|Range|Read|ReadOnly|Realtime|Redraw|REG_BINARY|REG_DWORD|REG_EXPAND_SZ|REG_MULTI_SZ|REG_SZ|Region|Relative|Rename|Report|Resize|Restore|Retry|RGB|Screen|Seconds|Section|Serial|SetLabel|ShiftAltTab|Show|Single|Slider|SortDesc|Standard|static|Status|StatusBar|StatusCD|strike|Style|Submit|SysMenu|Tab2|TabStop|Text|Theme|Tile|ToggleCheck|ToggleEnable|ToolWindow|Top|Topmost|TransColor|Transparent|Tray|TreeView|TryAgain|Type|UnCheck|underline|Unicode|Unlock|UpDown|Upper|Uppercase|UseErrorLevel|Vis|VisFirst|Visible|VScroll|Wait|WaitClose|WantCtrlA|WantF2|WantReturn|While|Wrap|Xdigit|xm|xp|xs|Yes|ym|yp|ys)\b/i + important: /#\b(?:AllowSameLineComments|ClipboardTimeout|CommentFlag|DerefChar|ErrorStdOut|EscapeChar|HotkeyInterval|HotkeyModifierTimeout|Hotstring|If|IfTimeout|IfWinActive|IfWinExist|IfWinNotActive|IfWinNotExist|Include|IncludeAgain|InputLevel|InstallKeybdHook|InstallMouseHook|KeyHistory|MaxHotkeysPerInterval|MaxMem|MaxThreads|MaxThreadsBuffer|MaxThreadsPerHotkey|MenuMaskKey|NoEnv|NoTrayIcon|Persistent|SingleInstance|UseHook|Warn|WinActivateForce)\b/i, + keyword: /\b(?:Abort|AboveNormal|Add|ahk_class|ahk_exe|ahk_group|ahk_id|ahk_pid|All|Alnum|Alpha|AltSubmit|AltTab|AltTabAndMenu|AltTabMenu|AltTabMenuDismiss|AlwaysOnTop|AutoSize|Background|BackgroundTrans|BelowNormal|between|BitAnd|BitNot|BitOr|BitShiftLeft|BitShiftRight|BitXOr|Bold|Border|Button|ByRef|Checkbox|Checked|CheckedGray|Choose|ChooseString|Close|Color|ComboBox|Contains|ControlList|Count|Date|DateTime|Days|DDL|Default|DeleteAll|Delimiter|Deref|Destroy|Digit|Disable|Disabled|DropDownList|Edit|Eject|Else|Enable|Enabled|Error|Exist|Expand|ExStyle|FileSystem|First|Flash|Float|FloatFast|Focus|Font|for|global|Grid|Group|GroupBox|GuiClose|GuiContextMenu|GuiDropFiles|GuiEscape|GuiSize|Hdr|Hidden|Hide|High|HKCC|HKCR|HKCU|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG|HKEY_CURRENT_USER|HKEY_LOCAL_MACHINE|HKEY_USERS|HKLM|HKU|Hours|HScroll|Icon|IconSmall|ID|IDLast|If|IfEqual|IfExist|IfGreater|IfGreaterOrEqual|IfInString|IfLess|IfLessOrEqual|IfMsgBox|IfNotEqual|IfNotExist|IfNotInString|IfWinActive|IfWinExist|IfWinNotActive|IfWinNotExist|Ignore|ImageList|in|Integer|IntegerFast|Interrupt|is|italic|Join|Label|LastFound|LastFoundExist|Limit|Lines|List|ListBox|ListView|local|Lock|Logoff|Low|Lower|Lowercase|MainWindow|Margin|Maximize|MaximizeBox|MaxSize|Minimize|MinimizeBox|MinMax|MinSize|Minutes|MonthCal|Mouse|Move|Multi|NA|No|NoActivate|NoDefault|NoHide|NoIcon|NoMainWindow|norm|Normal|NoSort|NoSortHdr|NoStandard|Not|NoTab|NoTimers|Number|Off|Ok|On|OwnDialogs|Owner|Parse|Password|Picture|Pixel|Pos|Pow|Priority|ProcessName|Radio|Range|Read|ReadOnly|Realtime|Redraw|REG_BINARY|REG_DWORD|REG_EXPAND_SZ|REG_MULTI_SZ|REG_SZ|Region|Relative|Rename|Report|Resize|Restore|Retry|RGB|Screen|Seconds|Section|Serial|SetLabel|ShiftAltTab|Show|Single|Slider|SortDesc|Standard|static|Status|StatusBar|StatusCD|strike|Style|Submit|SysMenu|Tab2|TabStop|Text|Theme|Tile|ToggleCheck|ToggleEnable|ToolWindow|Top|Topmost|TransColor|Transparent|Tray|TreeView|TryAgain|Throw|Try|Catch|Finally|Type|UnCheck|underline|Unicode|Unlock|Until|UpDown|Upper|Uppercase|UseErrorLevel|Vis|VisFirst|Visible|VScroll|Wait|WaitClose|WantCtrlA|WantF2|WantReturn|While|Wrap|Xdigit|xm|xp|xs|Yes|ym|yp|ys)\b/i, + function: /[^(); \t,\n+*\-=?>:\\\/<&%\[\]]+?(?=\()/m, + punctuation: /[{}[\]():,]/ } } diff --git a/lang/bash.js b/lang/bash.js index 2850c27..a87c150 100644 --- a/lang/bash.js +++ b/lang/bash.js @@ -135,7 +135,7 @@ function bash(Prism) { }, variable: insideString.variable, function: { - pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/, + pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/, lookbehind: true }, keyword: { diff --git a/lang/batch.js b/lang/batch.js index a2fd14c..c64c049 100644 --- a/lang/batch.js +++ b/lang/batch.js @@ -13,7 +13,7 @@ function batch(Prism) { punctuation: /:/ } } - var string = /"[^"]*"/ + var string = /"(?:[\\"]"|[^"])*"(?!")/ var number = /(?:\b|-)\d+\b/ Prism.languages.batch = { comment: [ @@ -78,7 +78,7 @@ function batch(Prism) { }, { // Other commands - pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, + pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:"(?:[\\"]"|[^"])*"(?!")|[^"^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, lookbehind: true, inside: { keyword: /^\w+\b/i, diff --git a/lang/c.js b/lang/c.js index 8043653..21e7caa 100644 --- a/lang/c.js +++ b/lang/c.js @@ -22,20 +22,31 @@ function c(Prism) { macro: { // allow for multiline macro definitions // spaces after the # character compile fine with gcc - pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im, + pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, lookbehind: true, + greedy: true, alias: 'property', inside: { - // highlight the path of the include statement as a string - string: { - pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/, - lookbehind: true - }, + string: [ + { + // highlight the path of the include statement as a string + pattern: /^(#\s*include\s*)<[^>]+>/, + lookbehind: true + }, + Prism.languages.c['string'] + ], + comment: Prism.languages.c['comment'], // highlight macro directives as keywords directive: { - pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/, + pattern: /^(#\s*)[a-z]+/, lookbehind: true, alias: 'keyword' + }, + 'directive-hash': /^#/, + punctuation: /##|\\(?=[\r\n])/, + expression: { + pattern: /\S[\s\S]*/, + inside: Prism.languages.c } } }, diff --git a/lang/cpp.js b/lang/cpp.js index a7e6904..7cc68a0 100644 --- a/lang/cpp.js +++ b/lang/cpp.js @@ -5,24 +5,63 @@ cpp.displayName = 'cpp' cpp.aliases = [] function cpp(Prism) { Prism.register(refractorC) - Prism.languages.cpp = Prism.languages.extend('c', { - 'class-name': { - pattern: /(\b(?:class|enum|struct)\s+)\w+/, - lookbehind: true - }, - keyword: /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/, - number: { - pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i, - greedy: true - }, - operator: />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/, - boolean: /\b(?:true|false)\b/ - }) - Prism.languages.insertBefore('cpp', 'string', { - 'raw-string': { - pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/, - alias: 'string', - greedy: true - } - }) + ;(function (Prism) { + var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/ + Prism.languages.cpp = Prism.languages.extend('c', { + 'class-name': [ + { + pattern: RegExp( + /(\b(?:class|concept|enum|struct|typename)\s+)(?!)\w+/.source.replace( + //g, + function () { + return keyword.source + } + ) + ), + lookbehind: true + }, // This is intended to capture the class name of method implementations like: + // void foo::bar() const {} + // However! The `foo` in the above example could also be a namespace, so we only capture the class name if + // it starts with an uppercase letter. This approximation should give decent results. + /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/, // This will capture the class name before destructors like: + // Foo::~Foo() {} + /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i, // This also intends to capture the class name of method implementations but here the class has template + // parameters, so it can't be a namespace (until C++ adds generic namespaces). + /\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/ + ], + keyword: keyword, + number: { + pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i, + greedy: true + }, + operator: />>=?|<<=?|->|([-+&|:])\1|[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/, + boolean: /\b(?:true|false)\b/ + }) + Prism.languages.insertBefore('cpp', 'string', { + 'raw-string': { + pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/, + alias: 'string', + greedy: true + } + }) + Prism.languages.insertBefore('cpp', 'class-name', { + // the base clause is an optional list of parent classes + // https://en.cppreference.com/w/cpp/language/class + 'base-clause': { + pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)(?:[^;{}"'])+?(?=\s*[;{])/, + lookbehind: true, + greedy: true, + inside: Prism.languages.extend('cpp', {}) + } + }) + Prism.languages.insertBefore( + 'inside', + 'operator', + { + // All untokenized words that are not namespaces should be class names + 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i + }, + Prism.languages.cpp['base-clause'] + ) + })(Prism) } diff --git a/lang/csharp.js b/lang/csharp.js index 56f039f..a3f1268 100644 --- a/lang/csharp.js +++ b/lang/csharp.js @@ -53,7 +53,7 @@ function csharp(Prism) { // contextual keywords // ("var" and "dynamic" are missing because they are used like types) contextual: - 'add alias ascending async await by descending from get global group into join let nameof notnull on orderby partial remove select set unmanaged value when where where', + 'add alias and ascending async await by descending from get global group into join let nameof not notnull on or orderby partial remove select set unmanaged value when where where', // all other keywords other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield' @@ -98,6 +98,10 @@ function csharp(Prism) { genericName ]) var array = /\[\s*(?:,\s*)*\]/.source + var typeExpressionWithoutTuple = replace( + /<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, + [identifier, array] + ) var tupleElement = replace( /[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array] @@ -189,7 +193,9 @@ function csharp(Prism) { // Casts and checks via as and is. // as Foo, is Bar // (things like if(a is Foo b) is covered by variable declaration) - pattern: re(/(\b(?:is|as)\s+)<<0>>/.source, [typeExpression]), + pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [ + typeExpressionWithoutTuple + ]), lookbehind: true, inside: typeInside }, @@ -197,7 +203,8 @@ function csharp(Prism) { // Variable, field and parameter declaration // (Foo bar, Bar baz, Foo[,,] bay, Foo> bax) pattern: re( - /\b<<0>>(?=\s+(?!<<1>>)<<2>>(?:\s*[=,;:{)\]]|\s+in))/.source, + /\b<<0>>(?=\s+(?!<<1>>)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/ + .source, [typeExpression, nonContextualKeywords, name] ), inside: typeInside @@ -324,7 +331,7 @@ alias: 'class-name' }) // attributes var regularStringOrCharacter = regularString + '|' + character var regularStringCharacterOrComment = replace( - /\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*[\s\S]*?\*\/|<<0>>/.source, + /\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter] ) var roundExpression = nested( @@ -381,9 +388,11 @@ alias: 'class-name' formatString ]) // single line var sInterpolationRound = nested( - replace(/[^"'/()]|\/(?!\*)|\/\*.*?\*\/|<<0>>|\(<>*\)/.source, [ - regularStringOrCharacter - ]), + replace( + /[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<>*\)/ + .source, + [regularStringOrCharacter] + ), 2 ) var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [ @@ -393,7 +402,7 @@ alias: 'class-name' function createInterpolationInside(interpolation, interpolationRound) { return { interpolation: { - pattern: re(/([^{](?:\{\{)*)<<0>>/.source, [interpolation]), + pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]), lookbehind: true, inside: { 'format-string': { diff --git a/lang/csp.js b/lang/csp.js index 68d8aa4..813e3e8 100644 --- a/lang/csp.js +++ b/lang/csp.js @@ -16,7 +16,7 @@ function csp(Prism) { */ Prism.languages.csp = { directive: { - pattern: /\b(?:(?:base-uri|form-action|frame-ancestors|plugin-types|referrer|reflected-xss|report-to|report-uri|require-sri-for|sandbox) |(?:block-all-mixed-content|disown-opener|upgrade-insecure-requests)(?: |;)|(?:child|connect|default|font|frame|img|manifest|media|object|script|style|worker)-src )/i, + pattern: /\b(?:base-uri|block-all-mixed-content|(?:child|connect|default|font|frame|img|manifest|media|object|script|style|worker)-src|disown-opener|form-action|frame-ancestors|plugin-types|referrer|reflected-xss|report-to|report-uri|require-sri-for|sandbox|upgrade-insecure-requests)\b/i, alias: 'keyword' }, safe: { diff --git a/lang/css-extras.js b/lang/css-extras.js index f8a551c..4ca9974 100644 --- a/lang/css-extras.js +++ b/lang/css-extras.js @@ -12,8 +12,8 @@ function cssExtras(Prism) { inside: (selectorInside = { 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/, 'pseudo-class': /:[-\w]+/, - class: /\.[-:.\w]+/, - id: /#[-:.\w]+/, + class: /\.[-\w]+/, + id: /#[-\w]+/, attribute: { pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'), greedy: true, @@ -31,11 +31,11 @@ function cssExtras(Prism) { punctuation: /\|$/ } }, - attribute: { + 'attr-name': { pattern: /^(\s*)[-\w\xA0-\uFFFF]+/, lookbehind: true }, - value: [ + 'attr-value': [ string, { pattern: /(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/, @@ -59,7 +59,11 @@ function cssExtras(Prism) { lookbehind: true } ], - punctuation: /[()]/ + combinator: />|\+|~|\|\|/, + // the `tag` token has been existed and removed. + // because we can't find a perfect tokenize to match it. + // if you want to add it, please read https://github.com/PrismJS/prism/pull/2373 first. + punctuation: /[(),]/ }) } Prism.languages.css['atrule'].inside[ @@ -72,7 +76,7 @@ function cssExtras(Prism) { } }) var unit = { - pattern: /(\d)(?:%|[a-z]+)/, + pattern: /(\b\d+)(?:%|[a-z]+\b)/, lookbehind: true } // 123 -123 .123 -.123 12.3 -12.3 var number = { @@ -102,6 +106,7 @@ function cssExtras(Prism) { } } ], + // it's important that there is no boundary assertion after the hex digits entity: /\\[\da-f]{1,8}/i, unit: unit, number: number diff --git a/lang/css.js b/lang/css.js index 0bded64..cdfdb76 100644 --- a/lang/css.js +++ b/lang/css.js @@ -16,15 +16,31 @@ function css(Prism) { pattern: /(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/, lookbehind: true, alias: 'selector' + }, + keyword: { + pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/, + lookbehind: true } // See rest below } }, url: { - pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'), + // https://drafts.csswg.org/css-values-3/#urls + pattern: RegExp( + '\\burl\\((?:' + + string.source + + '|' + + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + + ')\\)', + 'i' + ), greedy: true, inside: { function: /^url/i, - punctuation: /^\(|\)$/ + punctuation: /^\(|\)$/, + string: { + pattern: RegExp('^' + string.source + '$'), + alias: 'url' + } } }, selector: RegExp( diff --git a/lang/cypher.js b/lang/cypher.js new file mode 100644 index 0000000..eb3ed44 --- /dev/null +++ b/lang/cypher.js @@ -0,0 +1,40 @@ +'use strict' + +module.exports = cypher +cypher.displayName = 'cypher' +cypher.aliases = [] +function cypher(Prism) { + Prism.languages.cypher = { + // https://neo4j.com/docs/cypher-manual/current/syntax/comments/ + comment: /\/\/.*/, + string: { + pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/, + greedy: true + }, + 'class-name': { + pattern: /(:\s*)(?:\w+|`(?:[^`\\\r\n])*`)(?=\s*[{):])/, + lookbehind: true, + greedy: true + }, + relationship: { + pattern: /(-\[\s*(?:\w+\s*|`(?:[^`\\\r\n])*`\s*)?:\s*|\|\s*:\s*)(?:\w+|`(?:[^`\\\r\n])*`)/, + lookbehind: true, + greedy: true, + alias: 'property' + }, + identifier: { + pattern: /`(?:[^`\\\r\n])*`/, + greedy: true, + alias: 'symbol' + }, + variable: /\$\w+/, + // https://neo4j.com/docs/cypher-manual/current/syntax/reserved/ + keyword: /\b(?:ADD|ALL|AND|AS|ASC|ASCENDING|ASSERT|BY|CALL|CASE|COMMIT|CONSTRAINT|CONTAINS|CREATE|CSV|DELETE|DESC|DESCENDING|DETACH|DISTINCT|DO|DROP|ELSE|END|ENDS|EXISTS|FOR|FOREACH|IN|INDEX|IS|JOIN|KEY|LIMIT|LOAD|MANDATORY|MATCH|MERGE|NODE|NOT|OF|ON|OPTIONAL|OR|ORDER(?=\s+BY)|PERIODIC|REMOVE|REQUIRE|RETURN|SCALAR|SCAN|SET|SKIP|START|STARTS|THEN|UNION|UNIQUE|UNWIND|USING|WHEN|WHERE|WITH|XOR|YIELD)\b/i, + function: /\b\w+\b(?=\s*\()/, + boolean: /\b(?:true|false|null)\b/i, + number: /\b(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/, + // https://neo4j.com/docs/cypher-manual/current/syntax/operators/ + operator: /:|<--?|--?>?|<>|=~?|[<>]=?|[+*/%^|]|\.\.\.?/, + punctuation: /[()[\]{},;.]/ + } +} diff --git a/lang/d.js b/lang/d.js index e5a5c77..ecc1a10 100644 --- a/lang/d.js +++ b/lang/d.js @@ -18,7 +18,7 @@ function d(Prism) { [ // /+ comment +/ // Allow one level of nesting - /\/\+(?:\/\+[\s\S]*?\+\/|(?!\/\+)[\s\S])*?\+\//.source, // // comment + /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source, // // comment /\/\/.*/.source, // /* comment */ /\/\*[\s\S]*?\*\//.source ].join('|') + diff --git a/lang/dart.js b/lang/dart.js index 374cad5..a1eb7b6 100644 --- a/lang/dart.js +++ b/lang/dart.js @@ -17,7 +17,7 @@ function dart(Prism) { ], keyword: [ /\b(?:async|sync|yield)\*/, - /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|default|deferred|do|dynamic|else|enum|export|external|extends|factory|final|finally|for|get|if|implements|import|in|library|new|null|operator|part|rethrow|return|set|static|super|switch|this|throw|try|typedef|var|void|while|with|yield)\b/ + /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extension|external|extends|factory|final|finally|for|Function|get|hide|if|implements|interface|import|in|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/ ], operator: /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/ }) diff --git a/lang/dhall.js b/lang/dhall.js new file mode 100644 index 0000000..af76da7 --- /dev/null +++ b/lang/dhall.js @@ -0,0 +1,72 @@ +'use strict' + +module.exports = dhall +dhall.displayName = 'dhall' +dhall.aliases = [] +function dhall(Prism) { + // ABNF grammar: + // https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf + Prism.languages.dhall = { + // Multi-line comments can be nested. E.g. {- foo {- bar -} -} + // The multi-line pattern is essentially this: + // \{-(?:[^-{]|-(?!\})|\{(?!-)|)*-\} + comment: /--.*|\{-(?:[^-{]|-(?!\})|\{(?!-)|\{-(?:[^-{]|-(?!\})|\{(?!-))*-\})*-\}/, + string: { + pattern: /"(?:[^"\\]|\\.)*"|''(?:[^']|'(?!')|'''|''\$\{)*''(?!'|\$)/, + greedy: true, + inside: { + interpolation: { + pattern: /\$\{[^{}]*\}/, + inside: { + expression: { + pattern: /(^\$\{)[\s\S]+(?=\}$)/, + lookbehind: true, + alias: 'language-dhall', + inside: null // see blow + }, + punctuation: /\$\{|\}/ + } + } + } + }, + label: { + pattern: /`[^`]*`/, + greedy: true + }, + url: { + // https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L596 + pattern: /\bhttps?:\/\/[\w.:%!$&'*+;=@~-]+(?:\/[\w.:%!$&'*+;=@~-]*)*(?:\?[/?\w.:%!$&'*+;=@~-]*)?/, + greedy: true + }, + env: { + // https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L661 + pattern: /\benv:(?:(?!\d)\w+|"(?:[^"\\=]|\\.)*")/, + greedy: true, + inside: { + function: /^env/, + operator: /^:/, + variable: /[\s\S]+/ + } + }, + hash: { + // https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L725 + pattern: /\bsha256:[\da-fA-F]{64}\b/, + inside: { + function: /sha256/, + operator: /:/, + number: /[\da-fA-F]{64}/ + } + }, + // https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L359 + keyword: /\b(?:as|assert|else|forall|if|in|let|merge|missing|then|toMap|using|with)\b|\u2200/, + builtin: /\b(?:Some|None)\b/, + boolean: /\b(?:False|True)\b/, + number: /\bNaN\b|-?\bInfinity\b|[+-]?\b(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/, + operator: /\/\\|\/\/\\\\|&&|\|\||[!=]=|===|\/\/|->|\+\+|::|[+*#@=:?<>|\\\u2227\u2a53\u2261\u2afd\u03bb\u2192]/, + punctuation: /\.\.|[{}\[\](),./]/, + // we'll just assume that every capital word left is a type name + 'class-name': /\b[A-Z]\w*\b/ + } + Prism.languages.dhall.string.inside.interpolation.inside.expression.inside = + Prism.languages.dhall +} diff --git a/lang/diff.js b/lang/diff.js index 3ca6bbb..28f1500 100644 --- a/lang/diff.js +++ b/lang/diff.js @@ -37,12 +37,21 @@ function diff(Prism) { alias.push('bold') } Prism.languages.diff[name] = { - // pattern: /^(?:[_].*(?:\r\n?|\n|(?![\s\S])))+/m pattern: RegExp( '^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm' ), - alias: alias + alias: alias, + inside: { + line: { + pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/, + lookbehind: true + }, + prefix: { + pattern: /[\s\S]/, + alias: /\w+/.exec(name)[0] + } + } } }) // make prefixes available to Diff plugin Object.defineProperty(Prism.languages.diff, 'PREFIXES', { diff --git a/lang/docker.js b/lang/docker.js index a369249..8f2f7aa 100644 --- a/lang/docker.js +++ b/lang/docker.js @@ -10,7 +10,10 @@ function docker(Prism) { lookbehind: true }, string: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/, - comment: /#.*/, + comment: { + pattern: /#.*/, + greedy: true + }, punctuation: /---|\.\.\.|[:[\]{}\-,|>?]/ } Prism.languages.dockerfile = Prism.languages.docker diff --git a/lang/ebnf.js b/lang/ebnf.js index 3e3412d..7f5fd64 100644 --- a/lang/ebnf.js +++ b/lang/ebnf.js @@ -20,7 +20,7 @@ function ebnf(Prism) { lookbehind: true, alias: ['rule', 'keyword'] }, - rule: /[a-z]\w*(?:[ \t]+[a-z]\w*)*/i, + rule: /\b[a-z]\w*(?:[ \t]+[a-z]\w*)*\b/i, punctuation: /\([:/]|[:/]\)|[.,;()[\]{}]/, operator: /[-=|*/!]/ } diff --git a/lang/editorconfig.js b/lang/editorconfig.js new file mode 100644 index 0000000..70cec6a --- /dev/null +++ b/lang/editorconfig.js @@ -0,0 +1,33 @@ +'use strict' + +module.exports = editorconfig +editorconfig.displayName = 'editorconfig' +editorconfig.aliases = [] +function editorconfig(Prism) { + Prism.languages.editorconfig = { + // https://editorconfig-specification.readthedocs.io/en/latest/ + comment: /[;#].*/, + section: { + pattern: /(^[ \t]*)\[.+]/m, + lookbehind: true, + alias: 'keyword', + inside: { + regex: /\\\\[\[\]{},!?.*]/, + // Escape special characters with '\\' + operator: /[!?]|\.\.|\*{1,2}/, + punctuation: /[\[\]{},]/ + } + }, + property: { + pattern: /(^[ \t]*)[^\s=]+(?=[ \t]*=)/m, + lookbehind: true + }, + value: { + pattern: /=.*/, + alias: 'string', + inside: { + punctuation: /^=/ + } + } + } +} diff --git a/lang/eiffel.js b/lang/eiffel.js index 70d89fe..6c5a5d6 100644 --- a/lang/eiffel.js +++ b/lang/eiffel.js @@ -17,7 +17,7 @@ function eiffel(Prism) { greedy: true }, // Single-line string { - pattern: /"(?:%\s+%|%.|[^%"\r\n])*"/, + pattern: /"(?:%\s*\n\s*%|%.|[^%"\r\n])*"/, greedy: true } ], @@ -33,7 +33,7 @@ function eiffel(Prism) { number: [ // hexa | octal | bin /\b0[xcb][\da-f](?:_*[\da-f])*\b/i, // Decimal - /(?:\d(?:_*\d)*)?\.(?:(?:\d(?:_*\d)*)?e[+-]?)?\d(?:_*\d)*|\d(?:_*\d)*\.?/i + /(?:\b\d(?:_*\d)*)?\.(?:(?:\d(?:_*\d)*)?e[+-]?)?\d(?:_*\d)*\b|\b\d(?:_*\d)*\b\.?/i ], punctuation: /:=|<<|>>|\(\||\|\)|->|\.(?=\w)|[{}[\];(),:?]/, operator: /\\\\|\|\.\.\||\.\.|\/[~\/=]?|[><]=?|[-+*^=~]/ diff --git a/lang/ejs.js b/lang/ejs.js index 25cfec6..4ed51dc 100644 --- a/lang/ejs.js +++ b/lang/ejs.js @@ -2,7 +2,7 @@ var refractorMarkupTemplating = require('./markup-templating.js') module.exports = ejs ejs.displayName = 'ejs' -ejs.aliases = [] +ejs.aliases = ['eta'] function ejs(Prism) { Prism.register(refractorMarkupTemplating) ;(function (Prism) { @@ -28,5 +28,6 @@ function ejs(Prism) { Prism.hooks.add('after-tokenize', function (env) { Prism.languages['markup-templating'].tokenizePlaceholders(env, 'ejs') }) + Prism.languages.eta = Prism.languages.ejs })(Prism) } diff --git a/lang/elixir.js b/lang/elixir.js index 26ee5d9..c09c21f 100644 --- a/lang/elixir.js +++ b/lang/elixir.js @@ -14,7 +14,7 @@ function elixir(Prism) { string: [ { // ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s - pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/, + pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/, greedy: true, inside: { // See interpolation below diff --git a/lang/erb.js b/lang/erb.js index 5510e01..6b5f7ba 100644 --- a/lang/erb.js +++ b/lang/erb.js @@ -1,12 +1,12 @@ 'use strict' -var refractorMarkupTemplating = require('./markup-templating.js') var refractorRuby = require('./ruby.js') +var refractorMarkupTemplating = require('./markup-templating.js') module.exports = erb erb.displayName = 'erb' erb.aliases = [] function erb(Prism) { - Prism.register(refractorMarkupTemplating) Prism.register(refractorRuby) + Prism.register(refractorMarkupTemplating) ;(function (Prism) { Prism.languages.erb = Prism.languages.extend('ruby', {}) Prism.languages.insertBefore('erb', 'comment', { diff --git a/lang/etlua.js b/lang/etlua.js index 1ff64bd..833b217 100644 --- a/lang/etlua.js +++ b/lang/etlua.js @@ -1,9 +1,11 @@ 'use strict' +var refractorLua = require('./lua.js') var refractorMarkupTemplating = require('./markup-templating.js') module.exports = etlua etlua.displayName = 'etlua' etlua.aliases = [] function etlua(Prism) { + Prism.register(refractorLua) Prism.register(refractorMarkupTemplating) ;(function (Prism) { Prism.languages.etlua = { diff --git a/lang/excel-formula.js b/lang/excel-formula.js index 73036ba..deaac4a 100644 --- a/lang/excel-formula.js +++ b/lang/excel-formula.js @@ -42,11 +42,11 @@ function excelFormula(Prism) { } }, 'function-name': { - pattern: /[A-Z]\w*(?=\()/i, + pattern: /\b[A-Z]\w*(?=\()/i, alias: 'keyword' }, range: { - pattern: /\$?(?:[A-Z]+\$?\d+:\$?[A-Z]+\$?\d+|[A-Z]+:\$?[A-Z]+|\d+:\$?\d+)/i, + pattern: /\$?\b(?:[A-Z]+\$?\d+:\$?[A-Z]+\$?\d+|[A-Z]+:\$?[A-Z]+|\d+:\$?\d+)\b/i, alias: 'property', inside: { operator: /:/, @@ -58,7 +58,7 @@ function excelFormula(Prism) { cell: { // Excel is case insensitive, so the string "foo1" could be either a variable or a cell. // To combat this, we match cells case insensitive, if the contain at least one "$", and case sensitive otherwise. - pattern: /[A-Z]+\d+|\$[A-Za-z]+\$?\d+|[A-Za-z]+\$\d+/, + pattern: /\b[A-Z]+\d+\b|\$[A-Za-z]+\$?\d+\b|\b[A-Za-z]+\$\d+\b/, alias: 'property' }, number: /(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?\b/i, diff --git a/lang/ftl.js b/lang/ftl.js index 72c5cc6..844f4cf 100644 --- a/lang/ftl.js +++ b/lang/ftl.js @@ -8,14 +8,14 @@ function ftl(Prism) { ;(function (Prism) { // https://freemarker.apache.org/docs/dgui_template_exp.html // FTL expression with 4 levels of nesting supported - var FTL_EXPR = /(?!<#--)[^()"']|\((?:)*\)|<#--[\s\S]*?-->|"(?:[^\\"]|\\.)*"|'(?:[^\\']|\\.)*'/ + var FTL_EXPR = /[^<()"']|\((?:)*\)|<(?!#--)|<#--(?:[^-]|-(?!->))*-->|"(?:[^\\"]|\\.)*"|'(?:[^\\']|\\.)*'/ .source for (var i = 0; i < 2; i++) { FTL_EXPR = FTL_EXPR.replace(//g, function () { return FTL_EXPR }) } - FTL_EXPR = FTL_EXPR.replace(//g, '[^sS]') + FTL_EXPR = FTL_EXPR.replace(//g, /[^\s\S]/.source) var ftl = { comment: /<#--[\s\S]*?-->/, string: [ diff --git a/lang/glsl.js b/lang/glsl.js index 5ed0258..3891fac 100644 --- a/lang/glsl.js +++ b/lang/glsl.js @@ -1,19 +1,11 @@ 'use strict' - +var refractorC = require('./c.js') module.exports = glsl glsl.displayName = 'glsl' glsl.aliases = [] function glsl(Prism) { - Prism.languages.glsl = Prism.languages.extend('clike', { - comment: [/\/\*[\s\S]*?\*\//, /\/\/(?:\\(?:\r\n|[\s\S])|[^\\\r\n])*/], - number: /(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ulf]*/i, + Prism.register(refractorC) + Prism.languages.glsl = Prism.languages.extend('c', { keyword: /\b(?:attribute|const|uniform|varying|buffer|shared|coherent|volatile|restrict|readonly|writeonly|atomic_uint|layout|centroid|flat|smooth|noperspective|patch|sample|break|continue|do|for|while|switch|case|default|if|else|subroutine|in|out|inout|float|double|int|void|bool|true|false|invariant|precise|discard|return|d?mat[234](?:x[234])?|[ibdu]?vec[234]|uint|lowp|mediump|highp|precision|[iu]?sampler[123]D|[iu]?samplerCube|sampler[12]DShadow|samplerCubeShadow|[iu]?sampler[12]DArray|sampler[12]DArrayShadow|[iu]?sampler2DRect|sampler2DRectShadow|[iu]?samplerBuffer|[iu]?sampler2DMS(?:Array)?|[iu]?samplerCubeArray|samplerCubeArrayShadow|[iu]?image[123]D|[iu]?image2DRect|[iu]?imageCube|[iu]?imageBuffer|[iu]?image[12]DArray|[iu]?imageCubeArray|[iu]?image2DMS(?:Array)?|struct|common|partition|active|asm|class|union|enum|typedef|template|this|resource|goto|inline|noinline|public|static|extern|external|interface|long|short|half|fixed|unsigned|superp|input|output|hvec[234]|fvec[234]|sampler3DRect|filter|sizeof|cast|namespace|using)\b/ }) - Prism.languages.insertBefore('glsl', 'comment', { - preprocessor: { - pattern: /(^[ \t]*)#(?:(?:define|undef|if|ifdef|ifndef|else|elif|endif|error|pragma|extension|version|line)\b)?/m, - lookbehind: true, - alias: 'builtin' - } - }) } diff --git a/lang/graphql.js b/lang/graphql.js index fd2ffe7..93ba08a 100644 --- a/lang/graphql.js +++ b/lang/graphql.js @@ -6,8 +6,20 @@ graphql.aliases = [] function graphql(Prism) { Prism.languages.graphql = { comment: /#.*/, + description: { + pattern: /(?:"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*")(?=\s*[a-z_])/i, + greedy: true, + alias: 'string', + inside: { + 'language-markdown': { + pattern: /(^"(?:"")?)(?!\1)[\s\S]+(?=\1$)/, + lookbehind: true, + inside: Prism.languages.markdown + } + } + }, string: { - pattern: /"(?:\\.|[^\\"\r\n])*"/, + pattern: /"""(?:[^"]|(?!""")")*"""|"(?:\\.|[^\\"\r\n])*"/, greedy: true }, number: /(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i, @@ -22,7 +34,7 @@ function graphql(Prism) { greedy: true }, 'class-name': { - pattern: /(\b(?:enum|implements|interface|on|scalar|type|union)\s+)[a-zA-Z_]\w*/, + pattern: /(\b(?:enum|implements|interface|on|scalar|type|union)\s+|&\s*)[a-zA-Z_]\w*/, lookbehind: true }, fragment: { @@ -30,8 +42,8 @@ function graphql(Prism) { lookbehind: true, alias: 'function' }, - keyword: /\b(?:enum|fragment|implements|input|interface|mutation|on|query|scalar|schema|type|union)\b/, - operator: /[!=|]|\.{3}/, + keyword: /\b(?:directive|enum|extend|fragment|implements|input|interface|mutation|on|query|repeatable|scalar|schema|subscription|type|union)\b/, + operator: /[!=|&]|\.{3}/, punctuation: /[!(){}\[\]:=,]/, constant: /\b(?!ID\b)[A-Z][A-Z_\d]*\b/ } diff --git a/lang/groovy.js b/lang/groovy.js index 5c1aea2..31d47cd 100644 --- a/lang/groovy.js +++ b/lang/groovy.js @@ -7,7 +7,8 @@ function groovy(Prism) { Prism.languages.groovy = Prism.languages.extend('clike', { string: [ { - pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:\$\/\$|[\s\S])*?\/\$/, + // https://groovy-lang.org/syntax.html#_dollar_slashy_string + pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/, greedy: true }, { diff --git a/lang/haml.js b/lang/haml.js index e9750a9..4907b3e 100644 --- a/lang/haml.js +++ b/lang/haml.js @@ -1,9 +1,10 @@ 'use strict' - +var refractorRuby = require('./ruby.js') module.exports = haml haml.displayName = 'haml' haml.aliases = [] function haml(Prism) { + Prism.register(refractorRuby) /* TODO Handle multiline code after tag %foo= some | diff --git a/lang/hcl.js b/lang/hcl.js index 8ff1370..0a5cbb2 100644 --- a/lang/hcl.js +++ b/lang/hcl.js @@ -32,9 +32,7 @@ function hcl(Prism) { } } }, - { - pattern: /[\w-]+(?=\s+{)/ - } + /[\w-]+(?=\s+{)/ ], property: [/[\w-\.]+(?=\s*=(?!=))/, /"(?:\\[\s\S]|[^\\"])+"(?=\s*[:=])/], string: { @@ -56,13 +54,13 @@ function hcl(Prism) { pattern: /"(?:\\[\s\S]|[^\\"])*"/, greedy: true }, - number: /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i, + number: /\b0x[\da-f]+\b|\b\d+\.?\d*(?:e[+-]?\d+)?/i, punctuation: /[!\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~?:]/ } } } }, - number: /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i, + number: /\b0x[\da-f]+\b|\b\d+\.?\d*(?:e[+-]?\d+)?/i, boolean: /\b(?:true|false)\b/i, punctuation: /[=\[\]{}]/ } diff --git a/lang/hlsl.js b/lang/hlsl.js new file mode 100644 index 0000000..957ec05 --- /dev/null +++ b/lang/hlsl.js @@ -0,0 +1,26 @@ +'use strict' +var refractorC = require('./c.js') +module.exports = hlsl +hlsl.displayName = 'hlsl' +hlsl.aliases = [] +function hlsl(Prism) { + Prism.register(refractorC) + Prism.languages.hlsl = Prism.languages.extend('c', { + // Regarding keywords and class names: + // The list of all keywords was split into 'keyword' and 'class-name' tokens based on whether they are capitalized. + // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords + // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words + 'class-name': [ + Prism.languages.c['class-name'], + /\b(?:AppendStructuredBuffer|BlendState|Buffer|ByteAddressBuffer|CompileShader|ComputeShader|ConsumeStructuredBuffer|DepthStencilState|DepthStencilView|DomainShader|GeometryShader|Hullshader|InputPatch|LineStream|OutputPatch|PixelShader|PointStream|RasterizerState|RenderTargetView|RWBuffer|RWByteAddressBuffer|RWStructuredBuffer|RWTexture(?:1D|1DArray|2D|2DArray|3D)|SamplerComparisonState|SamplerState|StructuredBuffer|Texture(?:1D|1DArray|2D|2DArray|2DMS|2DMSArray|3D|Cube|CubeArray)|TriangleStream|VertexShader)\b/ + ], + keyword: [ + // HLSL keyword + /\b(?:asm|asm_fragment|auto|break|case|catch|cbuffer|centroid|char|class|column_major|compile|compile_fragment|const|const_cast|continue|default|delete|discard|do|dynamic_cast|else|enum|explicit|export|extern|for|friend|fxgroup|goto|groupshared|if|in|inline|inout|interface|line|lineadj|linear|long|matrix|mutable|namespace|new|nointerpolation|noperspective|operator|out|packoffset|pass|pixelfragment|point|precise|private|protected|public|register|reinterpret_cast|return|row_major|sample|sampler|shared|short|signed|sizeof|snorm|stateblock|stateblock_state|static|static_cast|string|struct|switch|tbuffer|technique|technique10|technique11|template|texture|this|throw|triangle|triangleadj|try|typedef|typename|uniform|union|unorm|unsigned|using|vector|vertexfragment|virtual|void|volatile|while)\b/, // scalar, vector, and matrix types + /\b(?:bool|double|dword|float|half|int|min(?:10float|12int|16(?:float|int|uint))|uint)(?:[1-4](?:x[1-4])?)?\b/ + ], + // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-grammar#floating-point-numbers + number: /(?:(?:\b\d+\.?\d*|\B\.\d+)(?:[eE][+-]?\d+)?|\b0x[\da-fA-F]+)[fFhHlLuU]?\b/, + boolean: /\b(?:false|true)\b/ + }) +} diff --git a/lang/hpkp.js b/lang/hpkp.js index 9f2ba7c..7f9689d 100644 --- a/lang/hpkp.js +++ b/lang/hpkp.js @@ -15,11 +15,11 @@ function hpkp(Prism) { alias: 'keyword' }, safe: { - pattern: /\d{7,}/, + pattern: /\b\d{7,}\b/, alias: 'selector' }, unsafe: { - pattern: /\d{1,6}/, + pattern: /\b\d{1,6}\b/, alias: 'function' } } diff --git a/lang/hsts.js b/lang/hsts.js index 6d80378..714ba29 100644 --- a/lang/hsts.js +++ b/lang/hsts.js @@ -15,11 +15,11 @@ function hsts(Prism) { alias: 'keyword' }, safe: { - pattern: /\d{8,}/, + pattern: /\b\d{8,}\b/, alias: 'selector' }, unsafe: { - pattern: /\d{1,7}/, + pattern: /\b\d{1,7}\b/, alias: 'function' } } diff --git a/lang/iecst.js b/lang/iecst.js new file mode 100644 index 0000000..47978d6 --- /dev/null +++ b/lang/iecst.js @@ -0,0 +1,37 @@ +'use strict' + +module.exports = iecst +iecst.displayName = 'iecst' +iecst.aliases = [] +function iecst(Prism) { + Prism.languages.iecst = { + comment: [ + { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?(?:\*\/|$)|\(\*[\s\S]*?(?:\*\)|$)|\{[\s\S]*?(?:\}|$))/, + lookbehind: true + }, + { + pattern: /(^|[^\\:])\/\/.*/, + lookbehind: true, + greedy: true + } + ], + string: { + pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, + greedy: true + }, + 'class-name': /\b(?:END_)?(?:PROGRAM|CONFIGURATION|INTERFACE|FUNCTION_BLOCK|FUNCTION|ACTION|TRANSITION|TYPE|STRUCT|(?:INITIAL_)?STEP|NAMESPACE|LIBRARY|CHANNEL|FOLDER|RESOURCE|VAR_(?:GLOBAL|INPUT|PUTPUT|IN_OUT|ACCESS|TEMP|EXTERNAL|CONFIG)|VAR|METHOD|PROPERTY)\b/i, + keyword: /\b(?:(?:END_)?(?:IF|WHILE|REPEAT|CASE|FOR)|ELSE|FROM|THEN|ELSIF|DO|TO|BY|PRIVATE|PUBLIC|PROTECTED|CONSTANT|RETURN|EXIT|CONTINUE|GOTO|JMP|AT|RETAIN|NON_RETAIN|TASK|WITH|UNTIL|USING|EXTENDS|IMPLEMENTS|GET|SET|__TRY|__CATCH|__FINALLY|__ENDTRY)\b/, + variable: /\b(?:AT|BOOL|BYTE|(?:D|L)?WORD|U?(?:S|D|L)?INT|L?REAL|TIME(?:_OF_DAY)?|TOD|DT|DATE(?:_AND_TIME)?|STRING|ARRAY|ANY|POINTER)\b/, + symbol: /%[IQM][XBWDL][\d.]*|%[IQ][\d.]*/, + number: /\b(?:16#[\da-f]+|2#[01_]+|0x[\da-f]+)\b|\b(?:T|D|DT|TOD)#[\d_shmd:]*|\b[A-Z]*\#[\d.,_]*|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i, + boolean: /\b(?:TRUE|FALSE|NULL)\b/, + function: /\w+(?=\()/, + operator: /(?:S?R?:?=>?|&&?|\*\*?|<=?|>=?|[-:^/+])|\b(?:OR|AND|MOD|NOT|XOR|LE|GE|EQ|NE|GE|LT)\b/, + punctuation: /[();]/, + type: { + pattern: /#/, + alias: 'selector' + } + } +} diff --git a/lang/ignore.js b/lang/ignore.js new file mode 100644 index 0000000..1b643be --- /dev/null +++ b/lang/ignore.js @@ -0,0 +1,28 @@ +'use strict' + +module.exports = ignore +ignore.displayName = 'ignore' +ignore.aliases = [] +function ignore(Prism) { + ;(function (Prism) { + Prism.languages.ignore = { + // https://git-scm.com/docs/gitignore + comment: /^#.*/m, + entry: { + pattern: /\S(?:.*(?:(?:\\ )|\S))?/, + alias: 'string', + inside: { + operator: /^!|\*\*?|\?/, + regex: { + pattern: /(^|[^\\])\[[^\[\]]*\]/, + lookbehind: true + }, + punctuation: /\// + } + } + } + Prism.languages.gitignore = Prism.languages.ignore + Prism.languages.hgignore = Prism.languages.ignore + Prism.languages.npmignore = Prism.languages.ignore + })(Prism) +} diff --git a/lang/io.js b/lang/io.js index fdc969f..c776aa5 100644 --- a/lang/io.js +++ b/lang/io.js @@ -32,7 +32,7 @@ function io(Prism) { builtin: /\b(?:Array|AudioDevice|AudioMixer|Block|Box|Buffer|CFunction|CGI|Color|Curses|DBM|DNSResolver|DOConnection|DOProxy|DOServer|Date|Directory|Duration|DynLib|Error|Exception|FFT|File|Fnmatch|Font|Future|GL|GLE|GLScissor|GLU|GLUCylinder|GLUQuadric|GLUSphere|GLUT|Host|Image|Importer|LinkList|List|Lobby|Locals|MD5|MP3Decoder|MP3Encoder|Map|Message|Movie|Notification|Number|Object|OpenGL|Point|Protos|Regex|SGML|SGMLElement|SGMLParser|SQLite|Server|Sequence|ShowMessage|SleepyCat|SleepyCatCursor|Socket|SocketManager|Sound|Soup|Store|String|Tree|UDPSender|UPDReceiver|URL|User|Warning|WeakLink|Random|BigNum|Sequence)\b/, boolean: /\b(?:true|false|nil)\b/, number: /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e-?\d+)?/i, - operator: /[=!*/%+-^&|]=|>>?=?|<>?=?|<+*\-%$|,#][.:]?|[?^]\.?|[;\[]:?|[~}"i][.:]|[ACeEIjLor]\.|(?:[_\/\\qsux]|_?\d):)/, alias: 'keyword' }, - number: /\b_?(?:(?!\d:)\d+(?:\.\d+)?(?:(?:[ejpx]|ad|ar)_?\d+(?:\.\d+)?)*(?:b_?[\da-z]+(?:\.[\da-z]+)?)?|_(?!\.))/, + number: /\b_?(?:(?!\d:)\d+(?:\.\d+)?(?:(?:[ejpx]|ad|ar)_?\d+(?:\.\d+)?)*(?:b_?[\da-z]+(?:\.[\da-z]+)?)?|_\b(?!\.))/, adverb: { pattern: /[~}]|[\/\\]\.?|[bfM]\.|t[.:]/, alias: 'builtin' diff --git a/lang/java.js b/lang/java.js index 405c685..db57fcf 100644 --- a/lang/java.js +++ b/lang/java.js @@ -42,7 +42,14 @@ function java(Prism) { lookbehind: true }, namespace: { - pattern: /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)[a-z]\w*(?:\.[a-z]\w*)+/, + pattern: RegExp( + /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!)[a-z]\w*(?:\.[a-z]\w*)*\.?/.source.replace( + //g, + function () { + return keywords.source + } + ) + ), lookbehind: true, inside: { punctuation: /\./ diff --git a/lang/javadoc.js b/lang/javadoc.js index 039a7d4..ad35a31 100644 --- a/lang/javadoc.js +++ b/lang/javadoc.js @@ -1,58 +1,98 @@ 'use strict' +var refractorJava = require('./java.js') var refractorJavadoclike = require('./javadoclike.js') module.exports = javadoc javadoc.displayName = 'javadoc' javadoc.aliases = [] function javadoc(Prism) { + Prism.register(refractorJava) Prism.register(refractorJavadoclike) ;(function (Prism) { - var codeLines = { - code: { - pattern: /(^(?:\s*(?:\*\s*)*)).*[^*\s].+$/m, - lookbehind: true, - inside: Prism.languages.java, - alias: 'language-java' + var codeLinePattern = /(^(?:\s*(?:\*\s*)*)).*[^*\s].*$/m + var memberReference = /#\s*\w+(?:\s*\([^()]*\))?/.source + var reference = /(?:[a-zA-Z]\w+\s*\.\s*)*[A-Z]\w*(?:\s*)?|/.source.replace( + //g, + function () { + return memberReference } - } + ) Prism.languages.javadoc = Prism.languages.extend('javadoclike', {}) Prism.languages.insertBefore('javadoc', 'keyword', { - 'class-name': [ - { - pattern: /(@(?:exception|throws|see|link|linkplain|value)\s+(?:[a-z\d]+\.)*)[A-Z](?:\w*[a-z]\w*)?(?:\.[A-Z](?:\w*[a-z]\w*)?)*/, - lookbehind: true, - inside: { - punctuation: /\./ - } - }, - { - // @param the first generic type parameter - pattern: /(@param\s+)<[A-Z]\w*>/, - lookbehind: true, - inside: { - punctuation: /[.<>]/ - } + reference: { + pattern: RegExp( + /(@(?:exception|throws|see|link|linkplain|value)\s+(?:\*\s*)?)/ + .source + + '(?:' + + reference + + ')' + ), + lookbehind: true, + inside: { + function: { + pattern: /(#\s*)\w+(?=\s*\()/, + lookbehind: true + }, + field: { + pattern: /(#\s*)\w+/, + lookbehind: true + }, + namespace: { + pattern: /\b(?:[a-z]\w*\s*\.\s*)+/, + inside: { + punctuation: /\./ + } + }, + 'class-name': /\b[A-Z]\w*/, + keyword: Prism.languages.java.keyword, + punctuation: /[#()[\],.]/ } - ], - namespace: { - pattern: /(@(?:exception|throws|see|link|linkplain)\s+)(?:[a-z\d]+\.)+/, + }, + 'class-name': { + // @param the first generic type parameter + pattern: /(@param\s+)<[A-Z]\w*>/, lookbehind: true, inside: { - punctuation: /\./ + punctuation: /[.<>]/ } }, 'code-section': [ { - pattern: /(\{@code\s+)(?:[^{}]|\{[^{}]*\})+?(?=\s*\})/, + pattern: /(\{@code\s+)(?:[^{}]|\{(?:[^{}]|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*\})+?(?=\s*\})/, lookbehind: true, - inside: codeLines + inside: { + code: { + // there can't be any HTML inside of {@code} tags + pattern: codeLinePattern, + lookbehind: true, + inside: Prism.languages.java, + alias: 'language-java' + } + } }, { - pattern: /(<(code|tt)>\s*)[\s\S]+?(?=\s*<\/\2>)/, + pattern: /(<(code|pre|tt)>(?!)\s*)[\s\S]+?(?=\s*<\/\2>)/, lookbehind: true, - inside: codeLines + inside: { + line: { + pattern: codeLinePattern, + lookbehind: true, + inside: { + // highlight HTML tags and entities + tag: Prism.languages.markup.tag, + entity: Prism.languages.markup.entity, + code: { + // everything else is Java code + pattern: /.+/, + inside: Prism.languages.java, + alias: 'language-java' + } + } + } + } } ], - tag: Prism.languages.markup.tag + tag: Prism.languages.markup.tag, + entity: Prism.languages.markup.entity }) Prism.languages.javadoclike.addSupport('java', Prism.languages.javadoc) })(Prism) diff --git a/lang/javascript.js b/lang/javascript.js index b700911..aedc20f 100644 --- a/lang/javascript.js +++ b/lang/javascript.js @@ -18,21 +18,21 @@ function javascript(Prism) { lookbehind: true }, { - pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/, + pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|(?:get|set)(?=\s*[\[$\w\xA0-\uFFFF])|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/, lookbehind: true } ], number: /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/, // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) function: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/, - operator: /--|\+\+|\*\*=?|=>|&&|\|\||[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?[.?]?|[~:]/ + operator: /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/ }) Prism.languages.javascript[ 'class-name' ][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/ Prism.languages.insertBefore('javascript', 'keyword', { regex: { - pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*[\s\S]*?\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/, + pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/, lookbehind: true, greedy: true }, @@ -57,7 +57,7 @@ function javascript(Prism) { inside: Prism.languages.javascript }, { - pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/, + pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/, lookbehind: true, inside: Prism.languages.javascript } diff --git a/lang/jq.js b/lang/jq.js index da0cd06..f12202b 100644 --- a/lang/jq.js +++ b/lang/jq.js @@ -43,12 +43,12 @@ function jq(Prism) { }, variable: /\B\$\w+/, 'property-literal': { - pattern: /[a-z_]\w*(?=\s*:(?!:))/i, + pattern: /\b[a-z_]\w*(?=\s*:(?!:))/i, alias: 'property' }, keyword: /\b(?:as|break|catch|def|elif|else|end|foreach|if|import|include|label|module|modulemeta|null|reduce|then|try|while)\b/, boolean: /\b(?:true|false)\b/, - number: /(?:\b\d+\.|\B\.)?\d+(?:[eE][+-]?\d+)?\b/, + number: /(?:\b\d+\.|\B\.)?\b\d+(?:[eE][+-]?\d+)?\b/, operator: [ { pattern: /\|=?/, diff --git a/lang/jsdoc.js b/lang/jsdoc.js index e511969..fcadcf0 100644 --- a/lang/jsdoc.js +++ b/lang/jsdoc.js @@ -1,10 +1,12 @@ 'use strict' var refractorJavadoclike = require('./javadoclike.js') +var refractorTypescript = require('./typescript.js') module.exports = jsdoc jsdoc.displayName = 'jsdoc' jsdoc.aliases = [] function jsdoc(Prism) { Prism.register(refractorJavadoclike) + Prism.register(refractorTypescript) ;(function (Prism) { var javascript = Prism.languages.javascript var type = /{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})+}/.source @@ -46,17 +48,29 @@ function jsdoc(Prism) { }, 'class-name': [ { - pattern: RegExp('(@[a-z]+\\s+)' + type), + pattern: RegExp( + /(@(?:augments|extends|class|interface|memberof!?|template|this|typedef)\s+(?:\s+)?)[A-Z]\w*(?:\.[A-Z]\w*)*/.source.replace( + //g, + function () { + return type + } + ) + ), lookbehind: true, inside: { - punctuation: /[.,:?=<>|{}()[\]]/ + punctuation: /\./ } }, { - pattern: /(@(?:augments|extends|class|interface|memberof!?|this)\s+)[A-Z]\w*(?:\.[A-Z]\w*)*/, + pattern: RegExp('(@[a-z]+\\s+)' + type), lookbehind: true, inside: { - punctuation: /\./ + string: javascript.string, + number: javascript.number, + boolean: javascript.boolean, + keyword: Prism.languages.typescript.keyword, + operator: /=>|\.\.\.|[&|?:*]/, + punctuation: /[.,;=<>{}()[\]]/ } } ], diff --git a/lang/json.js b/lang/json.js index c2828b3..70f978f 100644 --- a/lang/json.js +++ b/lang/json.js @@ -2,8 +2,9 @@ module.exports = json json.displayName = 'json' -json.aliases = [] +json.aliases = ['webmanifest'] function json(Prism) { + // https://www.json.org/json-en.html Prism.languages.json = { property: { pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/, @@ -13,8 +14,11 @@ function json(Prism) { pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/, greedy: true }, - comment: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, - number: /-?\d+\.?\d*(?:e[+-]?\d+)?/i, + comment: { + pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, + greedy: true + }, + number: /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i, punctuation: /[{}[\],]/, operator: /:/, boolean: /\b(?:true|false)\b/, @@ -23,4 +27,5 @@ function json(Prism) { alias: 'keyword' } } + Prism.languages.webmanifest = Prism.languages.json } diff --git a/lang/json5.js b/lang/json5.js index cc19744..b51a2e0 100644 --- a/lang/json5.js +++ b/lang/json5.js @@ -22,7 +22,7 @@ function json5(Prism) { pattern: string, greedy: true }, - number: /[+-]?(?:NaN|Infinity|0x[a-fA-F\d]+|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/ + number: /[+-]?\b(?:NaN|Infinity|0x[a-fA-F\d]+)\b|[+-]?(?:\b\d+\.?\d*|\B\.\d+)(?:[eE][+-]?\d+\b)?/ }) })(Prism) } diff --git a/lang/jsstacktrace.js b/lang/jsstacktrace.js new file mode 100644 index 0000000..30c3853 --- /dev/null +++ b/lang/jsstacktrace.js @@ -0,0 +1,47 @@ +'use strict' + +module.exports = jsstacktrace +jsstacktrace.displayName = 'jsstacktrace' +jsstacktrace.aliases = [] +function jsstacktrace(Prism) { + Prism.languages.jsstacktrace = { + 'error-message': { + pattern: /^\S.*/m, + alias: 'string' + }, + 'stack-frame': { + pattern: /^[ \t]+at[ \t]+.*/m, + inside: { + 'not-my-code': { + pattern: /[ \t]+at[ \t]+(?:node\.js|\|.*(?:node_modules|\(\\)|\(\|\$|\(internal\/|\(node\.js)).*/m, + alias: 'comment' + }, + filename: { + pattern: /(\bat\s+|\()(?:[a-zA-Z]:)?[^():]+(?=:)/, + lookbehind: true, + alias: 'url' + }, + function: { + pattern: /(at\s+(?:new\s+)?)[_$a-zA-Z\xA0-\uFFFF<][.$\w\xA0-\uFFFF<>]*/, + lookbehind: true, + inside: { + punctuation: /\./ + } + }, + punctuation: /[()]/, + keyword: /\b(?:at|new)\b/, + alias: { + pattern: /\[(?:as\s+)?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\]/, + alias: 'variable' + }, + 'line-number': { + pattern: /:[0-9]+(?::[0-9]+)?\b/, + alias: 'number', + inside: { + punctuation: /:/ + } + } + } + } + } +} diff --git a/lang/jsx.js b/lang/jsx.js index 84ab662..024bf14 100644 --- a/lang/jsx.js +++ b/lang/jsx.js @@ -7,7 +7,7 @@ function jsx(Prism) { ;(function (Prism) { var javascript = Prism.util.clone(Prism.languages.javascript) Prism.languages.jsx = Prism.languages.extend('markup', javascript) - Prism.languages.jsx.tag.pattern = /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:$-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s{'">=]+|\{(?:\{(?:\{[^}]*\}|[^{}])*\}|[^{}])+\}))?|\{\s*\.{3}\s*[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\s*\}))*\s*\/?)?>/i + Prism.languages.jsx.tag.pattern = /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:$-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s{'">=]+|\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])+\}))?|\{\s*\.{3}\s*[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\s*\}))*\s*\/?)?>/i Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i Prism.languages.jsx.tag.inside[ 'attr-value' @@ -35,7 +35,7 @@ function jsx(Prism) { { script: { // Allow for two levels of nesting - pattern: /=(?:\{(?:\{(?:\{[^}]*\}|[^}])*\}|[^}])+\})/i, + pattern: /=(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])+\})/i, inside: { 'script-punctuation': { pattern: /^=(?={)/, diff --git a/lang/julia.js b/lang/julia.js index 43983c5..8f78c07 100644 --- a/lang/julia.js +++ b/lang/julia.js @@ -6,15 +6,33 @@ julia.aliases = [] function julia(Prism) { Prism.languages.julia = { comment: { - pattern: /(^|[^\\])#.*/, + // support one level of nested comments + // https://github.com/JuliaLang/julia/pull/6128 + pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/, lookbehind: true }, - string: /("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2/, + regex: { + // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1 + pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/, + greedy: true + }, + string: { + // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1 + // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1 + // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1 + // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1 + pattern: /"""[\s\S]+?"""|\w*"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/, + lookbehind: true, + greedy: true + }, keyword: /\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/, boolean: /\b(?:true|false)\b/, - number: /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:[efp][+-]?\d+)?j?/i, - operator: /[-+*^%÷&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥]/, - punctuation: /[{}[\];(),.:]/, - constant: /\b(?:(?:NaN|Inf)(?:16|32|64)?)\b/ + number: /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*\.?(?:\d+(?:_\d+)*)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i, + // https://docs.julialang.org/en/v1/manual/mathematical-operations/ + // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1 + operator: /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/, + punctuation: /::?|[{}[\]();,.?]/, + // https://docs.julialang.org/en/v1/base/numbers/#Base.im + constant: /\b(?:(?:NaN|Inf)(?:16|32|64)?|im|pi|e|catalan|eulergamma|golden)\b|[πℯγφ]/ } } diff --git a/lang/kotlin.js b/lang/kotlin.js index bd6bb0b..00e0a06 100644 --- a/lang/kotlin.js +++ b/lang/kotlin.js @@ -2,7 +2,7 @@ module.exports = kotlin kotlin.displayName = 'kotlin' -kotlin.aliases = [] +kotlin.aliases = ['kt', 'kts'] function kotlin(Prism) { ;(function (Prism) { Prism.languages.kotlin = Prism.languages.extend('clike', { @@ -61,5 +61,7 @@ function kotlin(Prism) { ].inside = { interpolation: interpolation } + Prism.languages.kt = Prism.languages.kotlin + Prism.languages.kts = Prism.languages.kotlin })(Prism) } diff --git a/lang/latte.js b/lang/latte.js index ddbd0f0..df5c9ff 100644 --- a/lang/latte.js +++ b/lang/latte.js @@ -1,10 +1,12 @@ 'use strict' var refractorMarkupTemplating = require('./markup-templating.js') +var refractorPhp = require('./php.js') module.exports = latte latte.displayName = 'latte' latte.aliases = [] function latte(Prism) { Prism.register(refractorMarkupTemplating) + Prism.register(refractorPhp) ;(function (Prism) { Prism.languages.latte = { comment: /^\{\*[\s\S]*/, diff --git a/lang/lilypond.js b/lang/lilypond.js index 46501ff..cce007f 100644 --- a/lang/lilypond.js +++ b/lang/lilypond.js @@ -1,11 +1,12 @@ 'use strict' - +var refractorScheme = require('./scheme.js') module.exports = lilypond lilypond.displayName = 'lilypond' lilypond.aliases = [] function lilypond(Prism) { + Prism.register(refractorScheme) ;(function (Prism) { - var schemeExpression = /\((?:[^();"#\\]|\\[\s\S]|;.*|"(?:[^"\\]|\\.)*"|#(?:\{(?:(?!#\})[\s\S])*#\}|[^{])|)*\)/ + var schemeExpression = /\((?:[^();"#\\]|\\[\s\S]|;.*(?!.)|"(?:[^"\\]|\\.)*"|#(?:\{(?:(?!#\})[\s\S])*#\}|[^{])|)*\)/ .source // allow for up to pow(2, recursivenessLog2) many levels of recursive brace expressions // For some reason, this can't be 4 var recursivenessLog2 = 5 diff --git a/lang/livescript.js b/lang/livescript.js index 9046916..4c77339 100644 --- a/lang/livescript.js +++ b/lang/livescript.js @@ -52,7 +52,7 @@ function livescript(Prism) { ], regex: [ { - pattern: /\/\/(?:\[.+?]|\\.|(?!\/\/)[^\\])+\/\/[gimyu]{0,5}/, + pattern: /\/\/(?:\[[^\r\n\]]*\]|\\.|(?!\/\/)[^\\\[])+\/\/[gimyu]{0,5}/, greedy: true, inside: { comment: { @@ -62,7 +62,7 @@ function livescript(Prism) { } }, { - pattern: /\/(?:\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}/, + pattern: /\/(?:\[[^\r\n\]]*\]|\\.|[^/\\\r\n\[])+\/[gimyu]{0,5}/, greedy: true } ], diff --git a/lang/lolcode.js b/lang/lolcode.js index 6d77286..54bd7a8 100644 --- a/lang/lolcode.js +++ b/lang/lolcode.js @@ -7,7 +7,7 @@ function lolcode(Prism) { Prism.languages.lolcode = { comment: [/\bOBTW\s+[\s\S]*?\s+TLDR\b/, /\bBTW.+/], string: { - pattern: /"(?::.|[^"])*"/, + pattern: /"(?::.|[^":])*"/, inside: { variable: /:\{[^}]+\}/, symbol: [/:\([a-f\d]+\)/i, /:\[[^\]]+\]/, /:[)>o":]/] diff --git a/lang/markdown.js b/lang/markdown.js index 8dc0a40..eac1861 100644 --- a/lang/markdown.js +++ b/lang/markdown.js @@ -15,19 +15,16 @@ function markdown(Prism) { * _Note:_ Keep in mind that this adds a capturing group. * * @param {string} pattern - * @param {boolean} starAlternative Whether to also add an alternative where all `_`s are replaced with `*`s. * @returns {RegExp} */ - function createInline(pattern, starAlternative) { + function createInline(pattern) { pattern = pattern.replace(//g, function () { return inner }) - if (starAlternative) { - pattern = pattern + '|' + pattern.replace(/_/g, '\\*') - } return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')') } - var tableCell = /(?:\\.|``.+?``|`[^`\r\n]+`|[^\\|\r\n`])+/.source + var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/ + .source var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|$)/.source.replace( /__/g, function () { @@ -176,8 +173,8 @@ function markdown(Prism) { // __strong__ // allow one nested instance of italic text using the same delimiter pattern: createInline( - /__(?:(?!_)|_(?:(?!_))+_)+__/.source, - true + /\b__(?:(?!_)|_(?:(?!_))+_)+__\b|\*\*(?:(?!\*)|\*(?:(?!\*))+\*)+\*\*/ + .source ), lookbehind: true, greedy: true, @@ -195,8 +192,8 @@ function markdown(Prism) { // _em_ // allow one nested instance of bold text using the same delimiter pattern: createInline( - /_(?:(?!_)|__(?:(?!_))+__)+_/.source, - true + /\b_(?:(?!_)|__(?:(?!_))+__)+_\b|\*(?:(?!\*)|\*\*(?:(?!\*))+\*\*)+\*/ + .source ), lookbehind: true, greedy: true, @@ -212,7 +209,7 @@ function markdown(Prism) { strike: { // ~~strike through~~ // ~strike~ - pattern: createInline(/(~~?)(?:(?!~))+?\2/.source, false), + pattern: createInline(/(~~?)(?:(?!~))+?\2/.source), lookbehind: true, greedy: true, inside: { @@ -230,8 +227,7 @@ function markdown(Prism) { // [example] [id] pattern: createInline( /!?\[(?:(?!\]))+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[(?:(?!\]))+\])/ - .source, - false + .source ), lookbehind: true, greedy: true, diff --git a/lang/markup.js b/lang/markup.js index 14298d3..55f594e 100644 --- a/lang/markup.js +++ b/lang/markup.js @@ -2,36 +2,52 @@ module.exports = markup markup.displayName = 'markup' -markup.aliases = ['xml', 'html', 'mathml', 'svg'] +markup.aliases = ['html', 'mathml', 'svg', 'xml', 'ssml', 'atom', 'rss'] function markup(Prism) { Prism.languages.markup = { comment: //, prolog: /<\?[\s\S]+?\?>/, doctype: { - pattern: /"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:(?!)*\]\s*)?>/i, - greedy: true + // https://www.w3.org/TR/xml/#NT-doctypedecl + pattern: /"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i, + greedy: true, + inside: { + 'internal-subset': { + pattern: /(\[)[\s\S]+(?=\]>$)/, + lookbehind: true, + greedy: true, + inside: null // see below + }, + string: { + pattern: /"[^"]*"|'[^']*'/, + greedy: true + }, + punctuation: /^$|[[\]]/, + 'doctype-tag': /^DOCTYPE/, + name: /[^\s<>'"]+/ + } }, cdata: //i, tag: { - pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i, + pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/, greedy: true, inside: { tag: { - pattern: /^<\/?[^\s>\/]+/i, + pattern: /^<\/?[^\s>\/]+/, inside: { punctuation: /^<\/?/, namespace: /^[^\s>\/:]+:/ } }, 'attr-value': { - pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i, + pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/, inside: { punctuation: [ - /^=/, { - pattern: /^(\s*)["']|["']$/, - lookbehind: true - } + pattern: /^=/, + alias: 'attr-equals' + }, + /"|'/ ] } }, @@ -44,10 +60,18 @@ function markup(Prism) { } } }, - entity: /&#?[\da-z]{1,8};/i + entity: [ + { + pattern: /&[\da-z]{1,8};/i, + alias: 'named-entity' + }, + /&#x?[\da-f]{1,8};/i + ] } Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = - Prism.languages.markup['entity'] // Plugin to make entity title show the real entity, idea by Roman Komarov + Prism.languages.markup['entity'] + Prism.languages.markup['doctype'].inside['internal-subset'].inside = + Prism.languages.markup // Plugin to make entity title show the real entity, idea by Roman Komarov Prism.hooks.add('wrap', function (env) { if (env.type === 'entity') { env.attributes['title'] = env.content.value.replace(/&/, '&') @@ -86,7 +110,7 @@ function markup(Prism) { var def = {} def[tagName] = { pattern: RegExp( - /(<__[\s\S]*?>)(?:\s*|[\s\S])*?(?=<\/__>)/.source.replace( + /(<__[\s\S]*?>)(?:))*\]\]>|(?!)/.source.replace( /__/g, function () { return tagName @@ -101,8 +125,11 @@ function markup(Prism) { Prism.languages.insertBefore('markup', 'cdata', def) } }) - Prism.languages.xml = Prism.languages.extend('markup', {}) Prism.languages.html = Prism.languages.markup Prism.languages.mathml = Prism.languages.markup Prism.languages.svg = Prism.languages.markup + Prism.languages.xml = Prism.languages.extend('markup', {}) + Prism.languages.ssml = Prism.languages.xml + Prism.languages.atom = Prism.languages.xml + Prism.languages.rss = Prism.languages.xml } diff --git a/lang/neon.js b/lang/neon.js index 1d1619c..12d9b57 100644 --- a/lang/neon.js +++ b/lang/neon.js @@ -33,7 +33,7 @@ function neon(Prism) { alias: 'keyword' }, string: { - pattern: /(^|[[{(=:,\s])(?:('''|""")\r?\n(?:(?:[^\r\n]|\r?\n(?![\t ]*\2))*\r?\n)?[\t ]*\2|'[^'\r\n]*'|"(?:\\.|[^"\r\n])*")/, + pattern: /(^|[[{(=:,\s])(?:('''|""")\r?\n(?:(?:[^\r\n]|\r?\n(?![\t ]*\2))*\r?\n)?[\t ]*\2|'[^'\r\n]*'|"(?:\\.|[^\\"\r\n])*")/, lookbehind: true, greedy: true }, diff --git a/lang/objectivec.js b/lang/objectivec.js index 117554d..89e2823 100644 --- a/lang/objectivec.js +++ b/lang/objectivec.js @@ -2,7 +2,7 @@ var refractorC = require('./c.js') module.exports = objectivec objectivec.displayName = 'objectivec' -objectivec.aliases = [] +objectivec.aliases = ['objc'] function objectivec(Prism) { Prism.register(refractorC) Prism.languages.objectivec = Prism.languages.extend('c', { @@ -11,4 +11,5 @@ function objectivec(Prism) { operator: /-[->]?|\+\+?|!=?|<>?=?|==?|&&?|\|\|?|[~^%?*\/@]/ }) delete Prism.languages.objectivec['class-name'] + Prism.languages.objc = Prism.languages.objectivec } diff --git a/lang/ocaml.js b/lang/ocaml.js index 5fa5642..2e80daa 100644 --- a/lang/ocaml.js +++ b/lang/ocaml.js @@ -43,6 +43,6 @@ function ocaml(Prism) { boolean: /\b(?:false|true)\b/, // Custom operators are allowed operator: /:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/, - punctuation: /[(){}\[\]|_.,:;]/ + punctuation: /[(){}\[\]|.,:;]|\b_\b/ } } diff --git a/lang/opencl.js b/lang/opencl.js index b6b9894..27c3ab6 100644 --- a/lang/opencl.js +++ b/lang/opencl.js @@ -1,12 +1,10 @@ 'use strict' var refractorC = require('./c.js') -var refractorCpp = require('./cpp.js') module.exports = opencl opencl.displayName = 'opencl' opencl.aliases = [] function opencl(Prism) { Prism.register(refractorC) - Prism.register(refractorCpp) ;(function (Prism) { /* OpenCL kernel language */ Prism.languages.opencl = Prism.languages.extend('c', { diff --git a/lang/oz.js b/lang/oz.js index 31a41a5..81b5d90 100644 --- a/lang/oz.js +++ b/lang/oz.js @@ -15,15 +15,15 @@ function oz(Prism) { greedy: true, alias: 'builtin' }, - keyword: /[$_]|\[\]|\b(?:at|attr|case|catch|choice|class|cond|declare|define|dis|else(?:case|if)?|end|export|fail|false|feat|finally|from|fun|functor|if|import|in|local|lock|meth|nil|not|of|or|prepare|proc|prop|raise|require|self|skip|then|thread|true|try|unit)\b/, + keyword: /\$|\[\]|\b(?:_|at|attr|case|catch|choice|class|cond|declare|define|dis|else(?:case|if)?|end|export|fail|false|feat|finally|from|fun|functor|if|import|in|local|lock|meth|nil|not|of|or|prepare|proc|prop|raise|require|self|skip|then|thread|true|try|unit)\b/, function: [ - /[a-z][A-Za-z\d]*(?=\()/, + /\b[a-z][A-Za-z\d]*(?=\()/, { - pattern: /(\{)[A-Z][A-Za-z\d]*/, + pattern: /(\{)[A-Z][A-Za-z\d]*\b/, lookbehind: true } ], - number: /\b(?:0[bx][\da-f]+|\d+\.?\d*(?:e~?\d+)?\b)|&(?:[^\\]|\\(?:\d{3}|.))/i, + number: /\b(?:0[bx][\da-f]+|\d+\.?\d*(?:e~?\d+)?)\b|&(?:[^\\]|\\(?:\d{3}|.))/i, variable: /\b[A-Z][A-Za-z\d]*|`(?:[^`\\]|\\.)+`/, 'attr-name': /\w+(?=:)/, operator: /:(?:=|::?)|<[-:=]?|=(?:=|=?:?|\\=:?|!!?|[|#+\-*\/,~^@]|\b(?:andthen|div|mod|orelse)\b/, diff --git a/lang/parigp.js b/lang/parigp.js index 25b2a23..e62781c 100644 --- a/lang/parigp.js +++ b/lang/parigp.js @@ -49,7 +49,7 @@ function parigp(Prism) { function: /\w[\w ]*?(?= *\()/, number: { // The lookbehind and the negative lookahead prevent from breaking the .. operator - pattern: /((?:\. *\. *)?)(?:\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *[+-]? *\d(?: *\d)*)?/i, + pattern: /((?:\. *\. *)?)(?:\b\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *[+-]? *\d(?: *\d)*)?/i, lookbehind: true }, operator: /\. *\.|[*\/!](?: *=)?|%(?: *=|(?: *#)?(?: *')*)?|\+(?: *[+=])?|-(?: *[-=>])?|<(?:(?: *<)?(?: *=)?| *>)?|>(?: *>)?(?: *=)?|=(?: *=){0,2}|\\(?: *\/)?(?: *=)?|&(?: *&)?|\| *\||['#~^]/, diff --git a/lang/pascal.js b/lang/pascal.js index cddb893..703014d 100644 --- a/lang/pascal.js +++ b/lang/pascal.js @@ -11,7 +11,7 @@ Support inline asm ? Prism.languages.pascal = { comment: [/\(\*[\s\S]+?\*\)/, /\{[\s\S]+?\}/, /\/\/.*/], string: { - pattern: /(?:'(?:''|[^'\r\n])*'|#[&$%]?[a-f\d]+)+|\^[a-z]/i, + pattern: /(?:'(?:''|[^'\r\n])*'(?!')|#[&$%]?[a-f\d]+)+|\^[a-z]/i, greedy: true }, keyword: [ diff --git a/lang/peoplecode.js b/lang/peoplecode.js new file mode 100644 index 0000000..62d44b3 --- /dev/null +++ b/lang/peoplecode.js @@ -0,0 +1,46 @@ +'use strict' + +module.exports = peoplecode +peoplecode.displayName = 'peoplecode' +peoplecode.aliases = ['pcode'] +function peoplecode(Prism) { + Prism.languages.peoplecode = { + comment: RegExp( + [ + // C-style multiline comments + /\/\*[\s\S]*?\*\//.source, // REM comments + /\bREM[^;]*;/.source, // Nested <* *> comments + /<\*(?:[^<*]|\*(?!>)|<(?!\*)|<\*(?:(?!\*>)[\s\S])*\*>)*\*>/.source, // /+ +/ comments + /\/\+[\s\S]*?\+\//.source + ].join('|') + ), + string: { + pattern: /'(?:''|[^'\r\n])*'(?!')|"(?:""|[^"\r\n])*"(?!")/, + greedy: true + }, + variable: /%\w+/, + 'function-definition': { + pattern: /((?:^|[^\w-])(?:function|method)\s+)\w+/i, + lookbehind: true, + alias: 'function' + }, + 'class-name': { + pattern: /((?:^|[^-\w])(?:as|catch|class|component|create|extends|global|implements|instance|local|of|property|returns)\s+)\w+(?::\w+)*/i, + lookbehind: true, + inside: { + punctuation: /:/ + } + }, + keyword: /\b(?:abstract|alias|as|catch|class|component|constant|create|declare|else|end-(?:class|evaluate|for|function|get|if|method|set|try|while)|evaluate|extends|for|function|get|global|implements|import|instance|if|library|local|method|null|of|out|peopleCode|private|program|property|protected|readonly|ref|repeat|returns?|set|step|then|throw|to|try|until|value|when(?:-other)?|while)\b/i, + 'operator-keyword': { + pattern: /\b(?:and|not|or)\b/i, + alias: 'operator' + }, + function: /[_a-z]\w*(?=\s*\()/i, + boolean: /\b(?:false|true)\b/i, + number: /\b\d+(?:\.\d+)?\b/, + operator: /<>|[<>]=?|!=|\*\*|[-+*/|=@]/, + punctuation: /[:.;,()[\]]/ + } + Prism.languages.pcode = Prism.languages.peoplecode +} diff --git a/lang/php.js b/lang/php.js index 36afb99..9a4d5ac 100644 --- a/lang/php.js +++ b/lang/php.js @@ -60,13 +60,13 @@ function php(Prism) { } }) var string_interpolation = { - pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/, + pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/, lookbehind: true, inside: Prism.languages.php } Prism.languages.insertBefore('php', 'string', { 'nowdoc-string': { - pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/, + pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/, greedy: true, alias: 'string', inside: { @@ -80,7 +80,7 @@ function php(Prism) { } }, 'heredoc-string': { - pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i, + pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i, greedy: true, alias: 'string', inside: { diff --git a/lang/phpdoc.js b/lang/phpdoc.js index c371aae..7a9775a 100644 --- a/lang/phpdoc.js +++ b/lang/phpdoc.js @@ -1,9 +1,11 @@ 'use strict' +var refractorPhp = require('./php.js') var refractorJavadoclike = require('./javadoclike.js') module.exports = phpdoc phpdoc.displayName = 'phpdoc' phpdoc.aliases = [] function phpdoc(Prism) { + Prism.register(refractorPhp) Prism.register(refractorJavadoclike) ;(function (Prism) { var typeExpression = /(?:\b[a-zA-Z]\w*|[|\\[\]])+/.source diff --git a/lang/powershell.js b/lang/powershell.js index b83fefb..56e5470 100644 --- a/lang/powershell.js +++ b/lang/powershell.js @@ -23,7 +23,7 @@ function powershell(Prism) { inside: { function: { // Allow for one level of nesting - pattern: /(^|[^`])\$\((?:\$\(.*?\)|(?!\$\()[^\r\n)])*\)/, + pattern: /(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/, lookbehind: true, // Populated at end of file inside: {} @@ -39,12 +39,12 @@ function powershell(Prism) { // Supports two levels of nested brackets (e.g. `[OutputType([System.Collections.Generic.List[int]])]`) namespace: /\[[a-z](?:\[(?:\[[^\]]*]|[^\[\]])*]|[^\[\]])*]/i, boolean: /\$(?:true|false)\b/i, - variable: /\$\w+\b/i, + variable: /\$\w+\b/, // Cmdlets and aliases. Aliases should come last, otherwise "write" gets preferred over "write-host" for example // Get-Command | ?{ $_.ModuleName -match "Microsoft.PowerShell.(Util|Core|Management)" } // Get-Alias | ?{ $_.ReferencedCommand.Module.Name -match "Microsoft.PowerShell.(Util|Core|Management)" } function: [ - /\b(?:Add-(?:Computer|Content|History|Member|PSSnapin|Type)|Checkpoint-Computer|Clear-(?:Content|EventLog|History|Item|ItemProperty|Variable)|Compare-Object|Complete-Transaction|Connect-PSSession|ConvertFrom-(?:Csv|Json|StringData)|Convert-Path|ConvertTo-(?:Csv|Html|Json|Xml)|Copy-(?:Item|ItemProperty)|Debug-Process|Disable-(?:ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)|Disconnect-PSSession|Enable-(?:ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)|Enter-PSSession|Exit-PSSession|Export-(?:Alias|Clixml|Console|Csv|FormatData|ModuleMember|PSSession)|ForEach-Object|Format-(?:Custom|List|Table|Wide)|Get-(?:Alias|ChildItem|Command|ComputerRestorePoint|Content|ControlPanelItem|Culture|Date|Event|EventLog|EventSubscriber|FormatData|Help|History|Host|HotFix|Item|ItemProperty|Job|Location|Member|Module|Process|PSBreakpoint|PSCallStack|PSDrive|PSProvider|PSSession|PSSessionConfiguration|PSSnapin|Random|Service|TraceSource|Transaction|TypeData|UICulture|Unique|Variable|WmiObject)|Group-Object|Import-(?:Alias|Clixml|Csv|LocalizedData|Module|PSSession)|Invoke-(?:Command|Expression|History|Item|RestMethod|WebRequest|WmiMethod)|Join-Path|Limit-EventLog|Measure-(?:Command|Object)|Move-(?:Item|ItemProperty)|New-(?:Alias|Event|EventLog|Item|ItemProperty|Module|ModuleManifest|Object|PSDrive|PSSession|PSSessionConfigurationFile|PSSessionOption|PSTransportOption|Service|TimeSpan|Variable|WebServiceProxy)|Out-(?:Default|File|GridView|Host|Null|Printer|String)|Pop-Location|Push-Location|Read-Host|Receive-(?:Job|PSSession)|Register-(?:EngineEvent|ObjectEvent|PSSessionConfiguration|WmiEvent)|Remove-(?:Computer|Event|EventLog|Item|ItemProperty|Job|Module|PSBreakpoint|PSDrive|PSSession|PSSnapin|TypeData|Variable|WmiObject)|Rename-(?:Computer|Item|ItemProperty)|Reset-ComputerMachinePassword|Resolve-Path|Restart-(?:Computer|Service)|Restore-Computer|Resume-(?:Job|Service)|Save-Help|Select-(?:Object|String|Xml)|Send-MailMessage|Set-(?:Alias|Content|Date|Item|ItemProperty|Location|PSBreakpoint|PSDebug|PSSessionConfiguration|Service|StrictMode|TraceSource|Variable|WmiInstance)|Show-(?:Command|ControlPanelItem|EventLog)|Sort-Object|Split-Path|Start-(?:Job|Process|Service|Sleep|Transaction)|Stop-(?:Computer|Job|Process|Service)|Suspend-(?:Job|Service)|Tee-Object|Test-(?:ComputerSecureChannel|Connection|ModuleManifest|Path|PSSessionConfigurationFile)|Trace-Command|Unblock-File|Undo-Transaction|Unregister-(?:Event|PSSessionConfiguration)|Update-(?:FormatData|Help|List|TypeData)|Use-Transaction|Wait-(?:Event|Job|Process)|Where-Object|Write-(?:Debug|Error|EventLog|Host|Output|Progress|Verbose|Warning))\b/i, + /\b(?:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|ForEach|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Move|New|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Sort|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Tee|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Where|Write)-[a-z]+\b/i, /\b(?:ac|cat|chdir|clc|cli|clp|clv|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|ebp|echo|epal|epcsv|epsn|erase|fc|fl|ft|fw|gal|gbp|gc|gci|gcs|gdr|gi|gl|gm|gp|gps|group|gsv|gu|gv|gwmi|iex|ii|ipal|ipcsv|ipsn|irm|iwmi|iwr|kill|lp|ls|measure|mi|mount|move|mp|mv|nal|ndr|ni|nv|ogv|popd|ps|pushd|pwd|rbp|rd|rdr|ren|ri|rm|rmdir|rni|rnp|rp|rv|rvpa|rwmi|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spps|spsv|start|sv|swmi|tee|trcm|type|write)\b/i ], // per http://technet.microsoft.com/en-us/library/hh847744.aspx diff --git a/lang/protobuf.js b/lang/protobuf.js index 433f7f3..7e862b7 100644 --- a/lang/protobuf.js +++ b/lang/protobuf.js @@ -7,15 +7,22 @@ function protobuf(Prism) { ;(function (Prism) { var builtinTypes = /\b(?:double|float|[su]?int(?:32|64)|s?fixed(?:32|64)|bool|string|bytes)\b/ Prism.languages.protobuf = Prism.languages.extend('clike', { - 'class-name': { - pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/, - lookbehind: true - }, - keyword: /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|service|syntax|to)\b/ + 'class-name': [ + { + pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/, + lookbehind: true + }, + { + pattern: /(\b(?:rpc\s+\w+|returns)\s*\(\s*(?:stream\s+)?)\.?[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s*\))/, + lookbehind: true + } + ], + keyword: /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|returns|rpc(?=\s+\w)|service|stream|syntax|to)\b(?!\s*=\s*\d)/, + function: /[a-z_]\w*(?=\s*\()/i }) Prism.languages.insertBefore('protobuf', 'operator', { map: { - pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[A-Za-z_]\w*\s*[=;])/, + pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[a-z_]\w*\s*[=;])/i, alias: 'class-name', inside: { punctuation: /[<>.,]/, @@ -24,14 +31,14 @@ function protobuf(Prism) { }, builtin: builtinTypes, 'positional-class-name': { - pattern: /(?:\b|\B\.)[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s+[A-Za-z_]\w*\s*[=;])/, + pattern: /(?:\b|\B\.)[a-z_]\w*(?:\.[a-z_]\w*)*(?=\s+[a-z_]\w*\s*[=;])/i, alias: 'class-name', inside: { punctuation: /\./ } }, annotation: { - pattern: /(\[\s*)[A-Za-z_]\w*(?=\s*=)/, + pattern: /(\[\s*)[a-z_]\w*(?=\s*=)/i, lookbehind: true } }) diff --git a/lang/pug.js b/lang/pug.js index cf8a1f5..776be6c 100644 --- a/lang/pug.js +++ b/lang/pug.js @@ -127,7 +127,9 @@ function pug(Prism) { } } ], - punctuation: /:/ + punctuation: /:/, + 'attr-id': /#[\w\-]+/, + 'attr-class': /\.[\w\-]+/ } }, code: [ diff --git a/lang/pure.js b/lang/pure.js index 499d88a..f80d472 100644 --- a/lang/pure.js +++ b/lang/pure.js @@ -1,11 +1,11 @@ 'use strict' -var refractorC = require('./c.js') + module.exports = pure pure.displayName = 'pure' pure.aliases = [] function pure(Prism) { - Prism.register(refractorC) ;(function (Prism) { + // https://agraef.github.io/pure-docs/pure.html#lexical-matters Prism.languages.pure = { comment: [ { @@ -49,7 +49,7 @@ function pure(Prism) { alias: 'builtin' }, // Any combination of operator chars can be an operator - operator: /(?=\b_|[^_])[!"#$%&'*+,\-.\/:<=>?@\\^_`|~\u00a1-\u00bf\u00d7-\u00f7\u20d0-\u2bff]+|\b(?:and|div|mod|not|or)\b/, + operator: /(?:[!"#$%&'*+,\-.\/:<=>?@\\^`|~\u00a1-\u00bf\u00d7-\u00f7\u20d0-\u2bff]|\b_+\b)+|\b(?:and|div|mod|not|or)\b/, // FIXME: How can we prevent | and , to be highlighted as operator when they are used alone? punctuation: /[(){}\[\];,|]/ } diff --git a/lang/purebasic.js b/lang/purebasic.js new file mode 100644 index 0000000..9a4a298 --- /dev/null +++ b/lang/purebasic.js @@ -0,0 +1,72 @@ +'use strict' + +module.exports = purebasic +purebasic.displayName = 'purebasic' +purebasic.aliases = [] +function purebasic(Prism) { + /* +Original Code by Bas Groothedde +!!MANY THANKS!! I never would have made this, regex and me will never be best friends ;) +==> https://codepen.io/ImagineProgramming/details/JYydBy/ +slightly changed to pass all tests +*/ + // PureBasic support, steal stuff from ansi-c + Prism.languages.purebasic = Prism.languages.extend('clike', { + comment: /;.*/, + keyword: /\b(?:declarecdll|declaredll|compilerselect|compilercase|compilerdefault|compilerendselect|compilererror|enableexplicit|disableexplicit|not|and|or|xor|calldebugger|debuglevel|enabledebugger|disabledebugger|restore|read|includepath|includebinary|threaded|runtime|with|endwith|structureunion|endstructureunion|align|newlist|newmap|interface|endinterface|extends|enumeration|endenumeration|swap|foreach|continue|fakereturn|goto|gosub|return|break|module|endmodule|declaremodule|enddeclaremodule|declare|declarec|prototype|prototypec|enableasm|disableasm|dim|redim|data|datasection|enddatasection|to|procedurereturn|debug|default|case|select|endselect|as|import|endimport|importc|compilerif|compilerelse|compilerendif|compilerelseif|end|structure|endstructure|while|wend|for|next|step|if|else|elseif|endif|repeat|until|procedure|proceduredll|procedurec|procedurecdll|endprocedure|protected|shared|static|global|define|includefile|xincludefile|macro|endmacro)\b/i, + function: /\b\w+(?:\.\w+)?\s*(?=\()/, + number: /(?:\$[\da-f]+|\b-?\d*\.?\d+(?:e[+-]?\d+)?)\b/i, + operator: /(?:@\*?|\?|\*)\w+|-[>-]?|\+\+?|!=?|<>?=?|==?|&&?|\|?\||[~^%?*/@]/ + }) + Prism.languages.insertBefore('purebasic', 'keyword', { + tag: /#\w+/, + asm: { + pattern: /(^\s*)!.*/m, + lookbehind: true, + alias: 'tag', + inside: { + comment: /;.*/, + string: { + pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/, + greedy: true + }, + // Anonymous label references, i.e.: jmp @b + 'label-reference-anonymous': { + pattern: /(\s*!\s*j[a-z]+\s+)@[fb]/i, + lookbehind: true, + alias: 'fasm-label' + }, + // Named label reference, i.e.: jne label1 + 'label-reference-addressed': { + pattern: /(\s*!\s*j[a-z]+\s+)[A-Z._?$@][\w.?$@~#]*/i, + lookbehind: true, + alias: 'fasm-label' + }, + function: { + pattern: /^(\s*!\s*)[\da-z]+(?=\s|$)/im, + lookbehind: true + }, + 'function-inline': { + pattern: /(\s*:\s*)[\da-z]+(?=\s)/i, + lookbehind: true, + alias: 'function' + }, + label: { + pattern: /^(\s*!\s*)[A-Za-z._?$@][\w.?$@~#]*(?=:)/m, + lookbehind: true, + alias: 'fasm-label' + }, + keyword: [ + /(?:extern|extern|global)[^;\r\n]*/i, + /(?:CPU|FLOAT|DEFAULT).*/ + ], + register: /\b(?:st\d|[xyz]mm\d\d?|[cdt]r\d|r\d\d?[bwd]?|[er]?[abcd]x|[abcd][hl]|[er]?(?:bp|sp|si|di)|[cdefgs]s|mm\d+)\b/i, + number: /(?:\b|-|(?=\$))(?:0[hx][\da-f]*\.?[\da-f]+(?:p[+-]?\d+)?|\d[\da-f]+[hx]|\$\d[\da-f]*|0[oq][0-7]+|[0-7]+[oq]|0[by][01]+|[01]+[by]|0[dt]\d+|\d*\.?\d+(?:\.?e[+-]?\d+)?[dt]?)\b/i, + operator: /[\[\]*+\-/%<>=&|$!,.:]/ + } + } + }) + delete Prism.languages.purebasic['class-name'] + delete Prism.languages.purebasic['boolean'] + Prism.languages.pbfasm = Prism.languages['purebasic'] +} diff --git a/lang/python.js b/lang/python.js index dbe5fff..6d80ddd 100644 --- a/lang/python.js +++ b/lang/python.js @@ -10,7 +10,7 @@ function python(Prism) { lookbehind: true }, 'string-interpolation': { - pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]+?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i, + pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i, greedy: true, inside: { interpolation: { @@ -33,7 +33,7 @@ function python(Prism) { } }, 'triple-quoted-string': { - pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]+?\1/i, + pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i, greedy: true, alias: 'string' }, diff --git a/lang/q.js b/lang/q.js index 037bc2d..e95b49a 100644 --- a/lang/q.js +++ b/lang/q.js @@ -47,7 +47,7 @@ function q(Prism) { alias: 'function' }, verb: { - pattern: /(?:\B\.\B|\b[01]:|<[=>]?|>=?|[:+\-*%,!?_~=|$&#@^]):?/, + pattern: /(?:\B\.\B|\b[01]:|<[=>]?|>=?|[:+\-*%,!?~=|$&#@^]):?|\b_\b:?/, alias: 'operator' }, punctuation: /[(){}\[\];.]/ diff --git a/lang/qml.js b/lang/qml.js index b2b8d2e..e4b3831 100644 --- a/lang/qml.js +++ b/lang/qml.js @@ -6,7 +6,7 @@ qml.aliases = [] function qml(Prism) { ;(function (Prism) { var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source - var jsComment = /\/\/.*|\/\*(?:(?!\*\/)[\s\S])*\*\//.source + var jsComment = /\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))*\*\//.source var jsExpr = /(?:[^\\()[\]{}"'/]||\/(?![*/])||\(*\)|\[*\]|\{*\}|\\[\s\S])/.source .replace(//g, function () { return jsString diff --git a/lang/racket.js b/lang/racket.js new file mode 100644 index 0000000..2d3407f --- /dev/null +++ b/lang/racket.js @@ -0,0 +1,75 @@ +'use strict' +var refractorScheme = require('./scheme.js') +module.exports = racket +racket.displayName = 'racket' +racket.aliases = ['rkt'] +function racket(Prism) { + Prism.register(refractorScheme) + Prism.languages.racket = Prism.languages.extend('scheme', { + 'lambda-parameter': { + // the racket lambda syntax is a lot more complex, so we won't even attempt to capture it. + // this will just prevent false positives of the `function` pattern + pattern: /(\(lambda\s+\()[^()'\s]+/, + lookbehind: true + } + }) // Add brackets to racket + // The basic idea here is to go through all pattens of Scheme and replace all occurrences of "(" with the union of "(" + // and "["; Similar for ")". This is a bit tricky because "(" can be escaped or inside a character set. Both cases + // have to be handled differently and, of course, we don't want to destroy groups, so we can only replace literal "(" + // and ")". + // To do this, we use a regular expression which will parse any JS regular expression. It works because regexes are + // matches from left to right and already matched text cannot be matched again. We use this to first capture all + // escaped characters (not really, we don't get escape sequences but we don't need them). Because we already captured + // all escaped characters, we know that any "[" character is the start of a character set, so we match that character + // set whole. + // With the regex parsed, we only have to replace all escaped "(" (they cannot be unescaped outside of character sets) + // with /[([]/ and replace all "(" inside character sets. + // Note: This method does not work for "(" that are escaped like this /\x28/ or this /\u0028/. + Prism.languages.DFS(Prism.languages.racket, function (key, value) { + if (Prism.util.type(value) === 'RegExp') { + var source = value.source.replace( + /\\(.)|\[\^?((?:\\.|[^\\\]])*)\]/g, + function (m, g1, g2) { + if (g1) { + if (g1 === '(') { + // replace all '(' characters outside character sets + return '[([]' + } + if (g1 === ')') { + // replace all ')' characters outside character sets + return '[)\\]]' + } + } + if (g2) { + var prefix = m[1] === '^' ? '[^' : '[' + return ( + prefix + + g2.replace(/\\(.)|[()]/g, function (m, g1) { + if (m === '(' || g1 === '(') { + // replace all '(' characters inside character sets + return '([' + } + if (m === ')' || g1 === ')') { + // replace all ')' characters inside character sets + return ')\\]' + } + return m + }) + + ']' + ) + } + return m + } + ) + this[key] = RegExp(source, value.flags) + } + }) + Prism.languages.insertBefore('racket', 'string', { + lang: { + pattern: /^#lang.+/m, + greedy: true, + alias: 'keyword' + } + }) + Prism.languages.rkt = Prism.languages.racket +} diff --git a/lang/regex.js b/lang/regex.js index 68f9c61..3c64524 100644 --- a/lang/regex.js +++ b/lang/regex.js @@ -10,7 +10,14 @@ function regex(Prism) { alias: 'escape' } var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/ - var charClass = /\\[wsd]|\.|\\p{[^{}]+}/i + var charClass = { + pattern: /\.|\\[wsd]|\\p{[^{}]+}/i, + alias: 'class-name' + } + var charClassWithoutDot = { + pattern: /\\[wsd]|\\p{[^{}]+}/i, + alias: 'class-name' + } var rangeChar = '(?:[^\\\\-]|' + escape.source + ')' var range = RegExp(rangeChar + '-' + rangeChar) // the name of a capturing group var groupName = { @@ -18,15 +25,6 @@ function regex(Prism) { lookbehind: true, alias: 'variable' } - var backreference = [ - /\\(?![123][0-7]{2})[1-9]/, // a backreference which is not an octal escape - { - pattern: /\\k<[^<>']+>/, - inside: { - 'group-name': groupName - } - } - ] Prism.languages.regex = { charset: { pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/, @@ -34,26 +32,48 @@ function regex(Prism) { inside: { 'charset-negation': { pattern: /(^\[)\^/, - lookbehind: true + lookbehind: true, + alias: 'operator' + }, + 'charset-punctuation': { + pattern: /^\[|\]$/, + alias: 'punctuation' }, - 'charset-punctuation': /^\[|\]$/, range: { pattern: range, inside: { escape: escape, - 'range-punctuation': /-/ + 'range-punctuation': { + pattern: /-/, + alias: 'operator' + } } }, 'special-escape': specialEscape, - charclass: charClass, - backreference: backreference, + charclass: charClassWithoutDot, escape: escape } }, 'special-escape': specialEscape, charclass: charClass, - backreference: backreference, - anchor: /[$^]|\\[ABbGZz]/, + backreference: [ + { + // a backreference which is not an octal escape + pattern: /\\(?![123][0-7]{2})[1-9]/, + alias: 'keyword' + }, + { + pattern: /\\k<[^<>']+>/, + alias: 'keyword', + inside: { + 'group-name': groupName + } + } + ], + anchor: { + pattern: /[$^]|\\[ABbGZz]/, + alias: 'function' + }, escape: escape, group: [ { @@ -61,14 +81,24 @@ function regex(Prism) { // https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference?view=netframework-4.7.2#grouping-constructs // (), (?), (?'name'), (?>), (?:), (?=), (?!), (?<=), (?']+>|'[^<>']+'|[>:]|]?|>[=>]?|[&|^~]|\b(?:or|and|not|with|at)\b/, punctuation: /[{}[\];(),.:]/ } + Prism.languages.rpy = Prism.languages.renpy } diff --git a/lang/rip.js b/lang/rip.js index 317b6ee..f464f08 100644 --- a/lang/rip.js +++ b/lang/rip.js @@ -14,7 +14,7 @@ function rip(Prism) { datetime: /\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\b/, character: /\B`[^\s`'",.:;#\/\\()<>\[\]{}]\b/, regex: { - pattern: /(^|[^/])\/(?!\/)(?:\[.+?]|\\.|[^/\\\r\n])+\/(?=\s*(?:$|[\r\n,.;})]))/, + pattern: /(^|[^/])\/(?!\/)(?:\[[^\n\r\]]*\]|\\.|[^/\\\r\n\[])+\/(?=\s*(?:$|[\r\n,.;})]))/, lookbehind: true, greedy: true }, @@ -23,7 +23,7 @@ function rip(Prism) { pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, greedy: true }, - number: /[+-]?(?:(?:\d+\.\d+)|(?:\d+))/, + number: /[+-]?\b(?:\d+\.\d+|\d+)\b/, punctuation: /(?:\.{2,3})|[`,.:;=\/\\()<>\[\]{}]/, reference: /[^\d\s`'",.:;#\/\\()<>\[\]{}][^\s`'",.:;#\/\\()<>\[\]{}]*/ } diff --git a/lang/robotframework.js b/lang/robotframework.js index 7bfa8f3..dc31783 100644 --- a/lang/robotframework.js +++ b/lang/robotframework.js @@ -50,7 +50,7 @@ function robotframework(Prism) { } } var docTag = { - pattern: /(\[Documentation\](?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/, + pattern: /(\[Documentation\](?: |\t)[ \t]*)(?![ \t]|#)(?:.|(?:\r\n?|\n)[ \t]*\.{3})+/, lookbehind: true, alias: 'string' } @@ -72,7 +72,7 @@ function robotframework(Prism) { Prism.languages['robotframework'] = { settings: createSection('Settings', { documentation: { - pattern: /([\r\n] ?Documentation(?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/, + pattern: /([\r\n] ?Documentation(?: |\t)[ \t]*)(?![ \t]|#)(?:.|(?:\r\n?|\n)[ \t]*\.{3})+/, lookbehind: true, alias: 'string' }, diff --git a/lang/ruby.js b/lang/ruby.js index 2712798..1357973 100644 --- a/lang/ruby.js +++ b/lang/ruby.js @@ -42,36 +42,19 @@ function ruby(Prism) { Prism.languages.insertBefore('ruby', 'keyword', { regex: [ { - pattern: /%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - // Here we need to specifically allow interpolation - pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/, + pattern: RegExp( + /%r/.source + + '(?:' + + [ + /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/ + .source, + /\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/.source, // Here we need to specifically allow interpolation + /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/.source, + /\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/.source, + /<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/.source + ].join('|') + + ')' + ), greedy: true, inside: { interpolation: interpolation @@ -103,36 +86,18 @@ function ruby(Prism) { }) Prism.languages.ruby.string = [ { - pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - // Here we need to specifically allow interpolation - pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/, - greedy: true, - inside: { - interpolation: interpolation - } - }, - { - pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/, + pattern: RegExp( + /%[qQiIwWxs]?/.source + + '(?:' + + [ + /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, + /\((?:[^()\\]|\\[\s\S])*\)/.source, // Here we need to specifically allow interpolation + /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source, + /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source, + /<(?:[^<>\\]|\\[\s\S])*>/.source + ].join('|') + + ')' + ), greedy: true, inside: { interpolation: interpolation diff --git a/lang/rust.js b/lang/rust.js index 7bb4d75..722101f 100644 --- a/lang/rust.js +++ b/lang/rust.js @@ -4,66 +4,125 @@ module.exports = rust rust.displayName = 'rust' rust.aliases = [] function rust(Prism) { - /* TODO -Add support for Markdown notation inside doc comments -Add support for nested block comments... -Match closure params even when not followed by dash or brace -Add better support for macro definition -*/ - Prism.languages.rust = { - comment: [ - { - pattern: /(^|[^\\])\/\*[\s\S]*?\*\//, - lookbehind: true - }, - { - pattern: /(^|[^\\:])\/\/.*/, - lookbehind: true - } - ], - string: [ - { - pattern: /b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/, + ;(function (Prism) { + var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|)*\*\//.source + for (var i = 0; i < 2; i++) { + // support 4 levels of nested comments + multilineComment = multilineComment.replace(//g, function () { + return multilineComment + }) + } + multilineComment = multilineComment.replace(//g, function () { + return /[^\s\S]/.source + }) + Prism.languages.rust = { + comment: [ + { + pattern: RegExp(/(^|[^\\])/.source + multilineComment), + lookbehind: true, + greedy: true + }, + { + pattern: /(^|[^\\:])\/\/.*/, + lookbehind: true, + greedy: true + } + ], + string: { + pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/, greedy: true }, - { - pattern: /b?"(?:\\.|[^\\\r\n"])*"/, - greedy: true - } - ], - char: { - pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/, - alias: 'string' - }, - 'lifetime-annotation': { - pattern: /'[^\s>']+/, - alias: 'symbol' - }, - keyword: /\b(?:abstract|alignof|as|async|await|be|box|break|const|continue|crate|do|dyn|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|Self|struct|super|true|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/, - attribute: { - pattern: /#!?\[.+?\]/, - greedy: true, - alias: 'attr-name' - }, - function: [ - /\w+(?=\s*\()/, // Macros can use parens or brackets - /\w+!(?=\s*\(|\[)/ - ], - 'macro-rules': { - pattern: /\w+!/, - alias: 'function' - }, - // Hex, oct, bin, dec numbers with visual separators and type suffix - number: /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/, - // Closure params should not be confused with bitwise OR | - 'closure-params': { - pattern: /\|[^|]*\|(?=\s*[{-])/, - inside: { - punctuation: /[|:,]/, - operator: /[&*]/ - } - }, - punctuation: /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/, - operator: /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<>?=?|[@?]/ - } + char: { + pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/, + greedy: true, + alias: 'string' + }, + attribute: { + pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/, + greedy: true, + alias: 'attr-name', + inside: { + string: null // see below + } + }, + // Closure params should not be confused with bitwise OR | + 'closure-params': { + pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/, + lookbehind: true, + greedy: true, + inside: { + 'closure-punctuation': { + pattern: /^\||\|$/, + alias: 'punctuation' + }, + rest: null // see below + } + }, + 'lifetime-annotation': { + pattern: /'\w+/, + alias: 'symbol' + }, + 'fragment-specifier': { + pattern: /(\$\w+:)[a-z]+/, + lookbehind: true, + alias: 'punctuation' + }, + variable: /\$\w+/, + 'function-definition': { + pattern: /(\bfn\s+)\w+/, + lookbehind: true, + alias: 'function' + }, + 'type-definition': { + pattern: /(\b(?:enum|struct|union)\s+)\w+/, + lookbehind: true, + alias: 'class-name' + }, + 'module-declaration': [ + { + pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/, + lookbehind: true, + alias: 'namespace' + }, + { + pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/, + lookbehind: true, + alias: 'namespace', + inside: { + punctuation: /::/ + } + } + ], + keyword: [ + // https://github.com/rust-lang/reference/blob/master/src/keywords.md + /\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/, // primitives and str + // https://doc.rust-lang.org/stable/rust-by-example/primitives.html + /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/ + ], + // functions can technically start with an upper-case letter, but this will introduce a lot of false positives + // and Rust's naming conventions recommend snake_case anyway. + // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html + function: /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/, + macro: { + pattern: /\w+!/, + alias: 'property' + }, + constant: /\b[A-Z_][A-Z_\d]+\b/, + 'class-name': /\b[A-Z]\w*\b/, + namespace: { + pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/, + inside: { + punctuation: /::/ + } + }, + // Hex, oct, bin, dec numbers with visual separators and type suffix + number: /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/, + boolean: /\b(?:false|true)\b/, + punctuation: /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/, + operator: /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<>?=?|[@?]/ + } + Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust + Prism.languages.rust['attribute'].inside['string'] = + Prism.languages.rust['string'] + })(Prism) } diff --git a/lang/sas.js b/lang/sas.js index e414bfd..7769bf6 100644 --- a/lang/sas.js +++ b/lang/sas.js @@ -11,6 +11,14 @@ function sas(Prism) { pattern: RegExp(stringPattern + '[bx]'), alias: 'number' } + var macroVariable = { + pattern: /&[a-z_][a-z_0-9]*/i + } + var macroKeyword = { + pattern: /((?:^|\s|=|\())%(?:ABORT|BY|CMS|COPY|DISPLAY|DO|ELSE|END|EVAL|GLOBAL|GO|GOTO|IF|INC|INCLUDE|INDEX|INPUT|KTRIM|LENGTH|LET|LIST|LOCAL|PUT|QKTRIM|QSCAN|QSUBSTR|QSYSFUNC|QUPCASE|RETURN|RUN|SCAN|SUBSTR|SUPERQ|SYMDEL|SYMGLOBL|SYMLOCAL|SYMEXIST|SYSCALL|SYSEVALF|SYSEXEC|SYSFUNC|SYSGET|SYSRPUT|THEN|TO|TSO|UNQUOTE|UNTIL|UPCASE|WHILE|WINDOW)\b/i, + lookbehind: true, + alias: 'keyword' + } var step = { pattern: /(^|\s+)(?:proc\s+\w+|quit|run|data(?!\=))\b/i, alias: 'keyword', @@ -39,10 +47,7 @@ function sas(Prism) { lookbehind: true }, operator: /=/, - 'macro-variable': { - pattern: /&[^\.]*\./i, - alias: 'string' - }, + 'macro-variable': macroVariable, arg: { pattern: /[A-Z]+/i, alias: 'keyword' @@ -107,10 +112,10 @@ function sas(Prism) { pattern: /(?:action)/i, alias: 'keyword' }, + comment: comment, function: func, 'arg-value': args['arg-value'], operator: args.operator, - comment: comment, argument: args.arg, number: number, 'numeric-constant': numericConstant, @@ -164,9 +169,10 @@ function sas(Prism) { } }, 'proc-groovy': { - pattern: /(^proc\s+groovy(?:\s+[\w|=]+)?;)(?:\s*submit)[\s\S]+?(?=^(?:proc\s+\w+|quit|run|data);|(?![\s\S]))/im, + pattern: /(^proc\s+groovy(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|quit|run|data);|(?![\s\S]))/im, lookbehind: true, inside: { + comment: comment, groovy: { pattern: RegExp( /(^[ \t]*submit(?:\s+(?:load|parseonly|norun))?)(?:|[^"'])+?(?=endsubmit;)/.source.replace( @@ -181,6 +187,7 @@ function sas(Prism) { alias: 'language-groovy', inside: Prism.languages.groovy }, + keyword: keywords, 'submit-statement': submitStatement, 'global-statements': globalStatements, number: number, @@ -190,9 +197,10 @@ function sas(Prism) { } }, 'proc-lua': { - pattern: /(^proc\s+lua(?:\s+[\w|=]+)?;)(?:\s*submit)[\s\S]+?(?=^(?:proc\s+\w+|quit|run|data);|(?![\s\S]))/im, + pattern: /(^proc\s+lua(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|quit|run|data);|(?![\s\S]))/im, lookbehind: true, inside: { + comment: comment, lua: { pattern: RegExp( /(^[ \t]*submit(?:\s+(?:load|parseonly|norun))?)(?:|[^"'])+?(?=endsubmit;)/.source.replace( @@ -207,6 +215,7 @@ function sas(Prism) { alias: 'language-lua', inside: Prism.languages.lua }, + keyword: keywords, 'submit-statement': submitStatement, 'global-statements': globalStatements, number: number, @@ -219,6 +228,7 @@ function sas(Prism) { pattern: /(^proc\s+cas(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|quit|data);|(?![\s\S]))/im, lookbehind: true, inside: { + comment: comment, 'statement-var': { pattern: /((?:^|\s)=?)saveresult\s+[^;]+/im, lookbehind: true, @@ -241,7 +251,6 @@ function sas(Prism) { step: step, keyword: keywords, function: func, - comment: comment, format: format, altformat: altformat, 'global-statements': globalStatements, @@ -265,10 +274,23 @@ function sas(Prism) { inside: args }, /*Special keywords within macros*/ - 'macro-keyword': { - pattern: /((?:^|\s)=?)%(?:ABORT|BQUOTE|BY|CMS|COPY|DISPLAY|DO|ELSE|END|EVAL|GLOBAL|GO|GOTO|IF|INC|INCLUDE|INDEX|INPUT|KTRIM|LENGTH|LET|LIST|LOCAL|NRBQUOTE|NRQUOTE|NRSTR|PUT|QKTRIM|QSCAN|QSUBSTR|QSYSFUNC|QUOTE|QUPCASE|RETURN|RUN|SCAN|STR|SUBSTR|SUPERQ|SYMDEL|SYMGLOBL|SYMLOCAL|SYMEXIST|SYSCALL|SYSEVALF|SYSEXEC|SYSFUNC|SYSGET|SYSRPUT|THEN|TO|TSO|UNQUOTE|UNTIL|UPCASE|WHILE|WINDOW)\b/i, + 'macro-keyword': macroKeyword, + 'macro-variable': macroVariable, + 'macro-string-functions': { + pattern: /((?:^|\s|=))%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)\(.*?(?:[^%]\))/i, lookbehind: true, - alias: 'keyword' + inside: { + function: { + pattern: /%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)/i, + alias: 'keyword' + }, + 'macro-keyword': macroKeyword, + 'macro-variable': macroVariable, + 'escaped-char': { + pattern: /%['"()<>=¬^~;,#]/i + }, + punctuation: punctuation + } }, 'macro-declaration': { pattern: /^%macro[^;]+(?=;)/im, diff --git a/lang/scheme.js b/lang/scheme.js index 5a0e7d0..0c2753e 100644 --- a/lang/scheme.js +++ b/lang/scheme.js @@ -7,32 +7,66 @@ function scheme(Prism) { Prism.languages.scheme = { comment: /;.*/, string: { - pattern: /"(?:[^"\\]|\\.)*"|'[^()#'\s]+/, + pattern: /"(?:[^"\\]|\\.)*"/, + greedy: true + }, + symbol: { + pattern: /'[^()#'\s]+/, greedy: true }, character: { - pattern: /#\\(?:[ux][a-fA-F\d]+|[a-zA-Z]+|\S)/, + pattern: /#\\(?:[ux][a-fA-F\d]+|[-a-zA-Z]+|\S)/, + greedy: true, alias: 'string' }, + 'lambda-parameter': [ + // https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30 + { + pattern: /(\(lambda\s+)[^()'\s]+/, + lookbehind: true + }, + { + pattern: /(\(lambda\s+\()[^()']+/, + lookbehind: true + } + ], keyword: { - pattern: /(\()(?:define(?:-syntax|-library|-values)?|(?:case-)?lambda|let(?:\*|rec)?(?:-values)?|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-rules)(?=[()\s])/, + pattern: /(\()(?:define(?:-library|-macro|-syntax|-values)?|defmacro|(?:case-)?lambda|let(?:(?:\*|rec)?(?:-values)?|-syntax|rec-syntax)|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-(?:case|rules))(?=[()\s]|$)/, lookbehind: true }, builtin: { - pattern: /(\()(?:(?:cons|car|cdr|list|call-with-current-continuation|call\/cc|append|abs|apply|eval)\b|null\?|pair\?|boolean\?|eof-object\?|char\?|procedure\?|number\?|port\?|string\?|vector\?|symbol\?|bytevector\?)(?=[()\s])/, + pattern: /(\()(?:(?:cons|car|cdr|list|call-with-current-continuation|call\/cc|append|abs|apply|eval)\b|null\?|pair\?|boolean\?|eof-object\?|char\?|procedure\?|number\?|port\?|string\?|vector\?|symbol\?|bytevector\?)(?=[()\s]|$)/, lookbehind: true }, number: { - pattern: /([\s()])[-+]?(?:\d+\/\d+|\d*\.?\d+(?:\s*[-+]\s*\d*\.?\d+i)?)\b/, + // This pattern (apart from the lookarounds) works like this: + // + // Decimal numbers + // := \d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+ + // := (?:[+-]i)?|i + // := (?:#d(?:#[ei])?|#[ei](?:#d)?)? + // := [+-]? + // + // Binary, octal, and hexadecimal numbers + // := [\da-fA-F]+(?:\/[\da-fA-F]+)? + // := (?:[+-]i)?|i + // := #[box](?:#[ei])?|#[ei](?:#[box])? + // := [+-]? + // + // := | + pattern: /(^|[\s()])(?:(?:#d(?:#[ei])?|#[ei](?:#d)?)?[+-]?(?:(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)(?:[+-](?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)?|(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)|(?:#[box](?:#[ei])?|#[ei](?:#[box])?)[+-]?(?:[\da-fA-F]+(?:\/[\da-fA-F]+)?(?:[+-][\da-fA-F]+(?:\/[\da-fA-F]+)?i)?|[\da-fA-F]+(?:\/[\da-fA-F]+)?i))(?=[()\s]|$)/, + lookbehind: true + }, + boolean: { + pattern: /(^|[\s()])#[ft](?=[()\s]|$)/, lookbehind: true }, - boolean: /#[tf]/, operator: { - pattern: /(\()(?:[-+*%\/]|[<>]=?|=>?)(?=\s|$)/, + pattern: /(\()(?:[-+*%\/]|[<>]=?|=>?)(?=[()\s]|$)/, lookbehind: true }, function: { - pattern: /(\()[^()'\s]+(?=[()\s)]|$)/, + pattern: /(\()[^()'\s]+(?=[()\s]|$)/, lookbehind: true }, punctuation: /[()']/ diff --git a/lang/shell-session.js b/lang/shell-session.js index 7a3f961..83d88f8 100644 --- a/lang/shell-session.js +++ b/lang/shell-session.js @@ -1,9 +1,10 @@ 'use strict' - +var refractorBash = require('./bash.js') module.exports = shellSession shellSession.displayName = 'shellSession' shellSession.aliases = [] function shellSession(Prism) { + Prism.register(refractorBash) ;(function (Prism) { // CAREFUL! // The following patterns are concatenated, so the group referenced by a back reference is non-obvious! @@ -12,9 +13,9 @@ function shellSession(Prism) { // 1 capturing group /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/.source, // here doc // 1 capturing group - /<<-?\s*(\w+?)\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\2/.source, // here doc quoted + /<<-?\s*(\w+?)[ \t]*(?!.)[\s\S]*?[\r\n]\2/.source, // here doc quoted // 2 capturing group - /<<-?\s*(["'])(\w+)\3\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\4/.source + /<<-?\s*(["'])(\w+)\3[ \t]*(?!.)[\s\S]*?[\r\n]\4/.source ].join('|') Prism.languages['shell-session'] = { info: { @@ -54,7 +55,7 @@ function shellSession(Prism) { } } }, - output: /.(?:.*(?:\r\n?|\n|.$))*/ + output: /.(?:.*(?:[\r\n]|.$))*/ } })(Prism) } diff --git a/lang/smali.js b/lang/smali.js new file mode 100644 index 0000000..7c08f2a --- /dev/null +++ b/lang/smali.js @@ -0,0 +1,87 @@ +'use strict' + +module.exports = smali +smali.displayName = 'smali' +smali.aliases = [] +function smali(Prism) { + // Test files for the parser itself: + // https://github.com/JesusFreke/smali/tree/master/smali/src/test/resources/LexerTest + Prism.languages.smali = { + comment: /#.*/, + string: { + pattern: /"(?:[^\r\n\\"]|\\.)*"|'(?:[^\r\n\\']|\\(?:.|u[\da-fA-F]{4}))'/, + greedy: true + }, + 'class-name': { + pattern: /L(?:(?:\w+|`[^`\r\n]*`)\/)*(?:[\w$]+|`[^`\r\n]*`)(?=\s*;)/, + inside: { + 'class-name': { + pattern: /(^L|\/)(?:[\w$]+|`[^`\r\n]*`)$/, + lookbehind: true + }, + namespace: { + pattern: /^(L)(?:(?:\w+|`[^`\r\n]*`)\/)+/, + lookbehind: true, + inside: { + punctuation: /\// + } + }, + builtin: /^L/ + } + }, + builtin: [ + { + // Reference: https://github.com/JesusFreke/smali/wiki/TypesMethodsAndFields#types + pattern: /([();\[])[BCDFIJSVZ]+/, + lookbehind: true + }, + { + // e.g. .field mWifiOnUid:I + pattern: /([\w$>]:)[BCDFIJSVZ]/, + lookbehind: true + } + ], + keyword: [ + { + pattern: /(\.end\s+)[\w-]+/, + lookbehind: true + }, + { + pattern: /(^|[^\w.-])\.(?!\d)[\w-]+/, + lookbehind: true + }, + { + pattern: /(^|[^\w.-])(?:abstract|annotation|bridge|constructor|enum|final|interface|private|protected|public|runtime|static|synthetic|system|transient)(?![\w.-])/, + lookbehind: true + } + ], + function: { + pattern: /(^|[^\w.-])(?:\w+|<[\w$-]+>)(?=\()/, + lookbehind: true + }, + field: { + pattern: /[\w$]+(?=:)/, + alias: 'variable' + }, + register: { + pattern: /(^|[^\w.-])[vp]\d(?![\w.-])/, + lookbehind: true, + alias: 'variable' + }, + boolean: { + pattern: /(^|[^\w.-])(?:true|false)(?![\w.-])/, + lookbehind: true + }, + number: { + pattern: /(^|[^/\w.-])-?(?:NAN|INFINITY|0x(?:[\dA-F]+(?:\.[\dA-F]*)?|\.[\dA-F]+)(?:p[+-]?[\dA-F]+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)[dflst]?(?![\w.-])/i, + lookbehind: true + }, + label: { + pattern: /(:)\w+/, + lookbehind: true, + alias: 'property' + }, + operator: /->|\.\.|[\[=]/, + punctuation: /[{}(),;:]/ + } +} diff --git a/lang/solidity.js b/lang/solidity.js index e7be7d2..527e64b 100644 --- a/lang/solidity.js +++ b/lang/solidity.js @@ -2,7 +2,7 @@ module.exports = solidity solidity.displayName = 'solidity' -solidity.aliases = [] +solidity.aliases = ['sol'] function solidity(Prism) { Prism.languages.solidity = Prism.languages.extend('clike', { 'class-name': { @@ -22,4 +22,5 @@ function solidity(Prism) { alias: 'number' } }) + Prism.languages.sol = Prism.languages.solidity } diff --git a/lang/sql.js b/lang/sql.js index 1f73ae3..3ab2c00 100644 --- a/lang/sql.js +++ b/lang/sql.js @@ -23,7 +23,7 @@ function sql(Prism) { }, function: /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too? - keyword: /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURNS?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i, + keyword: /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:S|ING)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i, boolean: /\b(?:TRUE|FALSE|NULL)\b/i, number: /\b0x[\da-f]+\b|\b\d+\.?\d*|\B\.\d+\b/i, operator: /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i, diff --git a/lang/stylus.js b/lang/stylus.js index 94417a0..f51a6e3 100644 --- a/lang/stylus.js +++ b/lang/stylus.js @@ -5,8 +5,23 @@ stylus.displayName = 'stylus' stylus.aliases = [] function stylus(Prism) { ;(function (Prism) { + var unit = { + pattern: /(\b\d+)(?:%|[a-z]+)/, + lookbehind: true + } // 123 -123 .123 -.123 12.3 -12.3 + var number = { + pattern: /(^|[^\w.-])-?\d*\.?\d+/, + lookbehind: true + } var inside = { - url: /url\((["']?).*?\1\)/i, + comment: { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true + }, + url: { + pattern: /url\((["']?).*?\1\)/i, + greedy: true + }, string: { pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/, greedy: true @@ -21,13 +36,27 @@ function stylus(Prism) { lookbehind: true }, hexcode: /#[\da-f]{3,6}/i, - number: /\b\d+(?:\.\d+)?%?/, + color: [ + /\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i, + { + pattern: /\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i, + inside: { + unit: unit, + number: number, + function: /[\w-]+(?=\()/, + punctuation: /[(),]/ + } + } + ], + entity: /\\[\da-f]{1,8}/i, + unit: unit, boolean: /\b(?:true|false)\b/, operator: [ // We want non-word chars around "-" because it is // accepted in property names. - /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.+|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/ + /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/ ], + number: number, punctuation: /[{}()\[\];:,]/ } inside['interpolation'] = { @@ -49,10 +78,6 @@ function stylus(Prism) { } } Prism.languages.stylus = { - comment: { - pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, - lookbehind: true - }, 'atrule-declaration': { pattern: /(^\s*)@.+/m, lookbehind: true, @@ -100,11 +125,17 @@ function stylus(Prism) { lookbehind: true, inside: { interpolation: inside.interpolation, + comment: inside.comment, punctuation: /[{},]/ } }, func: inside.func, string: inside.string, + comment: { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true, + greedy: true + }, interpolation: inside.interpolation, punctuation: /[{}()\[\];:.]/ } diff --git a/lang/t4-cs.js b/lang/t4-cs.js index 21984dc..e4e6c98 100644 --- a/lang/t4-cs.js +++ b/lang/t4-cs.js @@ -1,10 +1,12 @@ 'use strict' var refractorT4Templating = require('./t4-templating.js') +var refractorCsharp = require('./csharp.js') module.exports = t4Cs t4Cs.displayName = 't4Cs' t4Cs.aliases = [] function t4Cs(Prism) { Prism.register(refractorT4Templating) + Prism.register(refractorCsharp) Prism.languages.t4 = Prism.languages['t4-cs'] = Prism.languages[ 't4-templating' ].createT4('csharp') diff --git a/lang/t4-vb.js b/lang/t4-vb.js index 8ffeda4..adabf78 100644 --- a/lang/t4-vb.js +++ b/lang/t4-vb.js @@ -1,11 +1,11 @@ 'use strict' var refractorT4Templating = require('./t4-templating.js') +var refractorVbnet = require('./vbnet.js') module.exports = t4Vb t4Vb.displayName = 't4Vb' t4Vb.aliases = [] function t4Vb(Prism) { Prism.register(refractorT4Templating) - Prism.languages['t4-vb'] = Prism.languages['t4-templating'].createT4( - 'visual-basic' - ) + Prism.register(refractorVbnet) + Prism.languages['t4-vb'] = Prism.languages['t4-templating'].createT4('vbnet') } diff --git a/lang/tap.js b/lang/tap.js index 54793a8..2c9f3f6 100644 --- a/lang/tap.js +++ b/lang/tap.js @@ -1,9 +1,10 @@ 'use strict' - +var refractorYaml = require('./yaml.js') module.exports = tap tap.displayName = 'tap' tap.aliases = [] function tap(Prism) { + Prism.register(refractorYaml) Prism.languages.tap = { fail: /not ok[^#{\n\r]*/, pass: /ok[^#{\n\r]*/, diff --git a/lang/textile.js b/lang/textile.js index 716e227..1fd3758 100644 --- a/lang/textile.js +++ b/lang/textile.js @@ -7,7 +7,25 @@ function textile(Prism) { ;(function (Prism) { // We don't allow for pipes inside parentheses // to not break table pattern |(. foo |). bar | - var modifierRegex = /(?:\([^|)]+\)|\[[^\]]+\]|\{[^}]+\})+/.source + var modifierRegex = /\([^|()\n]+\)|\[[^\]\n]+\]|\{[^}\n]+\}/.source // Opening and closing parentheses which are not a modifier + // This pattern is necessary to prevent exponential backtracking + var parenthesesRegex = /\)|\((?![^|()\n]+\))/.source + /** + * @param {string} source + * @param {string} [flags] + */ + function withModifier(source, flags) { + return RegExp( + source + .replace(//g, function () { + return '(?:' + modifierRegex + ')' + }) + .replace(//g, function () { + return '(?:' + parenthesesRegex + ')' + }), + flags || '' + ) + } var modifierTokens = { css: { pattern: /\{[^}]+\}/, @@ -35,11 +53,11 @@ function textile(Prism) { inside: { // h1. Header 1 'block-tag': { - pattern: RegExp('^[a-z]\\w*(?:' + modifierRegex + '|[<>=()])*\\.'), + pattern: withModifier(/^[a-z]\w*(?:||[<>=])*\./.source), inside: { modifier: { - pattern: RegExp( - '(^[a-z]\\w*)(?:' + modifierRegex + '|[<>=()])+(?=\\.)' + pattern: withModifier( + /(^[a-z]\w*)(?:||[<>=])+(?=\.)/.source ), lookbehind: true, inside: modifierTokens @@ -51,10 +69,10 @@ function textile(Prism) { // # List item // * List item list: { - pattern: RegExp('^[*#]+(?:' + modifierRegex + ')?\\s+.+', 'm'), + pattern: withModifier(/^[*#]+*\s+.+/.source, 'm'), inside: { modifier: { - pattern: RegExp('(^[*#]+)' + modifierRegex), + pattern: withModifier(/(^[*#]+)+/.source), lookbehind: true, inside: modifierTokens }, @@ -65,22 +83,18 @@ function textile(Prism) { table: { // Modifiers can be applied to the row: {color:red}.|1|2|3| // or the cell: |{color:red}.1|2|3| - pattern: RegExp( - '^(?:(?:' + - modifierRegex + - '|[<>=()^~])+\\.\\s*)?(?:\\|(?:(?:' + - modifierRegex + - '|[<>=()^~_]|[\\\\/]\\d+)+\\.)?[^|]*)+\\|', + pattern: withModifier( + /^(?:(?:||[<>=^~])+\.\s*)?(?:\|(?:(?:||[<>=^~_]|[\\/]\d+)+\.)?[^|]*)+\|/ + .source, 'm' ), inside: { modifier: { // Modifiers for rows after the first one are // preceded by a pipe and a line feed - pattern: RegExp( - '(^|\\|(?:\\r?\\n|\\r)?)(?:' + - modifierRegex + - '|[<>=()^~_]|[\\\\/]\\d+)+(?=\\.)' + pattern: withModifier( + /(^|\|(?:\r?\n|\r)?)(?:||[<>=^~_]|[\\/]\d+)+(?=\.)/ + .source ), lookbehind: true, inside: modifierTokens @@ -89,55 +103,53 @@ function textile(Prism) { } }, inline: { - pattern: RegExp( - '(\\*\\*|__|\\?\\?|[*_%@+\\-^~])(?:' + modifierRegex + ')?.+?\\1' + pattern: withModifier( + /(^|[^a-zA-Z\d])(\*\*|__|\?\?|[*_%@+\-^~])*.+?\2(?![a-zA-Z\d])/ + .source ), + lookbehind: true, inside: { // Note: superscripts and subscripts are not handled specifically // *bold*, **bold** bold: { - pattern: RegExp( - '(^(\\*\\*?)(?:' + modifierRegex + ')?).+?(?=\\2)' - ), + pattern: withModifier(/(^(\*\*?)*).+?(?=\2)/.source), lookbehind: true }, // _italic_, __italic__ italic: { - pattern: RegExp('(^(__?)(?:' + modifierRegex + ')?).+?(?=\\2)'), + pattern: withModifier(/(^(__?)*).+?(?=\2)/.source), lookbehind: true }, // ??cite?? cite: { - pattern: RegExp( - '(^\\?\\?(?:' + modifierRegex + ')?).+?(?=\\?\\?)' - ), + pattern: withModifier(/(^\?\?*).+?(?=\?\?)/.source), lookbehind: true, alias: 'string' }, // @code@ code: { - pattern: RegExp('(^@(?:' + modifierRegex + ')?).+?(?=@)'), + pattern: withModifier(/(^@*).+?(?=@)/.source), lookbehind: true, alias: 'keyword' }, // +inserted+ inserted: { - pattern: RegExp('(^\\+(?:' + modifierRegex + ')?).+?(?=\\+)'), + pattern: withModifier(/(^\+*).+?(?=\+)/.source), lookbehind: true }, // -deleted- deleted: { - pattern: RegExp('(^-(?:' + modifierRegex + ')?).+?(?=-)'), + pattern: withModifier(/(^-*).+?(?=-)/.source), lookbehind: true }, // %span% span: { - pattern: RegExp('(^%(?:' + modifierRegex + ')?).+?(?=%)'), + pattern: withModifier(/(^%*).+?(?=%)/.source), lookbehind: true }, modifier: { - pattern: RegExp( - '(^\\*\\*|__|\\?\\?|[*_%@+\\-^~])' + modifierRegex + pattern: withModifier( + /(^\*\*|__|\?\?|[*_%@+\-^~])+/.source ), lookbehind: true, inside: modifierTokens @@ -163,16 +175,16 @@ function textile(Prism) { // "text":http://example.com // "text":link-ref link: { - pattern: RegExp( - '"(?:' + modifierRegex + ')?[^"]+":.+?(?=[^\\w/]?(?:\\s|$))' + pattern: withModifier( + /"*[^"]+":.+?(?=[^\w/]?(?:\s|$))/.source ), inside: { text: { - pattern: RegExp('(^"(?:' + modifierRegex + ')?)[^"]+(?=")'), + pattern: withModifier(/(^"*)[^"]+(?=")/.source), lookbehind: true }, modifier: { - pattern: RegExp('(^")' + modifierRegex), + pattern: withModifier(/(^")+/.source), lookbehind: true, inside: modifierTokens }, @@ -186,23 +198,21 @@ function textile(Prism) { // !image.jpg! // !image.jpg(Title)!:http://example.com image: { - pattern: RegExp( - '!(?:' + - modifierRegex + - '|[<>=()])*[^!\\s()]+(?:\\([^)]+\\))?!(?::.+?(?=[^\\w/]?(?:\\s|$)))?' + pattern: withModifier( + /!(?:||[<>=])*[^!\s()]+(?:\([^)]+\))?!(?::.+?(?=[^\w/]?(?:\s|$)))?/ + .source ), inside: { source: { - pattern: RegExp( - '(^!(?:' + - modifierRegex + - '|[<>=()])*)[^!\\s()]+(?:\\([^)]+\\))?(?=!)' + pattern: withModifier( + /(^!(?:||[<>=])*)[^!\s()]+(?:\([^)]+\))?(?=!)/ + .source ), lookbehind: true, alias: 'url' }, modifier: { - pattern: RegExp('(^!)(?:' + modifierRegex + '|[<>=()])+'), + pattern: withModifier(/(^!)(?:||[<>=])+/.source), lookbehind: true, inside: modifierTokens }, diff --git a/lang/toml.js b/lang/toml.js index b285f54..555a7dd 100644 --- a/lang/toml.js +++ b/lang/toml.js @@ -5,8 +5,15 @@ toml.displayName = 'toml' toml.aliases = [] function toml(Prism) { ;(function (Prism) { - // pattern: /(?:[\w-]+|'[^'\n\r]*'|"(?:\.|[^\\"\r\n])*")/ - var key = '(?:[\\w-]+|\'[^\'\n\r]*\'|"(?:\\.|[^\\\\"\r\n])*")' + var key = /(?:[\w-]+|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*")/.source + /** + * @param {string} pattern + */ + function insertKey(pattern) { + return pattern.replace(/__/g, function () { + return key + }) + } Prism.languages.toml = { comment: { pattern: /#.*/, @@ -14,11 +21,7 @@ function toml(Prism) { }, table: { pattern: RegExp( - '(^\\s*\\[\\s*(?:\\[\\s*)?)' + - key + - '(?:\\s*\\.\\s*' + - key + - ')*(?=\\s*\\])', + insertKey(/(^\s*\[\s*(?:\[\s*)?)__(?:\s*\.\s*__)*(?=\s*\])/.source), 'm' ), lookbehind: true, @@ -27,7 +30,7 @@ function toml(Prism) { }, key: { pattern: RegExp( - '(^\\s*|[{,]\\s*)' + key + '(?:\\s*\\.\\s*' + key + ')*(?=\\s*=)', + insertKey(/(^\s*|[{,]\s*)__(?:\s*\.\s*__)*(?=\s*=)/.source), 'm' ), lookbehind: true, @@ -41,16 +44,16 @@ function toml(Prism) { date: [ { // Offset Date-Time, Local Date-Time, Local Date - pattern: /\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i, + pattern: /\b\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?\b/i, alias: 'number' }, { // Local Time - pattern: /\d{2}:\d{2}:\d{2}(?:\.\d+)?/i, + pattern: /\b\d{2}:\d{2}:\d{2}(?:\.\d+)?\b/, alias: 'number' } ], - number: /(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/, + number: /(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\b\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?\b(?:inf|nan)\b/, boolean: /\b(?:true|false)\b/, punctuation: /[.,=[\]{}]/ } diff --git a/lang/tt2.js b/lang/tt2.js index 8768b87..33073ff 100644 --- a/lang/tt2.js +++ b/lang/tt2.js @@ -14,7 +14,7 @@ function tt2(Prism) { Prism.languages.insertBefore('tt2', 'number', { operator: /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|or|not)\b/, variable: { - pattern: /[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*/i + pattern: /\b[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*\b/i } }) Prism.languages.insertBefore('tt2', 'keyword', { diff --git a/lang/turtle.js b/lang/turtle.js index 19ba3b6..e7aa59f 100644 --- a/lang/turtle.js +++ b/lang/turtle.js @@ -22,7 +22,7 @@ function turtle(Prism) { greedy: true }, url: { - pattern: /<(?:[^\x00-\x20<>"{}|^`\\]|\\(?:u[\da-f]{4}|U[\da-f]{8}))*>/i, + pattern: /<(?:[^\x00-\x20<>"{}|^`\\]|\\(?:u[\da-fA-F]{4}|U[\da-fA-F]{8}))*>/, greedy: true, inside: { punctuation: /[<>]/ diff --git a/lang/typescript.js b/lang/typescript.js index 70bd049..3e0ee09 100644 --- a/lang/typescript.js +++ b/lang/typescript.js @@ -4,10 +4,38 @@ module.exports = typescript typescript.displayName = 'typescript' typescript.aliases = ['ts'] function typescript(Prism) { - Prism.languages.typescript = Prism.languages.extend('javascript', { - // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words - keyword: /\b(?:abstract|as|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/, - builtin: /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/ - }) - Prism.languages.ts = Prism.languages.typescript + ;(function (Prism) { + Prism.languages.typescript = Prism.languages.extend('javascript', { + 'class-name': { + pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/, + lookbehind: true, + greedy: true, + inside: null // see below + }, + // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words + keyword: /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/, + builtin: /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/ + }) // doesn't work with TS because TS is too complex + delete Prism.languages.typescript['parameter'] // a version of typescript specifically for highlighting types + var typeInside = Prism.languages.extend('typescript', {}) + delete typeInside['class-name'] + Prism.languages.typescript['class-name'].inside = typeInside + Prism.languages.insertBefore('typescript', 'function', { + 'generic-function': { + // e.g. foo( ... + pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/, + greedy: true, + inside: { + function: /^#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*/, + generic: { + pattern: /<[\s\S]+/, + // everything after the first < + alias: 'class-name', + inside: typeInside + } + } + } + }) + Prism.languages.ts = Prism.languages.typescript + })(Prism) } diff --git a/lang/unrealscript.js b/lang/unrealscript.js new file mode 100644 index 0000000..9c82dee --- /dev/null +++ b/lang/unrealscript.js @@ -0,0 +1,46 @@ +'use strict' + +module.exports = unrealscript +unrealscript.displayName = 'unrealscript' +unrealscript.aliases = ['uc', 'uscript'] +function unrealscript(Prism) { + Prism.languages.unrealscript = { + comment: /\/\/.*|\/\*[\s\S]*?\*\//, + string: { + pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, + greedy: true + }, + category: { + pattern: /(\b(?:(?:autoexpand|hide|show)categories|var)\s*\()[^()]+(?=\))/, + lookbehind: true, + greedy: true, + alias: 'property' + }, + metadata: { + pattern: /(\w\s*)<\s*\w+\s*=[^<>|=\r\n]+(?:\|\s*\w+\s*=[^<>|=\r\n]+)*>/, + lookbehind: true, + greedy: true, + inside: { + property: /\w+(?=\s*=)/, + operator: /=/, + punctuation: /[<>|]/ + } + }, + macro: { + pattern: /`\w+/, + alias: 'property' + }, + 'class-name': { + pattern: /(\b(?:class|enum|extends|interface|state(?:\(\))?|struct|within)\s+)\w+/, + lookbehind: true + }, + keyword: /\b(?:abstract|actor|array|auto|autoexpandcategories|bool|break|byte|case|class|classgroup|client|coerce|collapsecategories|config|const|continue|default|defaultproperties|delegate|dependson|deprecated|do|dontcollapsecategories|editconst|editinlinenew|else|enum|event|exec|export|extends|final|float|for|forcescriptorder|foreach|function|goto|guid|hidecategories|hidedropdown|if|ignores|implements|inherits|input|int|interface|iterator|latent|local|material|name|native|nativereplication|noexport|nontransient|noteditinlinenew|notplaceable|operator|optional|out|pawn|perobjectconfig|perobjectlocalized|placeable|postoperator|preoperator|private|protected|reliable|replication|return|server|showcategories|simulated|singular|state|static|string|struct|structdefault|structdefaultproperties|switch|texture|transient|travel|unreliable|until|var|vector|while|within)\b/, + function: /[a-z_]\w*(?=\s*\()/i, + boolean: /\b(?:false|true)\b/, + number: /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i, + // https://docs.unrealengine.com/udk/Three/UnrealScriptExpressions.html + operator: />>|<<|--|\+\+|\*\*|[-+*/~!=<>$@]=?|&&?|\|\|?|\^\^?|[?:%]|\b(?:Cross|Dot|ClockwiseFrom)\b/, + punctuation: /[()[\]{};,.]/ + } + Prism.languages.uc = Prism.languages.uscript = Prism.languages.unrealscript +} diff --git a/lang/visual-basic.js b/lang/visual-basic.js index 390fab5..ece7a9b 100644 --- a/lang/visual-basic.js +++ b/lang/visual-basic.js @@ -21,12 +21,12 @@ function visualBasic(Prism) { greedy: true }, date: { - pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))[^\S\r\n]*#/i, + pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?)[^\S\r\n]*#/i, alias: 'builtin' }, number: /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i, boolean: /\b(?:True|False|Nothing)\b/i, - keyword: /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Xor)\b/i, + keyword: /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Currency|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|Type|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Until|Xor)\b/i, operator: [ /[+\-*/\\^<=>&#@$%!]/, { @@ -37,4 +37,5 @@ function visualBasic(Prism) { punctuation: /[{}().,:?]/ } Prism.languages.vb = Prism.languages['visual-basic'] + Prism.languages.vba = Prism.languages['visual-basic'] } diff --git a/lang/warpscript.js b/lang/warpscript.js new file mode 100644 index 0000000..a1ab370 --- /dev/null +++ b/lang/warpscript.js @@ -0,0 +1,28 @@ +'use strict' + +module.exports = warpscript +warpscript.displayName = 'warpscript' +warpscript.aliases = [] +function warpscript(Prism) { + Prism.languages.warpscript = { + comment: /#.*|\/\/.*|\/\*[\s\S]*?\*\//, + string: { + pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'|<'(?:[^\\']|'(?!>)|\\.)*'>/, + greedy: true + }, + variable: /\$\S+/, + macro: { + pattern: /@\S+/, + alias: 'property' + }, + // WarpScript doesn't have any keywords, these are all functions under the control category + // https://www.warp10.io/tags/control + keyword: /\b(?:BREAK|CHECKMACRO|CONTINUE|CUDF|DEFINED|DEFINEDMACRO|EVAL|FAIL|FOR|FOREACH|FORSTEP|IFT|IFTE|MSGFAIL|NRETURN|RETHROW|RETURN|SWITCH|TRY|UDF|UNTIL|WHILE)\b/, + number: /[+-]?\b(?:NaN|Infinity|\d+(?:\.\d*)?(?:[Ee][+-]?\d+)?|0x[\da-fA-F]+|0b[01]+)\b/, + boolean: /\b(?:false|true|F|T)\b/, + punctuation: /<%|%>|[{}[\]()]/, + // Some operators from the "operators" category + // https://www.warp10.io/tags/operators + operator: /==|&&?|\|\|?|\*\*?|>>>?|<<|==|[<>!~]=?|[-/%^]|\+!?|\b(?:AND|NOT|OR)\b/ + } +} diff --git a/lang/xml-doc.js b/lang/xml-doc.js new file mode 100644 index 0000000..3e31082 --- /dev/null +++ b/lang/xml-doc.js @@ -0,0 +1,42 @@ +'use strict' + +module.exports = xmlDoc +xmlDoc.displayName = 'xmlDoc' +xmlDoc.aliases = [] +function xmlDoc(Prism) { + ;(function (Prism) { + /** + * If the given language is present, it will insert the given doc comment grammar token into it. + * + * @param {string} lang + * @param {any} docComment + */ + function insertDocComment(lang, docComment) { + if (Prism.languages[lang]) { + Prism.languages.insertBefore(lang, 'comment', { + 'doc-comment': docComment + }) + } + } + var tag = Prism.languages.markup.tag + var slashDocComment = { + pattern: /\/\/\/.*/, + greedy: true, + alias: 'comment', + inside: { + tag: tag + } + } + var tickDocComment = { + pattern: /'''.*/, + greedy: true, + alias: 'comment', + inside: { + tag: tag + } + } + insertDocComment('csharp', slashDocComment) + insertDocComment('fsharp', slashDocComment) + insertDocComment('vbnet', tickDocComment) + })(Prism) +} diff --git a/lang/xquery.js b/lang/xquery.js index 59147c8..1325dbb 100644 --- a/lang/xquery.js +++ b/lang/xquery.js @@ -59,16 +59,16 @@ function xquery(Prism) { ], punctuation: /[[\](){},;:/]/ }) - Prism.languages.xquery.tag.pattern = /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|{(?!{)(?:{(?:{[^}]*}|[^}])*}|[^}])+}|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i + Prism.languages.xquery.tag.pattern = /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|{(?!{)(?:{(?:{[^{}]*}|[^{}])*}|[^{}])+}|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i Prism.languages.xquery['tag'].inside[ 'attr-value' - ].pattern = /=(?:("|')(?:\\[\s\S]|{(?!{)(?:{(?:{[^}]*}|[^}])*}|[^}])+}|(?!\1)[^\\])*\1|[^\s'">=]+)/i + ].pattern = /=(?:("|')(?:\\[\s\S]|{(?!{)(?:{(?:{[^{}]*}|[^{}])*}|[^{}])+}|(?!\1)[^\\])*\1|[^\s'">=]+)/i Prism.languages.xquery['tag'].inside['attr-value'].inside[ 'punctuation' ] = /^="|"$/ Prism.languages.xquery['tag'].inside['attr-value'].inside['expression'] = { // Allow for two levels of nesting - pattern: /{(?!{)(?:{(?:{[^}]*}|[^}])*}|[^}])+}/, + pattern: /{(?!{)(?:{(?:{[^{}]*}|[^{}])*}|[^{}])+}/, inside: Prism.languages.xquery, alias: 'language-xquery' } // The following will handle plain text inside tags diff --git a/lang/yang.js b/lang/yang.js new file mode 100644 index 0000000..3a963b7 --- /dev/null +++ b/lang/yang.js @@ -0,0 +1,27 @@ +'use strict' + +module.exports = yang +yang.displayName = 'yang' +yang.aliases = [] +function yang(Prism) { + Prism.languages.yang = { + // https://tools.ietf.org/html/rfc6020#page-34 + // http://www.yang-central.org/twiki/bin/view/Main/YangExamples + comment: /\/\*[\s\S]*?\*\/|\/\/.*/, + string: { + pattern: /"(?:[^\\"]|\\.)*"|'[^']*'/, + greedy: true + }, + keyword: { + pattern: /(^|[{};\r\n][ \t]*)[a-z_][\w.-]*/i, + lookbehind: true + }, + namespace: { + pattern: /(\s)[a-z_][\w.-]*(?=:)/i, + lookbehind: true + }, + boolean: /\b(?:false|true)\b/, + operator: /\+/, + punctuation: /[{};:]/ + } +} diff --git a/package.json b/package.json index c52876d..3324ada 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dependencies": { "hastscript": "^5.0.0", "parse-entities": "^2.0.0", - "prismjs": "~1.20.0" + "prismjs": "~1.21.0" }, "devDependencies": { "@babel/core": "^7.0.0", diff --git a/readme.md b/readme.md index 09eca1f..4f7cb1a 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ Perfect for [React][], [VDOM][], and others. `refractor` is built to work with all syntaxes supported by [Prism][], -that’s [209 languages][names] (as of [prism@1.20.0][prismjs]) and all +that’s [226 languages][names] (as of [prism@1.21.0][prismjs]) and all [themes][]. @@ -326,11 +326,13 @@ syntaxes are made to work with global variables and are not requirable. * [x] [`clike`](https://github.com/wooorm/refractor/blob/main/lang/clike.js) * [x] [`css`](https://github.com/wooorm/refractor/blob/main/lang/css.js) * [x] [`javascript`](https://github.com/wooorm/refractor/blob/main/lang/javascript.js) — alias: `js` -* [x] [`markup`](https://github.com/wooorm/refractor/blob/main/lang/markup.js) — alias: `xml`, `html`, `mathml`, `svg` +* [x] [`markup`](https://github.com/wooorm/refractor/blob/main/lang/markup.js) — alias: `html`, `mathml`, `svg`, `xml`, `ssml`, `atom`, `rss` * [ ] [`abap`](https://github.com/wooorm/refractor/blob/main/lang/abap.js) * [ ] [`abnf`](https://github.com/wooorm/refractor/blob/main/lang/abnf.js) * [ ] [`actionscript`](https://github.com/wooorm/refractor/blob/main/lang/actionscript.js) * [ ] [`ada`](https://github.com/wooorm/refractor/blob/main/lang/ada.js) +* [ ] [`agda`](https://github.com/wooorm/refractor/blob/main/lang/agda.js) +* [ ] [`al`](https://github.com/wooorm/refractor/blob/main/lang/al.js) * [ ] [`antlr4`](https://github.com/wooorm/refractor/blob/main/lang/antlr4.js) — alias: `g4` * [ ] [`apacheconf`](https://github.com/wooorm/refractor/blob/main/lang/apacheconf.js) * [ ] [`apl`](https://github.com/wooorm/refractor/blob/main/lang/apl.js) @@ -363,16 +365,19 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`csharp`](https://github.com/wooorm/refractor/blob/main/lang/csharp.js) — alias: `dotnet`, `cs` * [ ] [`csp`](https://github.com/wooorm/refractor/blob/main/lang/csp.js) * [ ] [`cssExtras`](https://github.com/wooorm/refractor/blob/main/lang/css-extras.js) +* [ ] [`cypher`](https://github.com/wooorm/refractor/blob/main/lang/cypher.js) * [ ] [`d`](https://github.com/wooorm/refractor/blob/main/lang/d.js) * [ ] [`dart`](https://github.com/wooorm/refractor/blob/main/lang/dart.js) * [ ] [`dax`](https://github.com/wooorm/refractor/blob/main/lang/dax.js) +* [ ] [`dhall`](https://github.com/wooorm/refractor/blob/main/lang/dhall.js) * [ ] [`diff`](https://github.com/wooorm/refractor/blob/main/lang/diff.js) * [ ] [`django`](https://github.com/wooorm/refractor/blob/main/lang/django.js) — alias: `jinja2` * [ ] [`dnsZoneFile`](https://github.com/wooorm/refractor/blob/main/lang/dns-zone-file.js) * [ ] [`docker`](https://github.com/wooorm/refractor/blob/main/lang/docker.js) — alias: `dockerfile` * [ ] [`ebnf`](https://github.com/wooorm/refractor/blob/main/lang/ebnf.js) +* [ ] [`editorconfig`](https://github.com/wooorm/refractor/blob/main/lang/editorconfig.js) * [ ] [`eiffel`](https://github.com/wooorm/refractor/blob/main/lang/eiffel.js) -* [ ] [`ejs`](https://github.com/wooorm/refractor/blob/main/lang/ejs.js) +* [ ] [`ejs`](https://github.com/wooorm/refractor/blob/main/lang/ejs.js) — alias: `eta` * [ ] [`elixir`](https://github.com/wooorm/refractor/blob/main/lang/elixir.js) * [ ] [`elm`](https://github.com/wooorm/refractor/blob/main/lang/elm.js) * [ ] [`erb`](https://github.com/wooorm/refractor/blob/main/lang/erb.js) @@ -400,11 +405,14 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`haskell`](https://github.com/wooorm/refractor/blob/main/lang/haskell.js) — alias: `hs` * [ ] [`haxe`](https://github.com/wooorm/refractor/blob/main/lang/haxe.js) * [ ] [`hcl`](https://github.com/wooorm/refractor/blob/main/lang/hcl.js) +* [ ] [`hlsl`](https://github.com/wooorm/refractor/blob/main/lang/hlsl.js) * [ ] [`hpkp`](https://github.com/wooorm/refractor/blob/main/lang/hpkp.js) * [ ] [`hsts`](https://github.com/wooorm/refractor/blob/main/lang/hsts.js) * [ ] [`http`](https://github.com/wooorm/refractor/blob/main/lang/http.js) * [ ] [`ichigojam`](https://github.com/wooorm/refractor/blob/main/lang/ichigojam.js) * [ ] [`icon`](https://github.com/wooorm/refractor/blob/main/lang/icon.js) +* [ ] [`iecst`](https://github.com/wooorm/refractor/blob/main/lang/iecst.js) +* [ ] [`ignore`](https://github.com/wooorm/refractor/blob/main/lang/ignore.js) * [ ] [`inform7`](https://github.com/wooorm/refractor/blob/main/lang/inform7.js) * [ ] [`ini`](https://github.com/wooorm/refractor/blob/main/lang/ini.js) * [ ] [`io`](https://github.com/wooorm/refractor/blob/main/lang/io.js) @@ -418,13 +426,14 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`jsExtras`](https://github.com/wooorm/refractor/blob/main/lang/js-extras.js) * [ ] [`jsTemplates`](https://github.com/wooorm/refractor/blob/main/lang/js-templates.js) * [ ] [`jsdoc`](https://github.com/wooorm/refractor/blob/main/lang/jsdoc.js) -* [ ] [`json`](https://github.com/wooorm/refractor/blob/main/lang/json.js) +* [ ] [`json`](https://github.com/wooorm/refractor/blob/main/lang/json.js) — alias: `webmanifest` * [ ] [`json5`](https://github.com/wooorm/refractor/blob/main/lang/json5.js) * [ ] [`jsonp`](https://github.com/wooorm/refractor/blob/main/lang/jsonp.js) +* [ ] [`jsstacktrace`](https://github.com/wooorm/refractor/blob/main/lang/jsstacktrace.js) * [ ] [`jsx`](https://github.com/wooorm/refractor/blob/main/lang/jsx.js) * [ ] [`julia`](https://github.com/wooorm/refractor/blob/main/lang/julia.js) * [ ] [`keyman`](https://github.com/wooorm/refractor/blob/main/lang/keyman.js) -* [ ] [`kotlin`](https://github.com/wooorm/refractor/blob/main/lang/kotlin.js) +* [ ] [`kotlin`](https://github.com/wooorm/refractor/blob/main/lang/kotlin.js) — alias: `kt`, `kts` * [ ] [`latex`](https://github.com/wooorm/refractor/blob/main/lang/latex.js) — alias: `tex`, `context` * [ ] [`latte`](https://github.com/wooorm/refractor/blob/main/lang/latte.js) * [ ] [`less`](https://github.com/wooorm/refractor/blob/main/lang/less.js) @@ -452,7 +461,7 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`nim`](https://github.com/wooorm/refractor/blob/main/lang/nim.js) * [ ] [`nix`](https://github.com/wooorm/refractor/blob/main/lang/nix.js) * [ ] [`nsis`](https://github.com/wooorm/refractor/blob/main/lang/nsis.js) -* [ ] [`objectivec`](https://github.com/wooorm/refractor/blob/main/lang/objectivec.js) +* [ ] [`objectivec`](https://github.com/wooorm/refractor/blob/main/lang/objectivec.js) — alias: `objc` * [ ] [`ocaml`](https://github.com/wooorm/refractor/blob/main/lang/ocaml.js) * [ ] [`opencl`](https://github.com/wooorm/refractor/blob/main/lang/opencl.js) * [ ] [`oz`](https://github.com/wooorm/refractor/blob/main/lang/oz.js) @@ -461,6 +470,7 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`pascal`](https://github.com/wooorm/refractor/blob/main/lang/pascal.js) — alias: `objectpascal` * [ ] [`pascaligo`](https://github.com/wooorm/refractor/blob/main/lang/pascaligo.js) * [ ] [`pcaxis`](https://github.com/wooorm/refractor/blob/main/lang/pcaxis.js) — alias: `px` +* [ ] [`peoplecode`](https://github.com/wooorm/refractor/blob/main/lang/peoplecode.js) — alias: `pcode` * [ ] [`perl`](https://github.com/wooorm/refractor/blob/main/lang/perl.js) * [ ] [`phpExtras`](https://github.com/wooorm/refractor/blob/main/lang/php-extras.js) * [ ] [`php`](https://github.com/wooorm/refractor/blob/main/lang/php.js) @@ -475,14 +485,16 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`pug`](https://github.com/wooorm/refractor/blob/main/lang/pug.js) * [ ] [`puppet`](https://github.com/wooorm/refractor/blob/main/lang/puppet.js) * [ ] [`pure`](https://github.com/wooorm/refractor/blob/main/lang/pure.js) +* [ ] [`purebasic`](https://github.com/wooorm/refractor/blob/main/lang/purebasic.js) * [ ] [`python`](https://github.com/wooorm/refractor/blob/main/lang/python.js) — alias: `py` * [ ] [`q`](https://github.com/wooorm/refractor/blob/main/lang/q.js) * [ ] [`qml`](https://github.com/wooorm/refractor/blob/main/lang/qml.js) * [ ] [`qore`](https://github.com/wooorm/refractor/blob/main/lang/qore.js) * [ ] [`r`](https://github.com/wooorm/refractor/blob/main/lang/r.js) +* [ ] [`racket`](https://github.com/wooorm/refractor/blob/main/lang/racket.js) — alias: `rkt` * [ ] [`reason`](https://github.com/wooorm/refractor/blob/main/lang/reason.js) * [ ] [`regex`](https://github.com/wooorm/refractor/blob/main/lang/regex.js) -* [ ] [`renpy`](https://github.com/wooorm/refractor/blob/main/lang/renpy.js) +* [ ] [`renpy`](https://github.com/wooorm/refractor/blob/main/lang/renpy.js) — alias: `rpy` * [ ] [`rest`](https://github.com/wooorm/refractor/blob/main/lang/rest.js) * [ ] [`rip`](https://github.com/wooorm/refractor/blob/main/lang/rip.js) * [ ] [`roboconf`](https://github.com/wooorm/refractor/blob/main/lang/roboconf.js) @@ -495,9 +507,10 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`scheme`](https://github.com/wooorm/refractor/blob/main/lang/scheme.js) * [ ] [`scss`](https://github.com/wooorm/refractor/blob/main/lang/scss.js) * [ ] [`shellSession`](https://github.com/wooorm/refractor/blob/main/lang/shell-session.js) +* [ ] [`smali`](https://github.com/wooorm/refractor/blob/main/lang/smali.js) * [ ] [`smalltalk`](https://github.com/wooorm/refractor/blob/main/lang/smalltalk.js) * [ ] [`smarty`](https://github.com/wooorm/refractor/blob/main/lang/smarty.js) -* [ ] [`solidity`](https://github.com/wooorm/refractor/blob/main/lang/solidity.js) +* [ ] [`solidity`](https://github.com/wooorm/refractor/blob/main/lang/solidity.js) — alias: `sol` * [ ] [`solutionFile`](https://github.com/wooorm/refractor/blob/main/lang/solution-file.js) * [ ] [`soy`](https://github.com/wooorm/refractor/blob/main/lang/soy.js) * [ ] [`sparql`](https://github.com/wooorm/refractor/blob/main/lang/sparql.js) — alias: `rq` @@ -518,6 +531,7 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`turtle`](https://github.com/wooorm/refractor/blob/main/lang/turtle.js) * [ ] [`twig`](https://github.com/wooorm/refractor/blob/main/lang/twig.js) * [ ] [`typescript`](https://github.com/wooorm/refractor/blob/main/lang/typescript.js) — alias: `ts` +* [ ] [`unrealscript`](https://github.com/wooorm/refractor/blob/main/lang/unrealscript.js) — alias: `uc`, `uscript` * [ ] [`vala`](https://github.com/wooorm/refractor/blob/main/lang/vala.js) * [ ] [`vbnet`](https://github.com/wooorm/refractor/blob/main/lang/vbnet.js) * [ ] [`velocity`](https://github.com/wooorm/refractor/blob/main/lang/velocity.js) @@ -525,12 +539,15 @@ syntaxes are made to work with global variables and are not requirable. * [ ] [`vhdl`](https://github.com/wooorm/refractor/blob/main/lang/vhdl.js) * [ ] [`vim`](https://github.com/wooorm/refractor/blob/main/lang/vim.js) * [ ] [`visualBasic`](https://github.com/wooorm/refractor/blob/main/lang/visual-basic.js) +* [ ] [`warpscript`](https://github.com/wooorm/refractor/blob/main/lang/warpscript.js) * [ ] [`wasm`](https://github.com/wooorm/refractor/blob/main/lang/wasm.js) * [ ] [`wiki`](https://github.com/wooorm/refractor/blob/main/lang/wiki.js) * [ ] [`xeora`](https://github.com/wooorm/refractor/blob/main/lang/xeora.js) — alias: `xeoracube` +* [ ] [`xmlDoc`](https://github.com/wooorm/refractor/blob/main/lang/xml-doc.js) * [ ] [`xojo`](https://github.com/wooorm/refractor/blob/main/lang/xojo.js) * [ ] [`xquery`](https://github.com/wooorm/refractor/blob/main/lang/xquery.js) * [ ] [`yaml`](https://github.com/wooorm/refractor/blob/main/lang/yaml.js) — alias: `yml` +* [ ] [`yang`](https://github.com/wooorm/refractor/blob/main/lang/yang.js) * [ ] [`zig`](https://github.com/wooorm/refractor/blob/main/lang/zig.js) diff --git a/script/languages.js b/script/languages.js index c2c0f6c..fc0a2c7 100644 --- a/script/languages.js +++ b/script/languages.js @@ -14,10 +14,7 @@ var trim = require('trim-lines') var bundled = require('./bundled') var root = path.join('node_modules', 'prismjs', 'components') -var useBracesRegex = /Prism\.languages\[['"]([^'"]+)['"]](?!\s*[=:])/g -var extendRegex = /languages\.extend\(['"]([^'"]+)['"]/g -var insertRegex = /Prism\.languages\.insertBefore\(["'](.+?)["']/g -var cloneRegex = /Prism\.util\.clone\(Prism\.languages\.([^[)]+)[)[]/g +var componentsJson = require('prismjs/components.json') var anyAliasRegex = /((?:Prism\.languages\.\w+ = )+)Prism\.languages\.(extend\([^)]+\)|\w+);/g var aliasRegex = /Prism\.languages\.(\w+) = /g var prefix = 'refractor-' @@ -57,18 +54,18 @@ function generate(name, callback) { return callback(err) } - deps = [].concat( - findAll(doc, useBracesRegex), - findAll(doc, extendRegex), - findAll(doc, cloneRegex), - findAll(doc, insertRegex) - ) - anyAlias = findAll(doc, anyAliasRegex).join('\n') - aliases = findAll(anyAlias, aliasRegex).filter((d) => d !== name) + deps = componentsJson.languages[name].require || [] + + if (!Array.isArray(deps)) { + deps = [deps] + } deps = diff(deps.filter(unique), bundled.map(base).concat([id, 'inside'])) deps = deps.filter((d) => d !== name) + anyAlias = findAll(doc, anyAliasRegex).join('\n') + aliases = findAll(anyAlias, aliasRegex).filter((d) => d !== name) + doc = babel.transformSync(doc, {plugins: [fixWrapHook]}).code fs.writeFile( diff --git a/test/fixtures/js-keywords/output.html b/test/fixtures/js-keywords/output.html index 157bce3..38098e1 100644 --- a/test/fixtures/js-keywords/output.html +++ b/test/fixtures/js-keywords/output.html @@ -1,6 +1,6 @@ function $initHighlight(block, cls) { try { - if (cls.search(/\bno\-highlight\b/) != -1) + if (cls.search(/\bno\-highlight\b/) != -1) return process(block, true, 0x0F) + ' class=""'; } catch (e) { @@ -8,6 +8,6 @@ } for (var i = 0 / 2; i < classes.length; i++) { if (checkCondition(classes[i]) === undefined) - return /\d+[\s/]/g; + return /\d+[\s/]/g; } } diff --git a/test/fixtures/jsx-advanced/output.html b/test/fixtures/jsx-advanced/output.html index 1bfaeff..a57569c 100644 --- a/test/fixtures/jsx-advanced/output.html +++ b/test/fixtures/jsx-advanced/output.html @@ -18,10 +18,10 @@ render() { return ( <div> - <Alert color="info" isOpen={this.state.visible} toggle={this.onDismiss}> + <Alert color="info" isOpen={this.state.visible} toggle={this.onDismiss}> I am an alert and I can be dismissed! </Alert> - <Button className="btn btn-primary" onClick={this.resetCloseAlert}>Reset alert</Button> + <Button className="btn btn-primary" onClick={this.resetCloseAlert}>Reset alert</Button> <div> ) } diff --git a/test/fixtures/jsx/output.html b/test/fixtures/jsx/output.html index c95a611..aa80624 100644 --- a/test/fixtures/jsx/output.html +++ b/test/fixtures/jsx/output.html @@ -3,4 +3,4 @@ var jsx = <node>...<child>...</child></node>; var jsx = <div><br /></div>; var x = 5; -return (<node attr="value"></node>); +return (<node attr="value"></node>); diff --git a/test/fixtures/markdown-sublanguage/output.html b/test/fixtures/markdown-sublanguage/output.html index 21a866b..58fe30e 100755 --- a/test/fixtures/markdown-sublanguage/output.html +++ b/test/fixtures/markdown-sublanguage/output.html @@ -1 +1 @@ -This is _markdown_ with some <abbr title="Hypertext Markup Language">HTML</abbr> +This is _markdown_ with some <abbr title="Hypertext Markup Language">HTML</abbr> diff --git a/test/fixtures/markup-character-entity/output.html b/test/fixtures/markup-character-entity/output.html index 1ff9663..a5d9366 100644 --- a/test/fixtures/markup-character-entity/output.html +++ b/test/fixtures/markup-character-entity/output.html @@ -1 +1 @@ -<foo>&lt;</foo> +<foo>&lt;</foo> diff --git a/test/fixtures/rust-comments/output.html b/test/fixtures/rust-comments/output.html index cc54c05..64d1c41 100755 --- a/test/fixtures/rust-comments/output.html +++ b/test/fixtures/rust-comments/output.html @@ -1,3 +1,3 @@ /* rust has -/* nested /* block */ */ -*/ comments +/* nested /* block */ */ +*/ comments diff --git a/test/fixtures/rust-numbers/output.html b/test/fixtures/rust-numbers/output.html index 5f49ae1..9e789af 100755 --- a/test/fixtures/rust-numbers/output.html +++ b/test/fixtures/rust-numbers/output.html @@ -1,6 +1,6 @@ 123; -123usize; -123_usize; +123usize; +123_usize; 0xff00; 0xff_u8; 0b1111111110010000; diff --git a/test/fixtures/rust-strings/output.html b/test/fixtures/rust-strings/output.html index b4ee60a..17d2e3c 100755 --- a/test/fixtures/rust-strings/output.html +++ b/test/fixtures/rust-strings/output.html @@ -1,8 +1,8 @@ 'a'; '\n'; '\x1A'; -'\u12AS'; -'\U1234ASDF'; +'\u12AS'; +'\U1234ASDF'; b'a'; "hello"; diff --git a/test/fixtures/rust-traits/output.html b/test/fixtures/rust-traits/output.html index 487c238..6de0fbc 100644 --- a/test/fixtures/rust-traits/output.html +++ b/test/fixtures/rust-traits/output.html @@ -1,3 +1,3 @@ -fn sqr(i: i32) { i * i } -trait Minimum : Copy {} -pub trait Builder where Self: Sized + Iterator<Item=Event> {} +fn sqr(i: i32) { i * i } +trait Minimum : Copy {} +pub trait Builder where Self: Sized + Iterator<Item=Event> {} diff --git a/test/fixtures/xml-large/output.html b/test/fixtures/xml-large/output.html index 6f8918c..c75b1c4 100755 --- a/test/fixtures/xml-large/output.html +++ b/test/fixtures/xml-large/output.html @@ -1,7 +1,7 @@ <?xml version="1.0"?> -<response value="ok" xml:lang="en"> +<response value="ok" xml:lang="en"> <text>Ok</text> - <comment html_allowed="true"/> + <comment html_allowed="true"/> <ns1:description><![CDATA[ CDATA is <not> magical. ]]></ns1:description>