100% Java compatibility and Functional Programming.
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
is based on java 6. It’s compiled to JVM byte code, and can collaborate with any java library.
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 extractbuild/distributions/latte-${version}.zip
in modulelatte-build
, the shell script is in thebin
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>
lt
FilesThere 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.
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
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.
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
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
run
gradle clean jar
visit the Latte WebSite
or read the mannual
Latte是一种JVM编程语言。 它非常可读,同时也非常可扩展。
Atom
上的扩展插件:
atom-latte-lang-highlighting
atom-latte-lang-ide
Gradle
Plugin :
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 以获取更多信息。
你可以直接运行脚本
latte -s script-file-path script-arguments...
或者:
开启 REPL
解释器
输入 :script <script file>
并回车
然后使用 script run
或者 script run ['string array']
来运行这个脚本
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
的插件, 这个插件可以用来编译和运行latte
源文件和脚本(script)。
添加如下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
任务之前
在同一个上级目录中创建名称为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
运行
gradle clean jar
您可以从这两个地方获取语法规则