pogo

A readable, DSL friendly programming language that compiles to JavaScript

BSD-2-Clause 67 个版本
安装
npm install pogo
yarn add pogo
pnpm add pogo
bun add pogo
README

Whaa?

Pogoscript is a programming language that emphasises readability, is friendly to domain specific languages and compiles to regular Javascript.

travis-ci

NPM version

NPM dependencies

Installation

Pogoscript requires node.js and npm.

npm install -g pogo

Or to install local to your project:

npm install pogo

Usage

Interactive Prompt

pogo

Executing a Script

pogo helloWorld.pogo

Debugging a Script

All the regular node debugging invocations work:

To invoke the node debugger:

pogo debug helloWorld.pogo

To allow remote debugging, e.g. with node-inspector:

pogo --debug helloWorld.pogo

If you want to break on the first line:

pogo --debug-brk helloWorld.pogo

You can also put breakpoints in your source code, just put debugger on its own line:

someFunction ()
debugger
someOtherFunction ()

Compiling a Script

pogo -c helloWorld.pogo

Will produce helloWorld.js.

Watching and Compiling

pogo -cw helloWorld.pogo

Examples!

The canonical Node.js hello world:

http = require 'http'

http.createServer @(req, res)
    res.writeHead 200 ('Content-Type': 'text/plain')
    res.end "Hello World\n"
.listen 1337 "127.0.0.1"

console.log 'Server running at http://127.0.0.1:1337/'

The canonical 99 beers on the wall:

sing (n) bottlesOfBeerOnTheWall =
    if (n > 0)
        console.log ((n) bottlesOfBeerOnTheWall)
        sing (n - 1) bottlesOfBeerOnTheWall

(n) bottlesOfBeerOnTheWall =
    "#((n) bottles) of beer on the wall, #((n) bottles) of beer.\n" +
    "Take one down, pass it around, #((n - 1) bottles) of beer on the wall."

(n) bottles =
    if (n == 0)
        "no bottles"
    else if (n == 1)
        "1 bottle"
    else
        "#(n) bottles"

sing 99 bottlesOfBeerOnTheWall

The Big Features

Arguments and Parameters

Arguments and parameters can be placed anywhere in the name of a function or method call. The careful placement of an argument or a parameter can give it a lot of meaning.

mountains = ['Everest', 'La Tournette', 'Valuga']

for each @(mountain) in (mountains)
    console.log (mountain)

Blocks

Blocks are just indented code:

after (duration, doSomething) =
    setTimeout (doSomething, duration)

(n) seconds =
    n * 1000

after (10 seconds)
    console.log "hi there!"

Self

The self variable, also known as this in JavaScript, is retained from a block's outer context:

jack = {
    name = "Jack"
    
    sayHello () =
        console.log "hi, my name is #(self.name)"
        
        after (10 seconds)
            console.log "hi! this is #(self.name) again."
}

jack.sayHello ()

But if you want and expect self to be redefined to something useful, put => before the block like so:

onEachHttpRequest (action, port: 3000) =
    server = http.createServer @(request, response)
        requestContext = {
            request = request
            response = response
        }
        
        action.call (requestContext)
        
    server.listen (port)

onEachHttpRequest =>
    self.response.end "Hello World\n"

Optional Arguments

Methods and functions can take optional arguments, in the form of a hash passed as the last argument.

webServer (port: 4567) =
    console.log "starting web server on port #(port)"

webServer ()

webServer (port: 3000)

No Built-in Keywords

There are no keywords in PogoScript. All control structures use the same syntax rules as regular functions and methods, so it's very easy to write your own control structures:

unless (condition, block) =
    if (!condition)
        block ()

unless (windSpeed > 25)
    console.log "going surfing"

What about a multi-line control structure?

renderEachIn (list, render) ifNone (none) =
    if (list.length > 0)
        content = ''

        for each @(item) in (items)
            content := content + render (item)

        content
    else
        none ()

mountains = ['Everest', 'La Tournette', 'Valuga']

renderEach @(mountain) in (mountains)
    "<li>#(mountain)</li>"
ifNone
    "<li>no mountains...</li>"

More

joshski has put together a page showing how PogoScript translates into JavaScript. You can examine the cheatsheet, or head to the home page page.

版本列表
0.10.0 2015-08-11
0.9.10 2015-02-11
0.9.9 2015-02-10
0.9.8 2015-02-02
0.9.7 2015-01-19
0.9.6 2014-10-09
0.9.5 2014-09-10
0.9.4 2014-08-07
0.9.3 2014-08-05
0.9.2 2014-08-05
0.9.1 2014-08-05
0.9.0 2014-08-04
0.8.9 2014-07-30
0.8.8 2014-07-29
0.8.7 2014-07-11
0.8.6 2014-07-10
0.8.5 2014-07-10
0.8.4 2014-07-07
0.8.3 2014-07-07
0.8.2 2014-06-30
0.8.1 2014-06-24
0.8.0 2014-06-24
0.8.0-beta7 2014-06-12
0.8.0-beta6 2014-06-12
0.8.0-beta5 2014-06-11
0.8.0-beta4 2014-06-10
0.8.0-beta3 2014-05-24
0.8.0-beta2 2014-05-15
0.8.0-beta1 2014-05-15
0.7.1 2014-05-05
0.7.0 2014-04-26
0.6.11 2014-04-26
0.6.10 2014-04-26
0.6.9 2014-04-26
0.6.8 2014-03-20
0.6.7 2014-03-19
0.6.6 2014-03-15
0.6.5 2014-01-08
0.6.4 2013-12-12
0.6.3 2013-12-01
0.6.2 2013-12-01
0.6.1 2013-11-29
0.6.0 2013-11-28
0.5.1 2013-11-17
0.5.0 2013-11-15
0.4.5 2013-10-27
0.4.4 2013-10-20
0.4.3 2013-06-19
0.4.2 2013-06-19
0.4.1 2013-06-10
0.4.0 2013-06-09
0.3.2 2013-03-24
0.3.1 2013-02-23
0.3.0 2013-02-03
0.2.1 2012-11-26
0.2.0 2012-11-26
0.1.1 2012-11-21
0.1.0 2012-11-17
0.0.9 2012-11-11
0.0.8 2012-11-07
0.0.7 2012-11-07
0.0.6 2012-11-06
0.0.5 2012-11-03
0.0.4 2012-10-29
0.0.3 2012-10-28
0.0.2 2012-10-18
0.0.1 2012-09-07