6.0.6 • Published 4 years ago
mulang v6.0.6
Installing
As a node library
npm install mulangAs a CLI
npm install -g mulangUsing
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.shTry it out!
You can find an online interactive version of mulang, along with its documentation here
6.0.6
4 years ago
6.0.5
5 years ago
6.0.4
5 years ago
6.0.3
5 years ago
6.0.2
5 years ago
6.0.1
5 years ago
6.0.0
5 years ago
5.3.0
6 years ago
5.2.0
6 years ago
5.1.0
6 years ago
5.0.0
6 years ago
4.5.3
6 years ago
4.5.2
6 years ago
4.4.0
7 years ago
4.3.3
7 years ago
4.3.2-test
7 years ago
4.3.2
7 years ago
4.3.1
7 years ago
4.3.0
7 years ago