Socket
Book a DemoInstallSign in
Socket

mulang

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mulang

An intermediate language designed to perform advanced code analysis

latest
Source
npmnpm
Version
6.0.6
Version published
Weekly downloads
66
-29.03%
Maintainers
2
Weekly downloads
 
Created
Source

Installing

As a node library

npm install mulang

As a CLI

npm install -g mulang

Using

As a node/webpack library

Expectations checking

const code = mulang.nativeCode("JavaScript", "x = 1");

code.expect("*", "Assigns:x");
// => true

code.expect("*", "Assigns:y");
// => false

code.expect("*", "Assigns:x:WithNumber:1");
// => true

code.customExpect(`
  expectation "assigns 1":
    assigns with 1;
  expectation "assigns 2":
    assigns with 2`);
// => [['assigns 1', true], ['assigns 2', false]])

AST generation

const code = mulang.nativeCode("Python", "x = 1");

code.ast
// => { tag: 'Assignment', contents: [ 'x', { tag: 'MuNumber', contents: 1 } ] }

Run analysis

const code = mulang.nativeCode("Python", "x = 1");

const result = code.analyse({expectations: [{binding: '*', inspection: 'Declares'}, {binding: '*', inspection: 'Assigns'}]})

result.expectationResults
// => [
//  { expectation: { binding: '*', inspection: 'Declares' }, result: false },
//  { expectation: { binding: '*', inspection: 'Assigns' },  result: true }
//]

You can also compute code smells:

const code = mulang.nativeCode("Python", "def increment():\n\tx += 1");

const result = code.analyse({
                expectations: [ {binding: '*', inspection: 'DeclaresProcedure:Increment'} ],
                smellsSet: { tag: 'AllSmells' }})

result.expectationResults
// => [
//  { expectation: { binding: '*', inspection: 'DeclaresProcedure:Increment' }, result: false }
// ]

result.smells
// => [
//  { binding: 'increment', inspection: 'HasDeclarationTypos:Increment' }
//]

Internationalization

mulang.I18n.locale = 'en'

mulang.I18n.translate('*', 'Declares:foo')
// => 'solution must declare <strong>foo</strong>'

Raw mulang execution

const mulang = require('mulang')
mulang.analyse({
                "sample": {
                  "tag": "CodeSample",
                  "language": "Haskell",
                  "content": "x = z + 1"
                },
                "spec": {
                  "expectations": [
                    {
                      "binding": "Intransitive:x",
                      "inspection": "Uses:z"
                    }
                  ],
                  "smellsSet": { "tag": "NoSmells" }
                }
              });

As a CLI

$ mulangjs '{
     "sample" : {
        "tag" : "CodeSample",
        "language" : "Haskell",
        "content" : "x = z + 1"
     },
     "spec" : {
        "expectations" : [
           {
              "binding" : "Intransitive:x",
              "inspection" : "Uses:z"
           }
        ],
        "smellsSet" : { "tag" : "NoSmells" }
     }
  }' | json_pp
{
   "tag" : "AnalysisCompleted",
   "expectationResults" : [
      {
         "expectation" : {
            "binding" : "Intransitive:x",
            "inspection" : "Uses:z"
         },
         "result" : true
      }
   ],
   "smells" : [],
   "outputAst" : null,
   "signatures" : []
}

Releasing

Build and publish the package to NPM with:

$ ./ghcjslib/release.sh

Try it out!

You can find an online interactive version of mulang, along with its documentation here

Keywords

ast

FAQs

Package last updated on 15 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts