Nine Parsecs from Milwaukee

    mulang

    6.0.6 • Public • Published

    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

    Install

    npm i mulang

    DownloadsWeekly Downloads

    10

    Version

    6.0.6

    License

    GPL-3.0

    Unpacked Size

    22.5 MB

    Total Files

    5

    Last publish

    Collaborators

    • julianberbel
    • flbulgarelli