From 1e47fbb52a3901795d1ccfb12ee3885f34002b9b Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:20:46 -0500 Subject: [PATCH 1/6] Create julia.ts --- src/julia/julia.ts | 297 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 src/julia/julia.ts diff --git a/src/julia/julia.ts b/src/julia/julia.ts new file mode 100644 index 00000000..bfd2a515 --- /dev/null +++ b/src/julia/julia.ts @@ -0,0 +1,297 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'] + ], + autoClosingPairs: [ + {open: '{', close: '}'}, + {open: '[', close: ']'}, + {open: '(', close: ')'}, + {open: '"', close: '"'}, + {open: '\'', close: '\''}, + ], + surroundingPairs: [ + {open: '{', close: '}'}, + {open: '[', close: ']'}, + {open: '(', close: ')'}, + {open: '"', close: '"'}, + {open: '\'', close: '\''}, + ] +}; + +export const language = { + tokenPostfix: '.julia', + + keywords: [ + 'begin', 'while', 'if', 'for', 'try', 'return', 'break', 'continue', + 'function', 'macro', 'quote', 'let', 'local', 'global', 'const', 'do', + 'struct', 'module', 'baremodule', 'using', 'import', 'export', + 'end', 'else', 'elseif', 'catch', 'finally', + 'mutable', 'primitive', 'abstract', 'type', + 'in', 'isa', 'where', 'new' + ], + + types: [ + 'LinRange', 'LineNumberNode', 'LinearIndices', 'LoadError', 'MIME', 'Matrix', 'Method', 'MethodError', + 'Missing', 'MissingException', 'Module', 'NTuple', 'NamedTuple', 'Nothing', 'Number', 'OrdinalRange', + 'OutOfMemoryError', 'OverflowError', 'Pair', 'PartialQuickSort', 'PermutedDimsArray', 'Pipe', 'Ptr', + 'QuoteNode', 'Rational', 'RawFD', 'ReadOnlyMemoryError', 'Real', 'ReentrantLock', 'Ref', 'Regex', 'RegexMatch', + 'RoundingMode', 'SegmentationFault', 'Set', 'Signed', 'Some', 'StackOverflowError', 'StepRange', 'StepRangeLen', + 'StridedArray', 'StridedMatrix', 'StridedVecOrMat', 'StridedVector', 'String', 'StringIndexError', 'SubArray', + 'SubString', 'SubstitutionString', 'Symbol', 'SystemError', 'Task', 'Text', 'TextDisplay', 'Timer', 'Tuple', 'Type', + 'TypeError', 'TypeVar', 'UInt', 'UInt128', 'UInt16', 'UInt32', 'UInt64', 'UInt8', 'UndefInitializer', 'AbstractArray', + 'UndefKeywordError', 'AbstractChannel', 'UndefRefError', 'AbstractChar', 'UndefVarError', 'AbstractDict', 'Union', + 'AbstractDisplay', 'UnionAll', 'AbstractFloat', 'UnitRange', 'AbstractIrrational', 'Unsigned', 'AbstractMatrix', + 'AbstractRange', 'Val', 'AbstractSet', 'Vararg', 'AbstractString', 'VecElement', 'AbstractUnitRange', 'VecOrMat', + 'AbstractVecOrMat', 'Vector', 'AbstractVector', 'VersionNumber', 'Any', 'WeakKeyDict', 'ArgumentError', 'WeakRef', + 'Array', 'AssertionError', 'BigFloat', 'BigInt', 'BitArray', 'BitMatrix', 'BitSet', 'BitVector', 'Bool', 'BoundsError', + 'CapturedException', 'CartesianIndex', 'CartesianIndices', 'Cchar', 'Cdouble', 'Cfloat', 'Channel', 'Char', 'Cint', + 'Cintmax_t', 'Clong', 'Clonglong', 'Cmd', 'Colon', 'Complex', 'ComplexF16', 'ComplexF32', 'ComplexF64', + 'CompositeException', 'Condition', 'Cptrdiff_t', 'Cshort', 'Csize_t', 'Cssize_t', 'Cstring', 'Cuchar', 'Cuint', + 'Cuintmax_t', 'Culong', 'Culonglong', 'Cushort', 'Cvoid', 'Cwchar_t', 'Cwstring', 'DataType', 'DenseArray', + 'DenseMatrix', 'DenseVecOrMat', 'DenseVector', 'Dict', 'DimensionMismatch', 'Dims', 'DivideError', 'DomainError', + 'EOFError', 'Enum', 'ErrorException', 'Exception', 'ExponentialBackOff', 'Expr', 'Float16', 'Float32', 'Float64', + 'Function', 'GlobalRef', 'HTML', 'IO', 'IOBuffer', 'IOContext', 'IOStream', 'IdDict', 'IndexCartesian', 'IndexLinear', + 'IndexStyle', 'InexactError', 'InitError', 'Int', 'Int128', 'Int16', 'Int32', 'Int64', 'Int8', 'Integer', + 'InterruptException', 'InvalidStateException', 'Irrational', 'KeyError' + ], + + keywordops: [ + '<:', '>:', ':', '=>', '...', '.', '->', '?' + ], + + allops: /[^\w\d\s()\[\]{}"'#]+/, + + constants: [ + 'true', 'false', 'nothing', 'missing', 'undef', + 'Inf', 'pi', 'NaN', 'π', 'ℯ', + 'ans', + 'PROGRAM_FILE', 'ARGS', 'C_NULL', 'VERSION', 'DEPOT_PATH', 'LOAD_PATH' + ], + + operators: [ + '!', '!=', '!==', '%', '&', '*', '+', '-', '/', '//', '<', '<<', '<=', '==', '===', + '=>', '>', '>=', '>>', '>>>', '\\', '^', '|', '|>', '~', '÷', '∈', '∉', '∋', '∌', '∘', + '√', '∛', '∩', '∪', '≈', '≉', '≠', '≡', '≢', '≤', '≥', '⊆', '⊇', '⊈', '⊉', '⊊', '⊋', '⊻' + ], + + brackets: [ + { open: '(', close: ')', token: 'delimiter.parenthesis' }, + { open: '{', close: '}', token: 'delimiter.curly' }, + { open: '[', close: ']', token: 'delimiter.square' } + ], + + ident: /π|ℯ|\b(?!\d)\w+\b/, + + // escape sequences + escape: /(?:[abefnrstv\\"'\n\r]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4})/, + escapes: /\\(?:C\-(@escape|.)|c(@escape|.)|@escape)/, + + // The main tokenizer for our languages + tokenizer: { + root: [ + [/(::)\s*|\b(isa)\s+/, 'keyword', '@typeanno'], + [/\b(isa)(\s*\(@ident\s*,\s*)/, ['keyword', {token: '', next: '@typeanno'}]], + [/\b(type|struct)[ \t]+/, 'keyword', '@typeanno'], + + // symbols + [/^\s*:@ident[!?]?/, 'metatag'], + [/(return)(\s*:@ident[!?]?)/, ['keyword', 'metatag']], + [/(\(|\[|\{|@allops)(\s*:@ident[!?]?)/, ['', 'metatag']], + [/:\(/, 'metatag', '@quote'], + + // regular expressions + [/r"""/, 'regexp.delim', '@tregexp'], + [/r"/, 'regexp.delim', '@sregexp'], + + // strings + [/raw"""/, 'string.delim', '@rtstring'], + [/[bv]?"""/, 'string.delim', '@dtstring'], + + [/raw"/, 'string.delim', '@rsstring'], + [/[bv]?"/, 'string.delim', '@dsstring'], + + [/(@ident)\{/, { + cases: { + '$1@types': {token: 'type', next: '@gen'}, + '@default': {token: 'type', next: '@gen'} + } + }], + + [/@ident[!?'']?(?=\.?\()/, { + cases: { + '@types': 'type', + '@keywords': 'keyword', + '@constants': 'variable', + '@default': 'keyword.flow' + } + }], + + [/@ident[!?']?/, { + cases: { + '@types': 'type', + '@keywords': 'keyword', + '@constants': 'variable', + '@default': 'identifier' + } + }], + + [/\$\w+/, 'key'], + [/\$\(/, 'key', '@paste'], + + [/@@ident/, 'annotation'], + + // whitespace + {include: '@whitespace'}, + + // characters + [/'(?:@escapes|.)'/, 'string.character'], + + // delimiters and operators + [/[()\[\]{}]/, '@brackets'], + [/@allops/, { + cases: { + '@keywordops': 'keyword', + '@operators': 'operator', + } + }], + [/[;,]/, 'delimiter'], + + + // numbers + [/0[xX][0-9a-fA-F](_?[0-9a-fA-F])*/, 'number.hex'], + [/0[_oO][0-7](_?[0-7])*/, 'number.octal'], + [/0[bB][01](_?[01])*/, 'number.binary'], + [/[+\-]?\d+(\.\d+)?(im?|[eE][+\-]?\d+(\.\d+)?)?/, 'number'] + ], + + // type + typeanno: [ + [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*\{/, 'type', '@gen'], + [/([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(\s*<:\s*)/, ['type', 'keyword']], + [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*/, 'type', '@pop'], + ['', '', '@pop'] + ], + + // generic type + gen: [ + [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*\{/, 'type', '@push'], + [/[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*/, 'type'], + [/<:/, 'keyword'], + [/(\})(\s*<:\s*)/, ['type', {token: 'keyword', next: '@pop'}]], + [/\}/, 'type', '@pop'], + {include: '@root'} + ], + + // $(...) + quote: [ + [/\$\(/, 'key', '@paste'], + [/\(/, '@brackets', '@paren'], + [/\)/, 'metatag', '@pop'], + {include: '@root'} + ], + + // :(...) + paste: [ + [/:\(/, 'metatag', '@quote'], + [/\(/, '@brackets', '@paren'], + [/\)/, 'key', '@pop'], + {include: '@root'} + ], + + // (...) + paren: [ + [/\$\(/, 'key', '@paste'], + [/:\(/, 'metatag', '@quote'], + [/\(/, '@brackets', '@push'], + [/\)/, '@brackets', '@pop'], + {include: '@root'} + ], + + // r"egex string" + sregexp: [ + [/^.*/, 'invalid'], + [/[^\\"()\[\]{}]/, 'regexp'], + [/[()\[\]{}]/, '@brackets'], + [/\\./, 'operator.scss'], + [/"[imsx]*/, 'regexp.delim', '@pop'] + ], + tregexp: [ + [/[^\\"()\[\]{}]/, 'regexp'], + [/[()\[\]{}]/, '@brackets'], + [/\\./, 'operator.scss'], + [/"(?!"")/, 'string'], + [/"""[imsx]*/, 'regexp.delim', '@pop'] + ], + + // raw"string" + rsstring: [ + [/^.*/, 'invalid'], + [/[^\\"]/, 'string'], + [/\\./, 'string.escape'], + [/"/, 'string.delim', '@pop'] + ], + rtstring: [ + [/[^\\"]/, 'string'], + [/\\./, 'string.escape'], + [/"(?!"")/, 'string'], + [/"""/, 'string.delim', '@pop'] + ], + + // "string". + dsstring: [ + [/^.*/, 'invalid'], + [/[^\\"\$]/, 'string'], + [/\$/, '', '@interpolated'], + [/@escapes/, 'string.escape'], + [/\\./, 'string.escape.invalid'], + [/"/, 'string.delim', '@pop'], + ], + dtstring: [ + [/[^\\"\$]/, 'string'], + [/\$/, '', '@interpolated'], + [/@escapes/, 'string.escape'], + [/\\./, 'string.escape.invalid'], + [/"(?!"")/, 'string'], + [/"""/, 'string.delim', '@pop'], + ], + + // interpolated sequence + interpolated: [ + [/\(/, { token: '', switchTo: '@interpolated_compound' }], + [/[a-zA-Z_]\w*/, 'identifier'], + ['', '', '@pop'] // just a $ is interpreted as a $ + ], + + // any code + interpolated_compound: [ + [/\)/, '', '@pop'], + {include: '@root'}, + ], + + // whitespace & comments + whitespace: [ + [/[ \t\r\n]+/, ''], + [/#=/, 'comment', '@multi_comment'], + [/#.*$/, 'comment'], + ], + + multi_comment: [ + [/#=/, 'comment', '@push'], + [/=#/, 'comment', '@pop'], + [/=(?!#)|#(?!=)/, 'comment'], + [/[^#=]+/, 'comment'], + ] + } +}; From 39003d4b56722e7ddaad1c89df3d910afd73453a Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:33:44 -0500 Subject: [PATCH 2/6] Create julia.test.ts --- src/julia/julia.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/julia/julia.test.ts diff --git a/src/julia/julia.test.ts b/src/julia/julia.test.ts new file mode 100644 index 00000000..6e58561a --- /dev/null +++ b/src/julia/julia.test.ts @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import {testTokenization} from '../test/testRunner'; + +testTokenization('julia', [ + [{ + line: "a = 1", + tokens: [ + {startIndex: 0, type: "identifier.julia"}, + {startIndex: 1, type: ""}, + {startIndex: 2, type: "source.julia"}, + {startIndex: 3, type: ""}, + {startIndex: 4, type: "number.julia"} + ] + }], + + [{ + line: "b(c) = 2c" + tokens: [ + {startIndex: 0, type: "keyword.flow.julia"}, + {startIndex: 1, type: "delimiter.parenthesis.julia"}, + {startIndex: 2, type: "identifier.julia"}, + {startIndex: 3, type: "delimiter.parenthesis.julia"}, + {startIndex: 4, type: ""}, + {startIndex: 5, type: "source.julia"}, + {startIndex: 6, type: ""}, + {startIndex: 7, type: "number.julia"}, + {startIndex: 8, type: "identifer.julia"} + ] + }] +]); From 75b2a69851bb7fe6b4258dfbfc9b40bef93e05ee Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:36:04 -0500 Subject: [PATCH 3/6] Create julia.contribution.ts --- src/julia/julia.contribution.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/julia/julia.contribution.ts diff --git a/src/julia/julia.contribution.ts b/src/julia/julia.contribution.ts new file mode 100644 index 00000000..77d399c6 --- /dev/null +++ b/src/julia/julia.contribution.ts @@ -0,0 +1,14 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import {registerLanguage} from '../_.contribution'; + +registerLanguage({ + id: 'julia', + extensions: ['.jl'], + aliases: ['julia', 'Julia'], + loader: () => import('./julia') +}); From 75099538809f9c1da44ee4b4be28385160e333f7 Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:37:29 -0500 Subject: [PATCH 4/6] add julia --- src/monaco.contribution.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 95c20044..345fdd05 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -24,6 +24,7 @@ import './html/html.contribution'; import './ini/ini.contribution'; import './java/java.contribution'; import './javascript/javascript.contribution'; +import './julia/julia.contribution'; import './kotlin/kotlin.contribution'; import './less/less.contribution'; import './lua/lua.contribution'; From 8c06e270cd97a686fc8fdd6605f6938cd2c7621e Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:54:00 -0500 Subject: [PATCH 5/6] Added missing comma --- src/julia/julia.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/julia/julia.test.ts b/src/julia/julia.test.ts index 6e58561a..67060c0a 100644 --- a/src/julia/julia.test.ts +++ b/src/julia/julia.test.ts @@ -20,7 +20,7 @@ testTokenization('julia', [ }], [{ - line: "b(c) = 2c" + line: "b(c) = 2c", tokens: [ {startIndex: 0, type: "keyword.flow.julia"}, {startIndex: 1, type: "delimiter.parenthesis.julia"}, From 266e2c1a3917734144ca090f2b2b1316c4acef6c Mon Sep 17 00:00:00 2001 From: "alan.invents" Date: Thu, 13 Feb 2020 18:59:43 -0500 Subject: [PATCH 6/6] Fixed typo --- src/julia/julia.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/julia/julia.test.ts b/src/julia/julia.test.ts index 67060c0a..996ace09 100644 --- a/src/julia/julia.test.ts +++ b/src/julia/julia.test.ts @@ -30,7 +30,7 @@ testTokenization('julia', [ {startIndex: 5, type: "source.julia"}, {startIndex: 6, type: ""}, {startIndex: 7, type: "number.julia"}, - {startIndex: 8, type: "identifer.julia"} + {startIndex: 8, type: "identifier.julia"} ] }] ]);