latte-compiler

The latte-lang compiler project, which contains compiler and runtime required library.

License

License

GroupId

GroupId

org.latte-lang
ArtifactId

ArtifactId

latte-compiler
Last Version

Last Version

0.0.10-ALPHA
Release Date

Release Date

Type

Type

jar
Description

Description

latte-compiler
The latte-lang compiler project, which contains compiler and runtime required library.
Project URL

Project URL

http://latte-lang.org
Source Code Management

Source Code Management

https://github.com/wkgcass/Latte-lang

Download latte-compiler

How to add to project

<!-- https://jarcasting.com/artifacts/org.latte-lang/latte-compiler/ -->
<dependency>
    <groupId>org.latte-lang</groupId>
    <artifactId>latte-compiler</artifactId>
    <version>0.0.10-ALPHA</version>
</dependency>
// https://jarcasting.com/artifacts/org.latte-lang/latte-compiler/
implementation 'org.latte-lang:latte-compiler:0.0.10-ALPHA'
// https://jarcasting.com/artifacts/org.latte-lang/latte-compiler/
implementation ("org.latte-lang:latte-compiler:0.0.10-ALPHA")
'org.latte-lang:latte-compiler:jar:0.0.10-ALPHA'
<dependency org="org.latte-lang" name="latte-compiler" rev="0.0.10-ALPHA">
  <artifact name="latte-compiler" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.latte-lang', module='latte-compiler', version='0.0.10-ALPHA')
)
libraryDependencies += "org.latte-lang" % "latte-compiler" % "0.0.10-ALPHA"
[org.latte-lang/latte-compiler "0.0.10-ALPHA"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Latte-Lang

Join the chat at https://gitter.im/latte-lang/Lobby

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

Gradle Plugin

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

中文版 Chinese Version README

Latte是一种JVM编程语言。 它非常可读,同时也非常可扩展。

语法规则
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
  • 许多其它特性

Latte基于java6。它被编译到JVM字节码,可以与任何Java类库完美互通。

如何构建工程

环境仅仅需要 JDK 1.6 或更高

本工程使用 Gradle 进行管理,所以您也可以使用 Gradle 2.12(或更高) 进行自动Build
此外还提供了一个Build脚本

clone这个仓库,然后执行

./build.py

你将会获取一个shell脚本, shell脚本可以快捷地开启repl.

构建脚本不支持windows,请按latte-[class-recorder | compiler | gradle-plugin | library | build]顺序依次进入目录执行gradle clean latteBuild,并解压latte-build模块的build/distributions/latte-${version}.zip,其中的bin目录为shell脚本。

执行:

./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-lang支持JSR223规范。使用getEngineByName("Latte-lang")来获取ScriptEngine

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

由于Latte-lang是一种编译型语言,并且它直接编译到JVM字节码,所以你甚至可以在Latte源代码中使用脚本引擎。

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

Gradle 插件

提供了一个Gradle的插件, 这个插件可以用来编译和运行latte源文件和脚本(script)。

如何使用

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
}

所有的配置项都是可选的

插件添加了 compileLattecompileTestLatte 任务。compileLatteclasses 任务之前, compileTestLattetestClasses 任务之前

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 主页

Versions

Version
0.0.10-ALPHA
0.0.9.1-ALPHA
0.0.9-ALPHA
0.0.8-ALPHA
0.0.7-ALPHA
0.0.6-ALPHA
0.0.5-ALPHA
0.0.4-ALPHA
0.0.3-ALPHA