{"_id":"kobrascript","_rev":"28-463309519151455017ce343ecfc80937","name":"kobrascript","time":{"modified":"2022-06-19T09:39:12.218Z","created":"2015-03-08T00:44:53.041Z","1.8.0":"2015-03-08T00:44:53.990Z","1.8.1":"2015-03-08T00:56:32.582Z","2.0.0":"2015-07-13T01:32:28.618Z","2.1.0":"2015-07-19T22:07:38.070Z","2.1.1":"2015-07-24T06:46:44.276Z","2.2.0":"2015-08-05T04:41:57.248Z","2.2.1":"2015-08-05T04:53:17.986Z"},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}],"description":"A compiler for the KobraScript language","readme":"\n[![KobraScript Logo](https://raw.githubusercontent.com/AuthorOfTheSurf/KobraScript/master/ks-logo.jpg)](https://github.com/AuthorOfTheSurf/KobraScript)\n![Travis.CI build status](https://travis-ci.org/AuthorOfTheSurf/KobraScript.svg?branch=development)\n\nKobraScript is a language that harvests the power of JavaScript with an incredibly intuitive syntax.\n\n## Install\nYou can install KobraScript into your global environment so that you can execute KobraScript programs from anywhere. To do so, run this command:\n\n    npm install -g kobrascript\n\nYou can execute KobraScript programs like so:\n\n    kobra <name_of_program.ks>\n\nYou can also see the transpiled version of your code by running `kobrac`:\n\n    kobrac <name_of_program.ks>\n\nTo see a list of commands available, type `kobra` or `kobrac` with no arguments.\n\n\n#### Kobra Demands Respect (Hello, world!)\nSay my name...\n\n    say \"Kobra!\"                                            console.log(\"Kobra!\");\n\n#### Variable Declarations\nIn KobraScript, variable declarations are simplified to one character: `$`. Declare multiple variables at the same time with `,` or the slick `..` \"dot-dot\". KobraScript knows no semi-colons.\n\n    $ name = \"Samson\"                                       var name = \"Samson\";\n\n    $ likesMusic = true,                                    var likesMusic = true,\n      likesJazz                                                 likesJazz = undefined;\n\n    $ isRed = true                                          var isRed = true,\n    .. isFood = false                                           isFood = false,\n    .. isMine = true                                            isMine = true;\n\nVariables with uninitialized values are set to undefined.\n\n    $ total                                                 var total = undefined;\n\n#### Functions\nDeclare a function easily with `fn`. Open the block with `:`, and close using `end`, or `..`.  Also note that the `return` statement always expects an expression–use the `leave` statement to return early from a function without an expression.\n\n    fn average_intake(x):                                   function averageIntake(x) {\n        $ total = 0                                             var total = 0;\n        for ($ i = 0; i < x.length; i++):                       for (var i = 0; i < x.length; i++) {\n            total = total + x[i]                                    total = total + x[i];\n        end                                                     }\n        say total                                               console.log(total);\n        return total / x.length                                 return total / x.length;\n    end                                                     }\n\n    $  getSoup = fn (): return Res.soupOfTheDay() ..        var getSoup = function () {return Res.soupOfTheDay()},\n    .. getDrink = fn (): return Res.specdrinks ..               getDrink = function () {return Res.spacdrinks},\n    .. placeOrder = fn (item, quantity):                        placeOrder = function (item, quantity) {\n         Kitchen.addOrder(item, quantity)                           Kitchen.addOrder(item, quantity);\n       end                                                      };\n\n    fn bomb(code):                                          function bomb(code) {\n      if (code == \"Password1\"):                                 if (code === \"Password1\") {\n        leave                                                       return;\n      .. else:                                                  } else {\n        say \"Boom!\"                                                 console.log(\"Boom!\")\n      end                                                       }\n    end                                                     }\n\nSimilar to Javascript, anonymous self-calling functions are in KobraScript. These are typically used to create a private scope. In KobraScript, a closure literal may be constructed with `close`, followed by the inteded arguments as parameters enclosed in curly braces. One never has to worry about whether ones functions are being invoked on the fly. _Closed to the world, KobraScript may evaluate._\n\n    close{}:                                                (function() {\n      $ x = 10                                                  var x = 10;\n      say x                                                     console.log(x);\n    end                                                     }());\n\n    $ x = [1, 2, 3]                                         var x = [1, 2, 3];\n    close{x}:                                               (function(x) {\n      print \"I am \" + x[1] + \" good\"                            console.log(\"I am \" + x[1] + \" good\");\n    end                                                     }(x));\n\n#### Blocks\nBlocks in KobraScript are beautiful. Start a multiline block with `:` and terminate it with the clear `end`, or the elegantly-flowing `..`  \nFearlessly create a single-statement block by pointing `->` to it. Nice.\n\n    while (i--):                                            while (i--) {\n        say \"Countdown ... \" + i                                console.log(\"Countdown ... \" + i);\n    end                                                     }\n\n    fn numResponse (x):                                     function numResponse (x) {\n      if (x == 1):                                              if (x === 1) {\n        say \"that's one!\"                                           console.log(\"that's one!\");\n      .. else if (x == 2):                                      } else if (x === 2) {\n        say \"that's two!\"                                           console.log(\"that's two!\");\n      .. else:                                                  } else {\n        say \"that's somthin' else!\"                                 console.log(\"that's somthin' else!\");\n      end                                                       }\n    end                                                     }\n\n    for ($ i = 0; i < nums[\"length\"]; i++):                 for (var i = 0; i < nums.length; i++) {\n      $ p = nums[i]                                             var p = nums[i];\n      if (p) -> primes.push(p)                                  if (p) { primes.push(p) }\n    end                                                     }\n\n    if (socket)                                             if (socket) {\n      -> this.active[socket] = i++                              this.active[socket] = i++;\n                                                            }\n\n#### Conditional Statement\nIn KobraScript the `if` statement is written with a preference to `..` between conditional blocks. An `end` after the final block signals the conclusion of the statement. Kobra is cold as ice.\n\n    if (is_red && is_food):                                 if (is_red && is_food) {\n        eat()                                                   eat ();\n    .. else if (is_food && is_mine):                        } else if (is_food && is_mine) {\n        add_butter()                                            add_butter ();\n    .. else:                                                } else {\n        keep()                                                  keep();\n    end                                                     }\n\n#### Only If Statement\nBite first, ask for booleans later. Kobrascript allows a lightning-quick, conditional alternative to the garden-variety `if` statement.\n\n    only:                                                   if (feelingLucky) {\n      rollDice() .. if (feelingLucky)                           rollDice();\n                                                            }\n    only:\n      abandonShip() .. if (sinking) else:                   if (sinking) {\n      justKeepSwiming() ..                                    abandonShip();\n                                                            } else {\n                                                              justKeepSwimming();\n                                                            }\n\n#### Exchange Statement\nKobraScript utilizes a Go/Python-inspired statement in order to exchange `:=:` the values of two variables.\n\n    $ a = 2,                                                var a = 2,\n      b = 3                                                     b = 3;\n    a :=: b                                                 var swap = a; a = b; b = swap; // Awful.\n    say a   // 3                                            console.log(a);  // 3\n    say b   // 2                                            console.log(b);  // 2\n\n#### `for` and `while` loops\nFor and while loops look beautiful as expected; keyword, condition, block, nice.\n\n    $ a = 0 // A test variable for loops.                   var a = 0; // A test variable for loops.\n\n    for ($ i = 0; i < 4; i++):                              for (var i = 0; i < 4; i++) {\n        a++                                                     a++;\n    end                                                     }\n\n    while (a < 10):                                         while (a < 10) {\n        a++                                                     a++;\n    end                                                     }\n\n#### Objects\nObjects are easily specified and finely readable in KobraScript. Braces are used specifically for objects in this language, `{}` is an object (the one with no properties).\n\n    $ bicycle = {                                           var bicycle = {\n        frame: \"aluminum\",                                          frame: \"aluminum\",\n        year: 2009,                                                 year: 2009,\n        gears: 10,                                                  gears: 10,\n        speed: 12.7,                                                speed: 12.7,\n        move: fn ():                                                move: function () {\n            Transform.translate(FORWARD * this.speed)                   Transform.translate(FORWARD * this.speed);\n        ..,                                                         },\n        upgrade_speed: fn ():                                       upgradeSpeed: function () {\n            return this.speed = this.speed * 1.1                        return this.speed = this.speed * 1.1;\n        ..,                                                         },\n        get_frame: fn (): return this.frame end                     getFrame: function () {return this.frame;}\n    }                                                       }\n\n#### Arrays\nArrays in KobraScript follow normal scripting language convention.\n\n    $ protein_intake = [12, 21.3, 7.2, 20]                  var protein_intake = [12.0, 21.3, 7.2, 20.0];\n    $ enigma = [{code: '8878'}, [], false]                  var enigma = [{code: '8878'}, [], false];\n\n### Macrosyntax\n\nThis is regarded as the the most up-to-date specification of KS.\n*Except for the compiler itself of course.*\n\nKobraScript Syntax `v.2.2.0`\n\n    UNIT    ::=  PROGRAM\n\n    PROGRAM ::=  STMT+  (as BLOCK)\n\n    BLOCK   ::=  FREEBLK\n            |    SINGLE\n    FREEBLK ::=  ':'  STMT+  ('end' | '..')\n    SINGLE  ::=  '->'  STMT\n\n    STMT    ::=  VARDEC\n            |    FNDEC\n            |    'if'  '('  EXP  ')'  BLOCK\n                 ('else'  'if'  '('  EXP  ')'  BLOCK)*\n                 ('else'  '('  EXP  ')'  BLOCK)?\n            |    'only'  BLOCK  'if'  '('  EXP  ')'\n                 ('else'  BLOCK)?\n            |    'for'  '('  (VARDEC | ASSIGN (','))?  ';'  EXP  ';'  INCREMENT  ')'  BLOCK\n            |    'while'  '('  EXP  ')'  BLOCK\n            |    'break'\n            |    'continue'\n            |    'return'  EXP\n            |    'leave'\n            |    EXP\n\n    VARDEC  ::=  '$'  ID  '='  EXP  ((',' | '..')  ID  '='  EXP)*\n    FNDEC   ::=  'fn'  ID  PARAMS  BLOCK\n\n    PARAMS  ::=  '('  ID  (','  ID)*  ')'\n\n    EXP     ::=  EXP0 (('=' | '+=' | '-=' | '*=' | '/=' | '%=' | ':=:') EXP0)?\n    EXP0    ::=  EXP1 (('||' | '#') EXP1)*\n    EXP1    ::=  EXP2 ('&&' EXP2)*\n    EXP2    ::=  EXP3 (('==' | '~=' | '!=' | 'is')  EXP3)?\n    EXP3    ::=  EXP4 (('<' | '<=' | '>=' | '>')  EXP4)?\n    EXP4    ::=  EXP5 ([+-] EXP5)*\n    EXP5    ::=  EXP6 ([%*/] EXP6)*\n    EXP6    ::=  EXP7 (('**' | '-**')  EXP7)\n    EXP7    ::=  ('~!' | '~?')?  EXP8\n    EXP8    ::=  ('!' | '++' | '--' | 'new')?  EXP9\n    EXP9    ::=  EXPRT ('++' | '--' | '.' ID | '[' EXP ']' | '(' EXP (',' EXP)* ')')*\n    EXPRT   ::=  UNDEFLIT | NULLLIT | BOOLIT | STRLIT | NUMLIT\n            |    | ID | CLOSLIT | FNLIT | ARRAY | OBJECT\n            |    '(' EXP ')'\n\n    FNLIT   ::=  'fn'  (ID)? PARAMS  BLOCK\n    CLOSLIT ::=  'close'  '{'  (ID  (','  ID)*)?  '}'  BLOCK\n    ARRAYLIT::=  '['  (EXP  (','  EXP)*)?  ']'\n    OBJLIT  ::=  '{'  (PROP  (','  PROP)*)?  '}'\n    PROP    ::=  ID  ':'  EXP\n            |    STRLIT ':' EXP\n            |    NUMLIT ':' EXP\n            |    BOOLIT ':' EXP\n\n### Microsyntax\n\n    NUMLIT  ::=  -?(?:[1-9]\\d*|0)(?:.\\d+)?(?:[eE][+-]?\\d+)?\n    STRLIT  ::=  (\\\"|\\')(\\\\[bfnrtv0\\\"\\']|\\\\c[a-zA-z]|\\\\u[a-fA-F0-9]{4}|\\\\x[a-fA-F0-9]{2}|.)*\\1\n    BOOLIT  ::=  'true' | 'false'\n    UNDEFLIT::=  'undefined'\n    NULLLIT ::=  'null'\n    ID      ::=  [_a-zA-Z]\\w*\n    COMMENT ::=  '//'  TEXT  '\\n'\n","versions":{"1.8.1":{"name":"kobrascript","version":"1.8.1","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobrac.js"},"devDependencies":{"mocha":"latest","should":"latest"},"_id":"kobrascript@1.8.1","dist":{"shasum":"ddcdf7864daf7682ac152365e38191e141cc0722","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-1.8.1.tgz","integrity":"sha512-JLev22lpHTAv4ajZYC98HcFtG5okrbXQOj/HWjW8xuJ3Ub+gaLRWl0+xUmSg4Oci1t3gMCxz1tNcdM4gP9Q+MQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICZdRFOnw0ysyUY0kWXLJVWYOkZrHaF1/0Ayo7nkWap2AiEAl4m3w8t7EFg+lVkQMXNqvqL1yfHrI9CEsFfoo6E1wYw="}]},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"kobrascript","email":"edward@bramanti.org"},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]},"2.0.0":{"name":"kobrascript","version":"2.0.0","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","js-beautify":"^1.5.10","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobrac.js"},"devDependencies":{"mocha":"latest","should":"latest"},"scripts":{"test":"mocha"},"gitHead":"46591ff501a35f803e41d71bd0afd8a47984e418","_id":"kobrascript@2.0.0","_shasum":"09296ee97607979dd195da8d688f38fb9a699de8","_from":".","_npmVersion":"2.11.3","_nodeVersion":"0.12.7","_npmUser":{"name":"kobrascript","email":"kobrascript@gmail.com"},"dist":{"shasum":"09296ee97607979dd195da8d688f38fb9a699de8","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-2.0.0.tgz","integrity":"sha512-VuTzy9GIV+lbrs3EjQshov8Cs51B5V5CH8FVQzJR0p3u5CFzU8KwqR+yobmv/brFpSt4IKSfRW5EjwJ6il5+BQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHbgr6+IAmADXpOXShP6VjelgO55MkqPUple13pZa6jpAiEAx0cQSA+1kHPhntga6EEo+IKZWkL2osOAQt/X9R9NVa4="}]},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]},"2.1.0":{"name":"kobrascript","version":"2.1.0","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","js-beautify":"^1.5.10","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobra","kobrac":"./kobrac.js"},"devDependencies":{"mocha":"latest","should":"latest"},"scripts":{"test":"mocha"},"gitHead":"765cb7041cd982856eb1dccf5500c8514f4f6253","_id":"kobrascript@2.1.0","_shasum":"281712786a50e22a3a932d67dcf4406690a6e8eb","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"kobrascript","email":"kobrascript@gmail.com"},"dist":{"shasum":"281712786a50e22a3a932d67dcf4406690a6e8eb","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-2.1.0.tgz","integrity":"sha512-akeA96Q0flirhfqUNUL0j5I/QYJJhKQfooZPRKT6l1IqM52iECjS1DTIkWIBH4ZoUhFt4L43+4MkeZ7V+aZV0A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBFrhUZ3ZfJjMQCK8ZW+vnIyhg+vUoc9WQm6iRDDRQqhAiEAu20KmmLYZYvx9N2Ab1GZodH1y5Pk1ptV3gWldHQAc1U="}]},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]},"2.1.1":{"name":"kobrascript","version":"2.1.1","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","js-beautify":"^1.5.10","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobra","kobrac":"./kobrac.js"},"devDependencies":{"mocha":"latest","should":"latest"},"scripts":{"test":"mocha"},"gitHead":"a33c07d9ad9fa615dde8d6f140c7cb8d0cec92f5","_id":"kobrascript@2.1.1","_shasum":"4853a350748a10d579bfbc319780a2fc92bcdc17","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"kobrascript","email":"kobrascript@gmail.com"},"dist":{"shasum":"4853a350748a10d579bfbc319780a2fc92bcdc17","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-2.1.1.tgz","integrity":"sha512-n7G6tJczI/To95LWCzdwlm+1lphZTT5T02Dta58dkTvKiKAgaQHeYg+boMzbEGifmlI+Vgr2n6TAg3OKOseoig==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHNvT/F1IGRa9AaKUyV1u4yVEtdZ31NIytIfktnLZuTYAiEAxciQT+RFSW5Ed3C2JGu2Oc4LJW4om2z1NlR3l7p76kQ="}]},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]},"2.2.0":{"name":"kobrascript","version":"2.2.0","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","js-beautify":"^1.5.10","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobra","kobrac":"./kobra-cli.js"},"devDependencies":{"mocha":"latest","should":"latest"},"scripts":{"test":"mocha"},"gitHead":"8dca3ee17b22d1006f8be8bb6f16e89a13f0379c","_id":"kobrascript@2.2.0","_shasum":"7e32a1f50c206944d1fa7ac05ffe13f20f9d1f67","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"kobrascript","email":"kobrascript@gmail.com"},"dist":{"shasum":"7e32a1f50c206944d1fa7ac05ffe13f20f9d1f67","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-2.2.0.tgz","integrity":"sha512-Tr8Ik6kkXRZjDG9aDD5VHo80n2Kyp6UrZIeApLC4VMFE4yvNfx69l898EJCrQAF2tMcLSVvqGuG2T867SQqf5w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC+ONxie4qaN3s9AcYjd0SXlyhDwpOR1d9Vvbmhp/5pjAiEA9whpdf98Vp1NaOIwxSjTAlesjpyHOfeIp/R4pnOzh7I="}]},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]},"2.2.1":{"name":"kobrascript","version":"2.2.1","description":"A compiler for the KobraScript language","dependencies":{"byline":"latest","hashmap":"latest","js-beautify":"^1.5.10","minimist":"latest"},"main":"./kobrac.js","bin":{"kobra":"./kobra","kobrac":"./kobra-cli.js"},"devDependencies":{"mocha":"latest","should":"latest"},"scripts":{"test":"mocha"},"gitHead":"442a6e7a22cfa7e7024dd299ee5f15d8e624d723","_id":"kobrascript@2.2.1","_shasum":"d6b25492636e195706b87fd7b6e65265b038332d","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"kobrascript","email":"kobrascript@gmail.com"},"dist":{"shasum":"d6b25492636e195706b87fd7b6e65265b038332d","tarball":"https://registry.npmjs.org/kobrascript/-/kobrascript-2.2.1.tgz","integrity":"sha512-220DAKhPaXISJqJoa3bdPS8wIRrjfq/VrTKcJukKvSKEbkSzDKVq6VQr9l35YsLF1G+XvrwJPAe36jGUoDzSBQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCL4LzG0dAK9qRReRxlXi6I98DqkclTuLbzk8MCmZFJ9AIhAJHY4tXb92GOGVKovFJfIkAtlF7E/HH4rV/JfzvXB6VU"}]},"maintainers":[{"name":"kobrascript","email":"edward@bramanti.org"}]}},"dist-tags":{"latest":"2.2.1"},"readmeFilename":"README.md","users":{"kobrascript":true}}