Giter Site home page Giter Site logo

ivoke / codemirror-lang-dentaku Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dcflw/codemirror-lang-dentaku

0.0 0.0 0.0 82 KB

CodeMirror support for the Dentaku formula language

Home Page: https://www.npmjs.com/package/codemirror-lang-dentaku

License: ISC License

JavaScript 3.73% TypeScript 94.36% HTML 1.92%

codemirror-lang-dentaku's Introduction

Dentaku formula language support for CodeMirror

Dentaku is a parser and evaluator of formulas for Ruby. This package is language support of this formula language for CodeMirror.

Installation & usage

npm install --save codemirror codemirror-lang-dentaku
import { EditorView } from "codemirror";
import { dentaku } from "codemirror-lang-dentaku";

new EditorView({
  extensions: [dentaku()],
});

Features

  • Syntax highlighting (except case statements)
  • Autocompletion for known variables and built-in functions
  • Linting for syntax errors and undefined variables

This package doesn't offer support for everything that Dentaku offers, see the list of missing features below.

Configuration

The main export, dentaku, comes packaged with linting and autocompletion that you can configure:

dentaku({ completionOptions, linterOptions });

Autocompletion (completionOptions)

export interface DentakuLanguageCompletionOptions {
  /**
   * CodeMirror `Completion` objects for known variables.
   *
   * @example
   * ["a", "b"].map(name => ({ label: name, type: "variable" }))
   */
  variableEntries?: Array<Completion>;
  /**
   * Converter of built-in Dentaku functions into `Completion` objects.
   * Allows you to add additional information to completions like descriptions.
   */
  makeEntryForBuiltInFunctions?: (
    name: (typeof builtInFunctions)[number]
  ) => Completion | null | false;
  /**
   * Converter of built-in Dentaku operators into `Completion` objects.
   * Allows you to add additional information to completions like descriptions.
   */
  makeEntryForBuiltInOperators?: (
    name: (typeof builtInOperators)[number]
  ) => Completion | null | false;
}

Linting (linterOptions)

The linterOptions object is of type DentakuLinterOptions & { codeMirrorConfig?: Parameters<typeof linter>[1] } (see linter).
This means that, apart from allowing fields from DentakuLinterOptions described below, the linterOptions also allows an optional codeMirrorConfig field that lets you specify options for the CodeMirror linter function (linter(lintSource, options)).

export interface DentakuLinterOptions {
  /** List of variable names to not treat as undefined. */
  knownVariables?: Array<string>;
  /** Custom error messages. */
  messages?: ErrorMessages;
}

/** Message codes that can be overridden with custom messages. */
export interface ErrorMessages {
  /** Generic "invalid syntax" message when no better message can be inferred. */
  invalidSyntax: string;
  /** Missing a closing bracket in a list of function arguments. */
  closingBracketMissing: string;
  /** Expected a comma before this function argument. */
  expectedCommaBefore: string;
  /** Expected an operator before this expression. */
  expectedOperatorBefore: string;
  /** The function name needs parentheses to be called. */
  callParenthesesMissing: string;
  /** This variable is not defined. */
  undefinedVariable: string;
  /** Expected at least one parameter in a function call. */
  expectedAtLeastOneParameter: string;
  /** Expected that many parameters, found this many. */
  parameterCountMismatch: (thatMany: number, thisMany: number) => string;
}

Missing features

These features aren't on our roadmap because we don't use them currently, but contributions are highly welcome!

  • Hexadecimal number literals (e.g., 0xFF)
  • Logic operators as operators (e.g., a AND b), functions are supported though (e.g, and(a, b))
  • Syntax highlighting of case statements
  • Autocompletion for custom functions
  • Linting argument counts of custom functions (including functions that take no arguments)
  • Linting argument counts of functions with optional arguments
  • Customizing the severity of lint errors
  • Auto-fixing for fixable lint errors

codemirror-lang-dentaku's People

Contributors

illright avatar mattarau avatar ocheben avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.