new features, found in 'todo'

This commit is contained in:
Ugric committed 2022-06-29 23:41:52 +01:00
1 parent 3c785f11b7
commit af27ea0630
13 files changed
+346 -151

No files matched your search

-27
View File
@@ -1,27 +0,0 @@
on:
release:
types: [created]
jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
exclude:
- goarch: "386"
goos: darwin
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.29
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz"
project_path: "./"
binary_name: "argon-lang/argon"
+1 -2
View File
@@ -174,8 +174,7 @@ log(1 or 2)
## How do I run Argon?
Setup:
- download the Argon executable for [Windows](https://github.com/Ugric/Argon/raw/main/dist/Windows/argon.exe), [MacOS](https://github.com/Ugric/Argon/raw/main/dist/macOS/argon) or [Linux](https://github.com/Ugric/Argon/raw/main/dist/Linux/argon)
- *coming soon...*
Run a file:
+27 -1
View File
@@ -1,3 +1,29 @@
# make PI variable with PI to 1000 digits (may not be completely parsed)
PI = 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989e-1000
sub factorial(num) [
num = whole(num)
answer = 1
i = 2
while i < num+1 [
answer = answer * i
i = i + 1
]
return answer
]
# currently under development, DO NOT USE IN PRODUCTION!
sub _sine(theta) [
theta = ((theta + PI) % (2 * PI)) - PI
result = 0
termsign = 1
power = 1
i = 0
while i < 100 [
result = result + ((theta ** power) / factorial(power)) * termsign
termsign = 0 - termsign
power = power + 2
]
return result
]
+23 -6
View File
@@ -5,12 +5,13 @@ import (
"fmt"
"math"
"os"
"strings"
)
func ArgonLog(x ...any) any {
output := []any{}
for i := 0; i < len(x); i++ {
output = append(output, anyToArgon(x[i]))
output = append(output, anyToArgon(x[i], false))
}
fmt.Println(output...)
return nil
@@ -21,7 +22,7 @@ func ArgonNumber(x ...any) any {
}
func ArgonString(x ...any) any {
return (anyToArgon(x[0]))
return (anyToArgon(x[0], true))
}
func ArgonWhole(x ...any) any {
@@ -64,15 +65,31 @@ SOFTWARE.`)
return nil
}
func exec(code string) any {
runStr(code)
func exec(x ...any) any {
runStr(x[0].(string))
return nil
}
func eval(opperator string) any {
func eval(x ...any) any {
resp, _ := translateprocess(code{
code: opperator,
code: x[0].(string),
line: 0,
})
return resp
}
func ArgonAppend(x ...any) any {
return append(x[0].([]any), x[1])
}
func ArgonExtend(x ...any) any {
return append(x[0].([]any), x[1].([]any)...)
}
func ArgonLen(x ...any) any {
return len(x[0].([]any))
}
func ArgonJoin(x ...any) any {
return strings.Join(x[0].([]string), x[1].(string))
}
+13
View File
@@ -55,3 +55,16 @@ type returnType struct {
type breakType struct {
line int
}
type continueType struct {
line int
}
type itemsType struct {
vals []any
line int
}
type closeIndent struct {
line int
}
+79
View File
@@ -0,0 +1,79 @@
client
proto udp
explicit-exit-notify
remote 212.71.237.189 60005
dev tun
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
verify-x509-name server_wnJuJy53oNsHdwUB name
auth SHA256
auth-nocache
cipher AES-128-GCM
tls-client
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
ignore-unknown-option block-outside-dns
setenv opt block-outside-dns # Prevent Windows 10 DNS leak
verb 3
<ca>
-----BEGIN CERTIFICATE-----
MIIB1zCCAX2gAwIBAgIUb8tI/ox5s8DPwc13FER4ckU0yFQwCgYIKoZIzj0EAwIw
HjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjAzMDcwOTU3MjZa
Fw0zMjAzMDQwOTU3MjZaMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJSUhNaksw
WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARC7zM+9KYCZIVXl7i38BCK62wYu8W4
LrTFpFOK7DI7uaFcT544rEzDQIz3JY2HYMxN+nOtOybxfioHkZtvUUkao4GYMIGV
MB0GA1UdDgQWBBSj9j7NNN2V1z2MvYTkeRGGDLsndjBZBgNVHSMEUjBQgBSj9j7N
NN2V1z2MvYTkeRGGDLsndqEipCAwHjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJ
SE1qS4IUb8tI/ox5s8DPwc13FER4ckU0yFQwDAYDVR0TBAUwAwEB/zALBgNVHQ8E
BAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANXx1cZ+WhaXaya/I0Z+XRm3oMq6Jx3W
A65DUw4GKAOJAiBnL44bRCoA74kU755wau0i4IThZC5QLNoY4CJ82CaooQ==
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MIIB4DCCAYWgAwIBAgIRALja307VuXV/gGvUkGElDBkwCgYIKoZIzj0EAwIwHjEc
MBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjA2MjkxNjU0MzZaFw0y
NDEwMDExNjU0MzZaMBcxFTATBgNVBAMMDGdlb3JnZS1waG9uZTBZMBMGByqGSM49
AgEGCCqGSM49AwEHA0IABCslkMIcIiB5E7FaC3dTC7/iapKI9bexr9NahwMjd7aS
L/G4zlh+JCIH8A65y1DCzCazlJ3bYX7Rja9iXx2mRWCjgaowgacwCQYDVR0TBAIw
ADAdBgNVHQ4EFgQUiilqCz4C01AgMbX+j3GRkK6oOfswWQYDVR0jBFIwUIAUo/Y+
zTTdldc9jL2E5HkRhgy7J3ahIqQgMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJ
SUhNakuCFG/LSP6MebPAz8HNdxREeHJFNMhUMBMGA1UdJQQMMAoGCCsGAQUFBwMC
MAsGA1UdDwQEAwIHgDAKBggqhkjOPQQDAgNJADBGAiEAjrzNh3gFr1EGIcVwzvwH
lWswm8KkIPLHuuQZisqGBokCIQDX4FGUbyDbXmVVD4W5zU9mCQ5Qj37IlEpUMFcM
1Ey1lQ==
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg1lNu8HVoPPre6s9G
/mRZ8uIEFCweqCzVThUPioXHaVehRANCAAQrJZDCHCIgeROxWgt3Uwu/4mqSiPW3
sa/TWocDI3e2ki/xuM5YfiQiB/AOuctQwswms5Sd22F+0Y2vYl8dpkVg
-----END PRIVATE KEY-----
</key>
<tls-crypt>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
b827cd4cb18dc59de1bbd785f513de31
fa2b3bb1d916892b06c2284f139d09d4
6c034d7aeb5f30401a28dce36ded937c
9ed60e0f6c07f577776a72fc6e1d9902
7ff102bf78d43c8600e9a26498ccddbb
e54e7cabc1963cc18df35a4237944094
ceec82ecb6d221bd528b6d49c07ed3b9
689892c542e517a37679cf685bca2638
34db373071aaf06416704287a8ed0ae8
1b893b82f6b2a595f9be96148b03e141
16b683216a8c83c6001eef69a9bff581
10e38b20deae2337ea3a3ce1e5562146
aa4263b7fc79b7fb2dd23ea5d6bac5cf
ee0e70e23097a56244c5bbbf3c91a1f2
c7be0a74cf6b31a5032f2d24cdffeaba
4daa8b7f124018cc946b8cca0d07844b
-----END OpenVPN Static key V1-----
</tls-crypt>
+8 -8
View File
@@ -1,8 +1,8 @@
i = 0
while yes [
i = i + 1
log(i)
if i > 10 [
break
]
]
const aspect = input('aspect ratio: ')
const width = input('width: ') / 25.6
const height = width / aspect;
const diagonal = (width**2 + height ** 2) ** (1/2)
log(diagonal, 'inches')
+1 -1
View File
@@ -51,7 +51,7 @@ func importMod(path string) {
func runStr(str string) [][]any {
translated := translate(str)
ty, _, resp := run(translated, make(map[string]variableValue))
ty, _, resp := run(translated, []map[string]variableValue{vars})
if ty != nil {
log.Fatal(ty, " at top level")
}
+128 -83
View File
@@ -6,21 +6,22 @@ import (
"math"
"reflect"
"strconv"
"strings"
)
var runop func(codeseg any, localvars map[string]variableValue) (any, any)
var runop func(codeseg any, vargroups []map[string]variableValue) (any, any)
func init() {
runop = runprocess
}
func run(lines []any, localvars map[string]variableValue) (any, any, [][]any) {
func run(lines []any, vargroups []map[string]variableValue) (any, any, [][]any) {
output := ([][]any{})
for i := 0; i < len(lines); i++ {
if lines[i] != nil {
val, ty := runprocess(lines[i], localvars)
val, ty := runprocess(lines[i], vargroups)
output = append(output, []any{val, ty})
if ty == "return" || ty == "break" {
if ty == "return" || ty == "break" || ty == "continue" {
return ty, val, output
}
}
@@ -28,35 +29,52 @@ func run(lines []any, localvars map[string]variableValue) (any, any, [][]any) {
return nil, nil, output
}
func anyToArgon(x any) string {
switch x.(type) {
func anyToArgon(x any, quote bool) string {
switch x := x.(type) {
case string:
return x.(string)
if !quote {
return x
} else {
return strconv.Quote(x)
}
case float64:
return fmt.Sprint(x)
case bool:
if x.(bool) {
if x {
return "yes"
} else {
return "no"
}
case nil:
return "unknown"
case []any:
output := []string{}
for i := 0; i < len(x); i++ {
output = append(output, anyToArgon(x[i], true))
}
return "[" + strings.Join(output, ", ") + "]"
case variable:
return x.(variable).variable
return x.variable
default:
return fmt.Sprint(x)
}
}
func runprocess(codeseg any, localvars map[string]variableValue) (any, any) {
switch codeseg.(type) {
func runprocess(codeseg any, vargroups []map[string]variableValue) (any, any) {
switch codeseg := codeseg.(type) {
case opperator:
return runOperator(codeseg.(opperator), localvars), "opperator"
return runOperator(codeseg, vargroups), "opperator"
case variable:
myvar := localvars[codeseg.(variable).variable]
var varigroup map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][codeseg.variable].EXISTS != nil {
varigroup = vargroups[i]
break
}
}
myvar := varigroup[codeseg.variable]
if myvar.EXISTS == nil {
myvar = vars[codeseg.(variable).variable]
myvar = vargroups[len(vargroups)-1][codeseg.variable]
}
if myvar.EXISTS != nil {
if myvar.TYPE != "func" && myvar.TYPE != "init_function" {
@@ -65,55 +83,75 @@ func runprocess(codeseg any, localvars map[string]variableValue) (any, any) {
return codeseg, "value"
}
}
log.Fatal("undecared variable " + codeseg.(variable).variable + " on line " + fmt.Sprint(codeseg.(variable).line+1))
log.Fatal("undecared variable " + codeseg.variable + " on line " + fmt.Sprint(codeseg.line+1))
case funcCallType:
return callFunc(codeseg.(funcCallType), localvars), "value"
return callFunc(codeseg, vargroups), "value"
case itemsType:
vals := []any{}
for i := 0; i < len(codeseg.vals); i++ {
resp, _ := runprocess(codeseg.vals[i], vargroups)
vals = append(vals, resp)
}
return vals, "value"
case whileLoop:
whileloop := codeseg.(whileLoop)
resp, _ := runop(whileloop.condition, localvars)
whileloop := codeseg
resp, _ := runop(whileloop.condition, vargroups)
for boolean(resp) {
ty, val, _ := run(whileloop.code, localvars)
ty, val, _ := run(whileloop.code, vargroups)
if ty == "break" {
break
} else if ty == "continue" {
continue
} else if ty == "return" {
return val, "return"
return val, ty
}
resp, _ = runop(whileloop.condition, vargroups)
}
return nil, nil
case ifstatement:
iff := codeseg.(ifstatement)
resp, _ := runop(iff.condition, localvars)
iff := codeseg
resp, _ := runop(iff.condition, vargroups)
if boolean(resp) {
ty, val, _ := run(iff.TRUE, localvars)
ty, val, _ := run(iff.TRUE, vargroups)
return val, ty
} else {
ty, val, _ := run(iff.FALSE, localvars)
ty, val, _ := run(iff.FALSE, vargroups)
return val, ty
}
case importType:
importMod((codeseg.(importType).path).(string))
importMod((codeseg.path).(string))
return nil, nil
case setVariable:
setVariableVal(codeseg.(setVariable), localvars)
setVariableVal(codeseg, vargroups)
return nil, nil
case setFunction:
setFunctionVal(codeseg.(setFunction), localvars)
setFunctionVal(codeseg, vargroups)
return nil, nil
case returnType:
val, worked := runop(codeseg.(returnType).val, localvars)
if worked == nil {
log.Fatal("return statement must return a value on line " + fmt.Sprint(codeseg.(returnType).line+1))
var val any = nil
if codeseg.val != nil {
vars, worked := runop(codeseg.val, vargroups)
if worked == nil {
log.Fatal("return statement must return a value on line " + fmt.Sprint(codeseg.line+1))
}
val = vars
}
return val, "return"
case breakType:
return nil, "break"
case continueType:
return nil, "continue"
}
return codeseg, "value"
}
func callFunc(call funcCallType, localvars map[string]variableValue) any {
variables := localvars
if variables[call.name].EXISTS == nil {
variables = vars
func callFunc(call funcCallType, vargroups []map[string]variableValue) any {
var variables map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][call.name].EXISTS != nil {
variables = vargroups[i]
break
}
}
if variables[call.name].EXISTS == nil {
log.Fatal("undecared function '" + call.name + "' on line " + fmt.Sprint(call.line+1))
@@ -129,14 +167,14 @@ func callFunc(call funcCallType, localvars map[string]variableValue) any {
argvals := []any{}
for i := 0; i < len(callable.args); i++ {
resp, _ := runprocess(callable.args[i], localvars)
resp, _ := runprocess(callable.args[i], vargroups)
argvals = append(argvals, resp)
}
return vars[callable.name].VAL.(func(...any) any)(argvals...)
} else {
argvars := make(map[string]variableValue)
for i := 0; i < len(callable.args); i++ {
resp, _ := runprocess(callable.args[i], localvars)
resp, _ := runprocess(callable.args[i], vargroups)
name := variables[callable.name].VAL.(setFunction).args[i]
argvars[name] = variableValue{
VAL: resp,
@@ -145,7 +183,7 @@ func callFunc(call funcCallType, localvars map[string]variableValue) any {
FUNC: false,
}
}
ty, val, _ := run(vars[callable.name].VAL.(setFunction).code, argvars)
ty, val, _ := run(vars[callable.name].VAL.(setFunction).code, append(vargroups, argvars))
if ty != "return" && ty != nil {
log.Fatal(ty, " is not allowed in top level of function on line ", (callable.line + 1))
}
@@ -153,48 +191,54 @@ func callFunc(call funcCallType, localvars map[string]variableValue) any {
}
}
func setVariableVal(x setVariable, localvars map[string]variableValue) {
variable := localvars
if variable[x.variable].EXISTS == nil {
variable = vars
func setVariableVal(x setVariable, vargroups [](map[string]variableValue)) {
var variable map[string]variableValue = nil
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][x.variable].EXISTS != nil {
variable = vargroups[i]
break
}
}
vari := variable[x.variable]
if variable[x.variable].EXISTS == nil {
resp, _ := runop(x.value, localvars)
variable[x.variable] = variableValue{
resp, _ := runop(x.value, vargroups)
vargroups[len(vargroups)-1][x.variable] = variableValue{
TYPE: x.TYPE,
EXISTS: true,
VAL: resp,
FUNC: false,
}
} else if variable[x.variable].TYPE == "var" {
val, _ := runop(x.value, localvars)
resp, _ := runop(x.value, vargroups)
variable[x.variable] = variableValue{
TYPE: x.TYPE,
EXISTS: variable[x.variable].EXISTS,
VAL: val,
VAL: resp,
FUNC: variable[x.variable].FUNC,
}
} else {
log.Fatal("cannot edit " + vari.TYPE + " variable on line " + fmt.Sprint(x.line+1))
log.Fatal("cannot edit " + variable[x.variable].TYPE + " variable on line " + fmt.Sprint(x.line+1))
}
}
func setFunctionVal(x setFunction, localvars map[string]variableValue) {
variable := localvars[x.name]
if variable.EXISTS == nil {
variable = vars[x.name]
func setFunctionVal(x setFunction, vargroups []map[string]variableValue) {
var variable map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][x.name].EXISTS != nil {
variable = vargroups[i]
break
}
}
if vars[x.name].EXISTS == nil {
vars[x.name] = variableValue{
if variable[x.name].EXISTS == nil {
vargroups[len(vargroups)-1][x.name] = variableValue{
TYPE: "func",
EXISTS: true,
VAL: x,
FUNC: false,
}
} else if vars[x.name].TYPE == "func" {
variable.VAL = x
variable.FUNC = false
vari := variable[x.name]
vari.VAL = x
vari.FUNC = false
} else {
log.Fatal("cannot edit " + vars[x.name].TYPE + " variable on line " + fmt.Sprint(x.line+1))
}
@@ -232,15 +276,15 @@ func boolean(x any) bool {
}
func number(x any) float64 {
switch x.(type) {
switch x := x.(type) {
case float64:
return x.(float64)
return x
case float32:
return float64(x.(float32))
return float64(x)
case int:
return float64(x.(int))
return float64(x)
case bool:
if x.(bool) {
if x {
return 1
} else {
return 0
@@ -254,12 +298,13 @@ func number(x any) float64 {
}
}
func runOperator(opperation opperator, localvars map[string]variableValue) any {
func runOperator(opperation opperator, vargroups []map[string]variableValue) any {
var output any
opperationloop:
for i := 0; i < len(opperation.vals); i++ {
switch opperation.t {
case 0:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
@@ -267,122 +312,122 @@ func runOperator(opperation opperator, localvars map[string]variableValue) any {
output = x
} else {
output = false
break
break opperationloop
}
}
case 1:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if boolean(x) {
output = x
break
break opperationloop
}
case 2:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = xiny(output, x.([]any))
}
case 3:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = !xiny(output, x.([]interface{}))
}
case 4:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) <= number(x))
}
case 5:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) >= number(x))
}
case 6:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) < number(x))
}
case 7:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) > number(x))
}
case 8:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (output != x)
}
case 9:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (output == x)
}
case 10:
x, _ := runop(opperation.vals[i], localvars)
case 11:
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) - number(x))
}
case 11:
x, _ := runop(opperation.vals[i], localvars)
case 10:
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = dynamicAdd(output, x)
}
case 12:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) * number(x))
}
case 13:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = math.Floor(number(output) / number(x))
}
case 14:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = math.Mod(number(output), number(x))
}
case 15:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) / number(x))
}
case 16:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = math.Pow(number(output), 1/number(x))
}
case 17:
x, _ := runop(opperation.vals[i], localvars)
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
+1 -1
View File
@@ -25,7 +25,7 @@ func shell() {
resp := runStr(temp)
for i := 0; i < len(resp); i++ {
if resp[i][1] != nil {
fmt.Println(anyToArgon(resp[i][0]))
fmt.Println(anyToArgon(resp[i][0], false))
}
}
temp = ""
+5 -2
View File
@@ -3,11 +3,14 @@ completed:
- subs (functions)
- add return to functions
- add break
- add continue
- allow functions parameters to be passed in
- create sub return values
- make local variables that delete after the function finishes
incompleted:
- books (objects)
- items (arrays)
- add else if to if statments
- add try catch
- add continue
- allow functions parameters to be passed in
- fix close square bracket not being allowed in open indentation
+35 -20
View File
@@ -15,9 +15,9 @@ var whileCompile = makeRegex("( *)(while( )+" + anyAndNewline + "+( )+\\[" + any
var subCompile = makeRegex("( *)(sub( )+" + variableOnly + "\\(" + anyAndNewline + "*\\)( )+\\[" + anyAndNewline + "*)( *)")
var ifCompile = makeRegex("( *)(if( )+" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
var elseifCompile = makeRegex("( *)(\\] else if " + anyAndNewline + "+ \\[" + anyAndNewline + "*)( *)")
var openCompile = makeRegex("( *)(" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
var openCompile = makeRegex("( *)(" + anyAndNewline + "+( )+\\[([^\\]])*)( *)")
var elseCompile = makeRegex("( *)\\] else \\[" + anyAndNewline + "*( *)")
var closeCompile = makeRegex("( *)" + anyAndNewline + "*\\]" + anyAndNewline + "*( *)")
var closeCompile = makeRegex("( *)\\]( *)")
var switchCloseCompile = makeRegex("( *)" + anyAndNewline + "*\\]" + anyAndNewline + "*\\[" + anyAndNewline + "*( *)")
var importCompile = makeRegex("( *)import " + anyAndNewline + "+( *)")
var bracketsCompile = makeRegex("( *)\\(" + anyAndNewline + "*\\)( *)")
@@ -26,7 +26,9 @@ var variableTextCompile = makeRegex("( *)" + variableOnly + "( *)")
var variableonlyCompile = makeRegex(variableOnly)
var setVariableCompile = makeRegex("( *)(((const|var) (" + variableOnly + "( *))=( *).+)|(( *)" + variableOnly + "( *))(( *)=( *).+))( *)")
var returnStatementCompile = makeRegex("( *)(return(( )+" + anyAndNewline + "*)?)( *)")
var itemsCompiled = makeRegex("( *)(\\[" + anyAndNewline + "*\\])( *)")
var breakStatementCompile = makeRegex("( *)break( *)")
var continueStatementCompile = makeRegex("( *)continue( *)")
var skipCompile = makeRegex("( *)(#(.*))?")
var processfunc func(codeseg code) (interface{}, bool)
var linefunc func(i int, codearray []code) (interface{}, int)
@@ -75,29 +77,29 @@ var opperators = [][]string{
" is equal to ",
" is ",
"===",
}, {
" minus ",
" subtract ",
"-",
}, {
" plus ",
" add ",
"+",
}, {
" minus ",
" subtract ",
"-",
}, {
"*",
" x ",
" times ",
" multiplied by ",
}, {
" mod ",
" modulo ",
"%",
}, {
" div ",
" floor division of ",
" floor divistion ",
"//",
"$",
}, {
" mod ",
" modulo ",
"%",
}, {
" over ",
" divided by ",
@@ -273,12 +275,12 @@ var getCodeInIndent = func(i int, codearray []code, isIf bool) ([]code, int) {
i++
for {
if (closeCompile.MatchString(codearray[i].code) && !switchCloseCompile.MatchString(codearray[i].code)) || (isIf && (elseCompile.MatchString(codearray[i].code) || elseifCompile.MatchString(codearray[i].code))) {
indent++
if indent > 0 {
indent--
if indent < 0 {
break
}
} else if openCompile.MatchString(codearray[i].code) && !switchCloseCompile.MatchString(codearray[i].code) {
indent--
indent++
}
result = append(result, codearray[i])
i++
@@ -313,14 +315,15 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
})
if worked {
vals = append(vals, val)
} else {
return opperator{
t: i,
vals: vals,
line: codeseg.line,
}, true
} else if len(opperators) == i+1 {
return nil, false
}
return opperator{
t: i,
vals: vals,
line: codeseg.line,
}, true
}
}
}
@@ -348,6 +351,15 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
line: codeseg.line,
})
return brackets, ran
} else if itemsCompiled.MatchString(codeseg.code) {
inside := strings.Trim(codeseg.code, " ")[1 : len(strings.Trim(codeseg.code, " "))-1]
vals, worked := getValuesFromCommas(inside, codeseg.line)
if worked {
return itemsType{
vals: vals,
line: codeseg.line,
}, true
}
} else if numberCompile.MatchString(codeseg.code) {
if s, err := strconv.ParseFloat(strings.Trim(codeseg.code, " "), 64); err == nil {
return s, true
@@ -384,6 +396,10 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
return breakType{
line: codeseg.line,
}, i + 1
} else if continueStatementCompile.MatchString(codeseg.code) {
return continueType{
line: codeseg.line,
}, i + 1
}
resp, worked := translateprocess(codeseg)
if worked {
@@ -502,7 +518,6 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
line: codeseg.line,
}, i + 1
} else if skipCompile.MatchString(codeseg.code) {
} else {
err := "Invalid syntax on line "
log.Fatal("\n\nLine " + fmt.Sprint(codeseg.line+1) + ": " + codeseg.code + "\n" + err + "\n\n")
+25
View File
@@ -76,4 +76,29 @@ func init() {
VAL: eval,
FUNC: true,
}
vars["append"] = variableValue{
TYPE: "init_function",
EXISTS: true,
VAL: ArgonAppend,
FUNC: true,
}
vars["extend"] = variableValue{
TYPE: "init_function",
EXISTS: true,
VAL: ArgonExtend,
FUNC: true,
}
vars["len"] = variableValue{
TYPE: "init_function",
EXISTS: true,
VAL: ArgonLen,
FUNC: true,
}
vars["join"] = variableValue{
TYPE: "init_function",
EXISTS: true,
VAL: ArgonJoin,
FUNC: true,
}
}