Latte-lang

100% Java compatibility and Functional Programming.

MIT License

Stars
133

Latte-Lang

Latte is a JVM language. It's highly readable and extensible.

Syntax Mannual (NEW) Latte WebSite

Atom Extensions :

atom-latte-lang-highlighting atom-latte-lang-ide

Gradle Plugin :

latte-gradle-plugin

Latte supports

  • Operator Binding
  • DSL
  • Data Class
  • Pattern Matching
  • Inner Method
  • Lambda and High-Order Function
  • JSON Literal
  • Regular Expression
  • Read Eval Print Loop
  • Compiling to JavaScript
  • Latte Gradle Plugin
  • JSR 223
  • many other features

Latte is based on java 6. It's compiled to JVM byte code, and can collaborate with any java library.

How to build

JDK 1.6 or higher is the only thing required.

The project is managed by Gradle, you can use Gradle 2.12 (or higher) to build automatically A build script is also provided.

clone the repository, and run

./build.py

You will get a shell scripts. The shell scripts can help you run the repl.

The build script does not support windows. Please follow the order (latte-[class-recorder | compiler | gradle-plugin | library | build]) to run gradle clean latteBuild in each directory, then extract build/distributions/latte-${version}.zip in module latte-build, the shell script is in the bin directory.

run:

./latte

then the REPL starts

Welcome to Latte lang
Type in expressions and double Enter to have them evaluated.
Type :help for more information.
for syntax help, please visit https://github.com/wkgcass/Latte-lang/

lt> 1+1
  |
res0 : java.lang.Integer = 2

lt>

Compile lt Files

There are two ways of compiling lt files

  • use program command

      latte -c <source-directory>
    

    the detailed commands and options can be found in

      latte -help
    

or:

  • start the REPL interpreter, and construct a Compiler

      compiler = Compiler()
    

    use >> operator to specify output directory

      compiler >> '...'
      // or
      compiler >> File('...')
    

    use + operator to add class-path

      compiler + '...'
    

    use compile MAP to specify source codes to be compiled and start compiling

      compiler compile ['fileName':FileObject]
    

    usually filesInDirectory('...', regex) is used, e.g.

      compiler compile filesInDirectory('...', '.\*\\.lt'.r)
    

    these method invocations can be chained up

      Compiler() + '...cp...' >> '...output...' compile filesInDirectory('...source...', '.\*\\.lt'.r)
    

    You can write a script to configure the settings. Check build.lts.template for more info.

Scripts

  • you can run a script directly

      latte -s script-location script-arguments...
    

or:

  • start the REPL interpreter type :script <script file> and Enter

    then use script run or script run ['string array'] to run the script

JSR 223

Latte-lang supports JSR 223 specification. Use getEngineByName("Latte-lang") to retrieve the scripting engine.

ScriptEngine engine = new ScriptEngineManager().getEngineByName("Latte-lang");
Object result = engine.eval("a = 1 + 3");
System.out.println(engine.get("a"));

Since Latte-lang is a compiling language, and it's directly compiled to JVM byte code, you could even use the scripting engine in Latte source codes.

engine = ScriptEngineManager().getEngineByName("Latte-lang")
result = engine eval "a = 1 + 3"
.println result
.println engine.a

A plugin for Gradle is provided, which helps you compile latte source codes.

How to use

step1

add the plugin configuration:

buildscript {
    dependencies {
        classpath 'org.latte-lang:latte-gradle-plugin:$VERSION'
    }
}

apply plugin: 'latte'

sourceSets {
    main {
        java
        latte.srcDirs = ['src/main/latte']
        resources
    }
    test {
        java
        latte
        resources
    }
}

latteConfig {
    afterJava = true
    afterGroovy = false
    fastFail = false
}

all configurations are optional

The plugin adds compileLatte and compileTestLatte tasks, where compileLatte is before classes task, and compileTestLatte is before testClasses task

step2

create a folder named latte in the same parent directory. The directory tree should be:

src
 main
  java
   \*.java    ; java source
  latte
   \*.lt      ; latte source
  resources
      \*.lts     ; latte scripts
        other resources
 test
     java
    \*.java
   latte
    \*.lt
   resources
       \*.lts
         other resources

step3

run

gradle clean jar

Syntax

visit the Latte WebSite

or read the mannual

LatteJVM

Latte

Atom:

atom-latte-lang-highlighting atom-latte-lang-ide

Gradle Plugin :

latte-gradle-plugin

Latte

  • DSL
  • Data Class
  • Lambda
  • JSON
  • Read Eval Print Loop
  • JavaScript
  • Latte Gradle Plugin
  • JSR 223

Lattejava6JVMJava

JDK 1.6

Gradle Gradle 2.12() Build Build

clone,

./build.py

shell, shellrepl.

windowslatte-[class-recorder | compiler | gradle-plugin | library | build]gradle clean latteBuild``latte-build``build/distributions/latte-${version}.zipbinshell

:

./latte

, REPL

Welcome to Latte lang
Type in expressions and double Enter to have them evaluated.
Type :help for more information.
for syntax help, please visit https://github.com/wkgcass/Latte-lang/

lt> 1+1
  |
res0 : java.lang.Integer = 2

lt>

lt

	latte -c <source-directory>



	latte -help

:

  • REPL, Compiler

      compiler = Compiler()
    

    >>

      compiler >> '...'
      // or
      compiler >> File('...')
    

    + class-path

      compiler + '...'
    

    compile MAP

      compiler compile ['fileName':FileObject]
    

    filesInDirectory('...', regex), e.g.

      compiler compile filesInDirectory('/Users/me/src', '.\*\\.lt'.r)
    
    
    
      Compiler() + '...cp...' >> '...output...' compile filesInDirectory('...source...', '.\*\\.lt'.r)
    

    script build.lts.template

Scripts

	latte -s script-file-path script-arguments...
  • REPL :script <script file>

    script run script run ['string array']

JSR 223

Latte-langJSR223getEngineByName("Latte-lang")``ScriptEngine

ScriptEngine engine = new ScriptEngineManager().getEngineByName("Latte-lang");
Object result = engine.eval("a = 1 + 3");
System.out.println(engine.get("a"));

Latte-langJVMLatte

engine = ScriptEngineManager().getEngineByName("Latte-lang")
result = engine eval "a = 1 + 3"
.println result
.println engine.a

Gradle lattescript

step1

gradle plugin

buildscript {
    dependencies {
        classpath 'org.latte-lang:latte-gradle-plugin:$VERSION'
    }
}

apply plugin: 'latte'

sourceSets {
    main {
        java
        latte.srcDirs = ['src/main/latte']
        resources
    }
    test {
        java
        latte
        resources
    }
}

latteConfig {
    afterJava = true
    afterGroovy = false
    fastFail = false
}

compileLatte compileTestLatte compileLatte classes , compileTestLatte testClasses

step2

latte

src
 main
  java
   \*.java    ; java source
  latte
   \*.lt      ; latte source
  resources
      \*.lts     ; latte scripts
        other resources
 test
     java
    \*.java
   latte
    \*.lt
   resources
       \*.lts
         other resources

step3

gradle clean jar

Latte