Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cuiping-monaco

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cuiping-monaco - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

5

dist/index.d.ts

@@ -1,3 +0,3 @@

import * as Monaco from 'monaco-editor';
import { Formula } from 'cuiping/core/parse';
import type * as Monaco from 'monaco-editor';
import type { Formula } from 'cuiping/core/parse';
export declare const getMonacoForCuiping: (monaco: typeof Monaco, { getFormula, markGroup }: {

@@ -11,2 +11,3 @@ getFormula?: (() => Formula | undefined) | undefined;

automaticLayout: boolean;
tabSize: number;
};

84

dist/index.js
import { GroupAttrs, BondAttrs } from 'cuiping/core/parse';
import { funcStructDefs } from 'cuiping/core/builtin';
export const getMonacoForCuiping = (monaco, { getFormula, markGroup }) => {

@@ -13,5 +14,11 @@ monaco.languages.register({ id: 'cuipingFormula' });

[/\s+/, 'space'],
[/(?=([\^_`](.|\([^)]*?\))|[^[\]{@+\-|/\\*!~=#;,]+)+)/, 'group.dlmt', '@group'],
[/\(\*/, 'comment.dlmt', '@comment'],
[/\$/, 'func', '@func'],
[/(?=([\^_`](.|\([^)]*?\))|[^[\]{@+\-|/\\*!~=#;,(']+|\((?!\*))+)/, 'group.dlmt', '@group'],
[/;/, 'semicolon']
],
'comment': [
[/([^*]|\*(?!\)))+?/, 'comment.content'],
[/\*\)/, 'comment.dlmt', '@pop']
],
'bonds': [

@@ -28,21 +35,26 @@ { include: 'root' },

[/(?=[^,:}]+)/, 'attr.dlmt', '@attr-without-value'],
[/}/, 'attrs', '@pop']
[/\s*}/, 'attrs', '@pop']
],
'attr-with-value': [
[/[^,:}]+?(?=:)/, 'attr.key'],
[/:/, 'attr.colon'],
[/\s*(&|ref)(?=\s*:)/, 'attr.key.label'],
[/\s*[^,:}]+?(?=\s*:)/, 'attr.key'],
[/\s*:\s*/, 'attr.colon'],
[/[^,}]+?(?=[,}])/, 'attr.value'],
[/,/, 'attrs.comma', '@pop'],
[/(?=})/, 'attr.dlmt', '@pop']
[/\s*,\s*/, 'attrs.comma', '@pop'],
[/(?=\s*})/, 'attr.dlmt', '@pop']
],
'attr-without-value': [
[/[^,:}]+?(?=[,}])/, 'attr.key'],
[/,/, 'attrs.comma', '@pop'],
[/(?=})/, 'attr.dlmt', '@pop']
[/\s*[^,:}]+?(?=\s*[,}])/, 'attr.key'],
[/\s*,\s*/, 'attrs.comma', '@pop'],
[/(?=\s*})/, 'attr.dlmt', '@pop']
],
'func': [
[/\w*/, 'func.name', '@pop']
],
'group': [
[/[\^_`]{/, 'group.typeset', '@group-typeset-multiple'],
[/[\^_`]/, 'group.typeset', '@group-typeset'],
[/[^[\]{@+\-|/\\*!~=#;,^_`]+/, 'group.content'],
[/(?=[[\]{@+\-|/\\*!~=#;,])/, 'group.dlmt', '@pop']
[/([^[\]{@+\-|/\\*!~=#;,^_`(']|\((?!\*))+/, 'group.content'],
[/'\w+/, 'label-abbr'],
[/(?=[[\]{@+\-|/\\*!~=#;,]|\(\*)/, 'group.dlmt', '@pop']
],

@@ -74,3 +86,6 @@ 'group-typeset-multiple': [

}));
const getRefNames = (all) => [...all.matchAll(/(&|ref)\s*:\s*(\w+)/g)];
const getLabels = (all) => [...all.matchAll(/(?<=((&|ref)\s*:\s*)|')(\w+)/g)].map(res => res[3]);
const noSuggestions = {
suggestions: []
};
monaco.languages.registerCompletionItemProvider('cuipingFormula', {

@@ -80,3 +95,3 @@ triggerCharacters: [

+ 'ABCDEFGHIJKLMNOPQRSTUCWXYZ'
+ '&'
+ '&' + '$'
],

@@ -91,5 +106,2 @@ provideCompletionItems: (model, position) => {

const all = model.getValue();
const noSuggestions = {
suggestions: []
};
const word = model.getWordUntilPosition(position);

@@ -102,9 +114,9 @@ const range = {

};
if (before.match(/(?<![\^_`]({[^}]*)?)&\w*$/) != null) { // Note: complete ref
const refNames = getRefNames(all);
if (before.match(/(?<![\^_`]({[^}]*)?|{[^}]*)&\w*$/) != null) { // Note: complete ref
const labels = getLabels(all);
range.startColumn--;
return {
suggestions: refNames.map(res => ({
label: '&' + res[2],
insertText: '&' + res[2],
suggestions: labels.map(label => ({
label: '&' + label,
insertText: '&' + label,
kind: CompletionItemKind.Reference,

@@ -115,2 +127,13 @@ range

}
if (before.match(/(?<![\^_`]({[^}]*)?|{[^}]*)\$\w*$/) != null) { // Note: complete func struct
range.startColumn--;
return {
suggestions: Object.entries(funcStructDefs).map(([name, _def]) => ({
label: '$' + name,
insertText: '$' + name,
kind: CompletionItemKind.Function,
range
}))
};
}
const attrRes = before.match(/(.)\s*{\s*([^}]*,)*[^:}]+$/);

@@ -143,5 +166,5 @@ if (attrRes != null) {

if ((refRes != null) && word?.[0] === '&') { // Note: go to definition of ref
const refNames = getRefNames(all);
const refNameNow = word.slice(1);
const refDef = refNames.find(res => res[2] === refNameNow);
const labels = getLabels(all);
const labelNow = word.slice(1);
const refDef = labels.find(label => label === labelNow);
if (refDef == null)

@@ -165,2 +188,4 @@ return null;

{ token: 'ref', foreground: 'DC68E6', fontStyle: 'italic' },
{ token: 'label-abbr', foreground: 'DC68E6' },
{ token: 'func', foreground: '12ACE8', fontStyle: 'bold' },
{ token: 'bond.type', foreground: '545A7B', fontStyle: 'bold' },

@@ -170,6 +195,10 @@ { token: 'group.typeset', foreground: 'AAAAAA', fontStyle: 'italic' },

{ token: 'attrs', foreground: '62C169' },
{ token: 'attr.key', foreground: '64D99D', fontStyle: 'bold' },
{ token: 'attr.key', foreground: '64D99D' },
{ token: 'attr.key.label', foreground: 'DC68E6' },
{ token: 'attr.colon', foreground: '89E2B5' },
{ token: 'bonds.comma', foreground: 'B7ACf0' },
{ token: 'semicolon', foreground: 'B7ACf0' }
{ token: 'semicolon', foreground: 'B7ACf0' },
{ token: 'func', foreground: '8CD7F3', fontStyle: 'bold' },
{ token: 'func.name', foreground: '40A9F1' },
{ token: 'comment', foreground: '489964', fontStyle: 'italic' }
],

@@ -205,3 +234,4 @@ colors: {

language: 'cuipingFormula',
automaticLayout: true
automaticLayout: true,
tabSize: 2
};
{
"name": "cuiping-monaco",
"version": "1.0.0",
"version": "1.1.0",
"description": "Monaco Editor extension for Cuiping formula",

@@ -11,3 +11,3 @@ "main": "./dist/index.js",

"dependencies": {
"cuiping": "^1.7.0",
"cuiping": "^2.0.0",
"monaco-editor": "^0.34.1"

@@ -14,0 +14,0 @@ },

@@ -1,3 +0,5 @@

import * as Monaco from 'monaco-editor'
import { GroupAttrs, BondAttrs, Formula } from 'cuiping/core/parse'
import type * as Monaco from 'monaco-editor'
import type { Formula } from 'cuiping/core/parse'
import { GroupAttrs, BondAttrs } from 'cuiping/core/parse'
import { funcStructDefs } from 'cuiping/core/builtin'

@@ -22,5 +24,11 @@ export const getMonacoForCuiping = (monaco: typeof Monaco, {

[ /\s+/, 'space' ],
[ /(?=([\^_`](.|\([^)]*?\))|[^[\]{@+\-|/\\*!~=#;,]+)+)/, 'group.dlmt', '@group' ],
[ /\(\*/, 'comment.dlmt', '@comment' ],
[ /\$/, 'func', '@func' ],
[ /(?=([\^_`](.|\([^)]*?\))|[^[\]{@+\-|/\\*!~=#;,(']+|\((?!\*))+)/, 'group.dlmt', '@group' ],
[ /;/, 'semicolon' ]
],
'comment': [
[ /([^*]|\*(?!\)))+?/, 'comment.content' ],
[ /\*\)/, 'comment.dlmt', '@pop' ]
],
'bonds': [

@@ -37,21 +45,26 @@ { include: 'root' },

[ /(?=[^,:}]+)/, 'attr.dlmt', '@attr-without-value' ],
[ /}/, 'attrs', '@pop' ]
[ /\s*}/, 'attrs', '@pop' ]
],
'attr-with-value': [
[ /[^,:}]+?(?=:)/, 'attr.key' ],
[ /:/, 'attr.colon' ],
[ /\s*(&|ref)(?=\s*:)/, 'attr.key.label' ],
[ /\s*[^,:}]+?(?=\s*:)/, 'attr.key' ],
[ /\s*:\s*/, 'attr.colon' ],
[ /[^,}]+?(?=[,}])/, 'attr.value' ],
[ /,/, 'attrs.comma', '@pop' ],
[ /(?=})/, 'attr.dlmt', '@pop' ]
[ /\s*,\s*/, 'attrs.comma', '@pop' ],
[ /(?=\s*})/, 'attr.dlmt', '@pop' ]
],
'attr-without-value': [
[ /[^,:}]+?(?=[,}])/, 'attr.key' ],
[ /,/, 'attrs.comma', '@pop' ],
[ /(?=})/, 'attr.dlmt', '@pop' ]
[ /\s*[^,:}]+?(?=\s*[,}])/, 'attr.key' ],
[ /\s*,\s*/, 'attrs.comma', '@pop' ],
[ /(?=\s*})/, 'attr.dlmt', '@pop' ]
],
'func': [
[ /\w*/, 'func.name', '@pop' ]
],
'group': [
[ /[\^_`]{/, 'group.typeset', '@group-typeset-multiple' ],
[ /[\^_`]/, 'group.typeset', '@group-typeset' ],
[ /[^[\]{@+\-|/\\*!~=#;,^_`]+/, 'group.content' ],
[ /(?=[[\]{@+\-|/\\*!~=#;,])/, 'group.dlmt', '@pop' ]
[ /([^[\]{@+\-|/\\*!~=#;,^_`(']|\((?!\*))+/, 'group.content' ],
[ /'\w+/, 'label-abbr' ],
[ /(?=[[\]{@+\-|/\\*!~=#;,]|\(\*)/, 'group.dlmt', '@pop' ]
],

@@ -88,4 +101,9 @@ 'group-typeset-multiple': [

const getRefNames = (all: string) => [ ...all.matchAll(/(&|ref)\s*:\s*(\w+)/g) ]
const getLabels = (all: string) =>
[ ...all.matchAll(/(?<=((&|ref)\s*:\s*)|')(\w+)/g) ].map(res => res[3])
const noSuggestions = {
suggestions: []
}
monaco.languages.registerCompletionItemProvider('cuipingFormula', {

@@ -95,3 +113,3 @@ triggerCharacters: [

+ 'ABCDEFGHIJKLMNOPQRSTUCWXYZ'
+ '&'
+ '&' + '$'
],

@@ -106,9 +124,3 @@ provideCompletionItems: (model, position): CompletionList => {

const all = model.getValue()
const noSuggestions = {
suggestions: []
}
const word = model.getWordUntilPosition(position)
const range = {

@@ -121,9 +133,9 @@ startLineNumber: position.lineNumber,

if (before.match(/(?<![\^_`]({[^}]*)?)&\w*$/) != null) { // Note: complete ref
const refNames = getRefNames(all)
if (before.match(/(?<![\^_`]({[^}]*)?|{[^}]*)&\w*$/) != null) { // Note: complete ref
const labels = getLabels(all)
range.startColumn --
return {
suggestions: refNames.map(res => ({
label: '&' + res[2],
insertText: '&' + res[2],
suggestions: labels.map(label => ({
label: '&' + label,
insertText: '&' + label,
kind: CompletionItemKind.Reference,

@@ -135,2 +147,14 @@ range

if (before.match(/(?<![\^_`]({[^}]*)?|{[^}]*)\$\w*$/) != null) { // Note: complete func struct
range.startColumn --
return {
suggestions: Object.entries(funcStructDefs).map(([ name, _def ]) => ({
label: '$' + name,
insertText: '$' + name,
kind: CompletionItemKind.Function,
range
}))
}
}
const attrRes = before.match(/(.)\s*{\s*([^}]*,)*[^:}]+$/)

@@ -164,5 +188,5 @@ if (attrRes != null) {

if ((refRes != null) && word?.[0] === '&') { // Note: go to definition of ref
const refNames = getRefNames(all)
const refNameNow = word.slice(1)
const refDef = refNames.find(res => res[2] === refNameNow)
const labels = getLabels(all)
const labelNow = word.slice(1)
const refDef = labels.find(label => label === labelNow)
if (refDef == null) return null

@@ -187,2 +211,4 @@ const [ refDefPosition ] = model.findMatches(refDef[0], true, false, true, null, false)

{ token: 'ref', foreground: 'DC68E6', fontStyle: 'italic' },
{ token: 'label-abbr', foreground: 'DC68E6' },
{ token: 'func', foreground: '12ACE8', fontStyle: 'bold' },
{ token: 'bond.type', foreground: '545A7B', fontStyle: 'bold' },

@@ -192,6 +218,10 @@ { token: 'group.typeset', foreground: 'AAAAAA', fontStyle: 'italic' },

{ token: 'attrs', foreground: '62C169' },
{ token: 'attr.key', foreground: '64D99D', fontStyle: 'bold' },
{ token: 'attr.key', foreground: '64D99D' },
{ token: 'attr.key.label', foreground: 'DC68E6' },
{ token: 'attr.colon', foreground: '89E2B5' },
{ token: 'bonds.comma', foreground: 'B7ACf0' },
{ token: 'semicolon', foreground: 'B7ACf0' }
{ token: 'semicolon', foreground: 'B7ACf0' },
{ token: 'func', foreground: '8CD7F3', fontStyle: 'bold' },
{ token: 'func.name', foreground: '40A9F1' },
{ token: 'comment', foreground: '489964', fontStyle: 'italic' }
],

@@ -228,3 +258,4 @@ colors: {

language: 'cuipingFormula',
automaticLayout: true
automaticLayout: true,
tabSize: 2
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc