-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f576f6e
Showing
114 changed files
with
29,173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ecal | ||
/.cache | ||
/.cover | ||
/.ecal_console_history | ||
/coverage.txt | ||
/coverage.out | ||
/coverage.html | ||
/dist | ||
/build | ||
/stdlib/stdlib_gen.go | ||
/ecal-support/node_modules | ||
/ecal-support/out | ||
/ecal-support/*.vsix | ||
/ecal-support/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2019 Matthias Ladkau | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
export NAME=ecal | ||
export TAG=`git describe --abbrev=0 --tags` | ||
export CGO_ENABLED=0 | ||
export GOOS=linux | ||
|
||
all: build | ||
clean: | ||
rm -f ecal | ||
|
||
mod: | ||
go mod init || true | ||
go mod tidy | ||
test: | ||
go test -p 1 ./... | ||
cover: | ||
go test -p 1 --coverprofile=coverage.out ./... | ||
go tool cover --html=coverage.out -o coverage.html | ||
sh -c "open coverage.html || xdg-open coverage.html" 2>/dev/null | ||
fmt: | ||
gofmt -l -w -s . | ||
|
||
vet: | ||
go vet ./... | ||
|
||
generate: | ||
go generate devt.de/krotik/ecal/stdlib/generate | ||
|
||
build: clean mod generate fmt vet | ||
go build -ldflags "-s -w" -o $(NAME) cli/*.go | ||
|
||
build-mac: clean mod generate fmt vet | ||
GOOS=darwin GOARCH=amd64 go build -o $(NAME).mac cli/*.go | ||
|
||
build-win: clean mod generate fmt vet | ||
GOOS=windows GOARCH=amd64 go build -o $(NAME).exe cli/*.go | ||
|
||
build-arm7: clean mod generate fmt vet | ||
GOOS=linux GOARCH=arm GOARM=7 go build -o $(NAME).arm7 cli/*.go | ||
|
||
build-arm8: clean mod generate fmt vet | ||
GOOS=linux GOARCH=arm64 go build -o $(NAME).arm8 cli/*.go | ||
|
||
dist: build build-win build-mac build-arm7 build-arm8 | ||
rm -fR dist | ||
|
||
mkdir -p dist/$(NAME)_linux_amd64 | ||
mv $(NAME) dist/$(NAME)_linux_amd64 | ||
cp LICENSE dist/$(NAME)_linux_amd64 | ||
cp NOTICE dist/$(NAME)_linux_amd64 | ||
tar --directory=dist -cz $(NAME)_linux_amd64 > dist/$(NAME)_$(TAG)_linux_amd64.tar.gz | ||
|
||
mkdir -p dist/$(NAME)_darwin_amd64 | ||
mv $(NAME).mac dist/$(NAME)_darwin_amd64/$(NAME) | ||
cp LICENSE dist/$(NAME)_darwin_amd64 | ||
cp NOTICE dist/$(NAME)_darwin_amd64 | ||
tar --directory=dist -cz $(NAME)_darwin_amd64 > dist/$(NAME)_$(TAG)_darwin_amd64.tar.gz | ||
|
||
mkdir -p dist/$(NAME)_windows_amd64 | ||
mv $(NAME).exe dist/$(NAME)_windows_amd64 | ||
cp LICENSE dist/$(NAME)_windows_amd64 | ||
cp NOTICE dist/$(NAME)_windows_amd64 | ||
tar --directory=dist -cz $(NAME)_windows_amd64 > dist/$(NAME)_$(TAG)_windows_amd64.tar.gz | ||
|
||
mkdir -p dist/$(NAME)_arm7 | ||
mv $(NAME).arm7 dist/$(NAME)_arm7 | ||
cp LICENSE dist/$(NAME)_arm7 | ||
cp NOTICE dist/$(NAME)_arm7 | ||
tar --directory=dist -cz $(NAME)_arm7 > dist/$(NAME)_$(TAG)_arm7.tar.gz | ||
|
||
mkdir -p dist/$(NAME)_arm8 | ||
mv $(NAME).arm8 dist/$(NAME)_arm8 | ||
cp LICENSE dist/$(NAME)_arm8 | ||
cp NOTICE dist/$(NAME)_arm8 | ||
tar --directory=dist -cz $(NAME)_arm8 > dist/$(NAME)_$(TAG)_arm8.tar.gz | ||
|
||
sh -c 'cd dist; sha256sum *.tar.gz' > dist/checksums.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ECAL - Event Condition Action Language | ||
Copyright (c) 2020 Matthias Ladkau |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
ECAL | ||
==== | ||
|
||
<p align="center"> | ||
<img height="150px" style="height:150px;" src="ecal-support/images/logo.png"> | ||
</p> | ||
|
||
ECAL is an ECA (Event Condition Action) language for concurrent event processing. ECAL can define event-based systems using rules which are triggered by events. ECAL is intended to be embedded into other software to provide an easy to use scripting language which can react to external events. | ||
|
||
Features | ||
-------- | ||
- Simple intuitive syntax | ||
- Minimalistic base language (by default only writing to a log is supported) | ||
- Language can be easily extended either by auto generating bridge adapters to Go functions or by adding custom function into the stdlib | ||
- External events can be easily pushed into the interpreter and scripts written in ECAL can react to these events. | ||
- Simple but powerful concurrent event-based processing supporting priorities and scoping for control flow. | ||
- Handling event rules can match on event state and rules can suppress each other. | ||
|
||
### Getting started | ||
|
||
Clone the repository and build the ECAL executable with a simple `make` command. You need Go 1.14 or higher. | ||
|
||
Run `./ecal` to start an interactive session. You can now write simple one line statements and evaluate them: | ||
|
||
``` | ||
>>>a:=2;b:=a*4;a+b | ||
10 | ||
>>>"Result is {{a+b}}" | ||
Result is 10 | ||
``` | ||
|
||
Close the interpreter by pressing <ctrl>+d and change into the directory `examples/fib`. | ||
There are 2 ECAL files in here: | ||
|
||
lib.ecal | ||
``` | ||
# Library for fib | ||
/* | ||
fib calculates the fibonacci series using recursion. | ||
*/ | ||
func fib(n) { | ||
if (n <= 1) { | ||
return n | ||
} | ||
return fib(n-1) + fib(n-2) | ||
} | ||
``` | ||
|
||
fib.ecal | ||
``` | ||
import "lib.ecal" as lib | ||
for a in range(2, 20, 2) { | ||
log("fib({{a}}) = ", lib.fib(a)) | ||
} | ||
``` | ||
|
||
Run the ECAL program with: `sh run.sh`. The output should be like: | ||
``` | ||
$ sh run.sh | ||
2000/01/01 12:12:01 fib(2) = 1 | ||
2000/01/01 12:12:01 fib(4) = 3 | ||
2000/01/01 12:12:01 fib(6) = 8 | ||
2000/01/01 12:12:01 fib(8) = 21 | ||
2000/01/01 12:12:01 fib(10) = 55 | ||
2000/01/01 12:12:01 fib(12) = 144 | ||
2000/01/01 12:12:02 fib(14) = 377 | ||
2000/01/01 12:12:02 fib(16) = 987 | ||
2000/01/01 12:12:02 fib(18) = 2584 | ||
2000/01/01 12:12:02 fib(20) = 6765 | ||
``` | ||
|
||
The interpreter can be run in debug mode which adds debug commands to the console. Run the ECAL program in debug mode with: `sh debug.sh` - this will also start a debug server which external development environments can connect to. There is a [VSCode integration](ecal-support/README.md) available which allows debugging via a graphical interface. | ||
|
||
### Further Reading: | ||
|
||
- [ECA Language](ecal.md) | ||
- [ECA Engine](engine.md) | ||
- [VSCode integration](ecal-support/README.md) | ||
|
||
License | ||
------- | ||
ECAL source code is available under the [MIT License](/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* ECAL | ||
* | ||
* Copyright 2020 Matthias Ladkau. All rights reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the MIT | ||
* License, If a copy of the MIT License was not distributed with this | ||
* file, You can obtain one at https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"devt.de/krotik/ecal/cli/tool" | ||
"devt.de/krotik/ecal/config" | ||
) | ||
|
||
func main() { | ||
|
||
tool.RunPackedBinary() // See if we try to run a standalone binary | ||
|
||
// Initialize the default command line parser | ||
|
||
flag.CommandLine.Init(os.Args[0], flag.ContinueOnError) | ||
|
||
// Define default usage message | ||
|
||
flag.Usage = func() { | ||
|
||
// Print usage for tool selection | ||
|
||
fmt.Println(fmt.Sprintf("Usage of %s <tool>", os.Args[0])) | ||
fmt.Println() | ||
fmt.Println(fmt.Sprintf("ECAL %v - Event Condition Action Language", config.ProductVersion)) | ||
fmt.Println() | ||
fmt.Println("Available commands:") | ||
fmt.Println() | ||
fmt.Println(" console Interactive console (default)") | ||
fmt.Println(" debug Run in debug mode") | ||
fmt.Println(" format Format all ECAL files in a directory structure") | ||
fmt.Println(" pack Create a single executable from ECAL code") | ||
fmt.Println(" run Execute ECAL code") | ||
fmt.Println() | ||
fmt.Println(fmt.Sprintf("Use %s <command> -help for more information about a given command.", os.Args[0])) | ||
fmt.Println() | ||
} | ||
|
||
// Parse the command bit | ||
|
||
if err := flag.CommandLine.Parse(os.Args[1:]); err == nil { | ||
interpreter := tool.NewCLIInterpreter() | ||
|
||
if len(flag.Args()) > 0 { | ||
|
||
arg := flag.Args()[0] | ||
|
||
if arg == "console" { | ||
err = interpreter.Interpret(true) | ||
} else if arg == "run" { | ||
err = interpreter.Interpret(false) | ||
} else if arg == "debug" { | ||
debugInterpreter := tool.NewCLIDebugInterpreter(interpreter) | ||
err = debugInterpreter.Interpret() | ||
} else if arg == "pack" { | ||
packer := tool.NewCLIPacker() | ||
err = packer.Pack() | ||
} else if arg == "format" { | ||
err = tool.Format() | ||
} else { | ||
flag.Usage() | ||
} | ||
|
||
} else if err == nil { | ||
|
||
err = interpreter.Interpret(true) | ||
} | ||
|
||
if err != nil { | ||
fmt.Println(fmt.Sprintf("Error: %v", err)) | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.