Categorygithub.com/jerloo/funny
modulepackage
0.2.11
Repository: https://github.com/jerloo/funny.git
Documentation: pkg.go.dev

# README

funny lang

A funny language interpreter written in golang.

It begins just for fun.

Target

To make creating dsl easily based on funny.

  • apitest dsl
  • api declare dsl

Installation

go install github.com/jerloo/funny/cmd/funny@latest

Usage


// funny.fun
// author: [email protected]
// github: https://github.com/jerloo/funny

echoln('define a varible value 1')
a = 1

echoln('define b varible value 2')
b = 2

echoln('define c varible value a ')
c = a

echoln('a, b, c values: ')
echoln('a = ', a,', b = ',  b, ', c = ', c)

echoln('assert c equels 1')
assert(c == 1)

d = c + b

echoln('assert (d = c + b) === ', d)
assert(d == 3)

echoln('define a function ')
echoln('minus(a, b) {')
echoln('  return b - a')
echoln('}')

minus(a, b) {
  return b - a
}

e = minus(a, b)
echoln('minus(a, b) === ', e)
assert(e == 1)

if a > 0 {
  echoln('if a > 0')
}

fib(n) {
  if n < 2 {
    return n
  }
  return fib(n - 1) + fib(n - 2)
}

r = fib(1)
echoln(r)
r = fib(2)
echoln(r)
r = fib(3)
echoln(r)
r = fib(4)
echoln(r)
r = fib(5)
echoln(r)
r = fib(6)
echoln(r)
r = fib(7)
echoln(r)
r = fib(8)
echoln(r)

person = {
  name = 'jerloo'
  age = 10
}
assert(person.name == 'jerloo')
echoln(person.age)

Object() {
  return {
    name = 'jerloo'
    age = 10
    isAdult() {
      this.age = this.age + 5
      echoln('this.age ', this.age)
      return true
    }
  }
}

obj = Object()
assert(obj.name == 'jerloo')
obj.age = 20
assert(obj.age == 20)
assert(obj.isAdult())
echoln(obj.isAdult())
echoln(obj.age)

arrdemo = [1,2,3]
echoln(arrdemo[2])
assert(arrdemo[2]==3)

hashTest = 'i am string'
echoln(hashTest)
echoln('hash(i am string) => ', hash(hashTest))

echoln('max(10, 20) => ', max(10,20))

import 'funny.imported.fun'

echoln('uuid => ', uuid())

deepObj = {
  a = {
    b = {
      c = 1
    }
  }
}

echoln('deepObj.a =>', test.a)
echoln('deepObj.a.b =>', test.a.b)
echoln('deepObj.a.b.c =>', test.a.b.c)
$ funny --help

usage: funny [<flags>] [<script>]

funny lang

Flags:
  --help    Show context-sensitive help (also try --help-long and --help-man).
  --lexer   tokenizer script
  --parser  parser AST

Args:
  [<script>]  script file path

Todos

  • Fix many and many bugs
  • Fix scope
  • Fix echo
  • Add more builtin functions
  • Add tests
  • Fix import feature
  • Typings
  • module and package feature
  • module repo based on github
  • Add everything with(have) comment's feature
  • Chinese comments length

License

The MIT License (MIT)

Copyright (c) 2018 jerloo

# Packages

No description provided by the author
No description provided by the author

# Functions

Assert return the value that has been given.
Base64Decode return base64 decoded string.
Base64Encode return base64 encoded string.
DumpRuntimes dumpruntimes().
Echo builtin function echos one or every item in a array.
Echoln builtin function echos one or every item in a array.
Env return the value of env key.
No description provided by the author
FormatData format(data, formatStr) string.
HttpRequest builtin function for http request.
Int like int('1').
JwtDecode jwtde(method, secret, token) string.
JwtEncode jwten(method, secret, claims) string.
Len return then length of the given list.
Max return then length of the given list.
Md5 return then length of the given list.
Min return then length of the given list.
Create a new funny with default settings.
NewFunnyWithScope create a new funny.
NewLexer create a new lexer.
NewParser create a new parser.
Now builtin function return now time.
P panic.
ReadJson readjson(filename).
ReadText readtext().
RegexMapMatch regexMapMatch(regexMap, text).
RegexMapValue regexMapValue(regexMap, text).
RegexMatch regexMatch(regex, text).
Sh sh(command).
SqlExec sqlexec(connection, sqlRaw, args) string.
SqlExecFile sqlexecfile(connection, file).
SqlQuery sqlquery(connection, sqlRaw, args) string.
Str like string(1).
StrJoin equal strings.Join.
StrSplit equal strings.Split.
Typeof builtin function echos one or every item in a array.
Typing return the type name of one object.
UUID builtin function return a uuid string value.
WriteJson writejson(filename, obj).
WriteText writetext(text).

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
VERSION of funny.

# Variables

go:embed builtins.funny.
FUNCTIONS all builtin functions.
No description provided by the author

# Structs

Assign like a = 2.
BinaryExpression like a > 10.
Block contains many statments.
Boolen like true, false.
Break like break in for.
Comment line for sth.
Continue like continue in for.
Field like obj.age.
FORStatement like for.
Function like test(a, b){}.
FunctionCall like test(a, b).
Funny the virtual machine of funny code.
No description provided by the author
IFStatement like if.
ImportFunctionCall like test(a, b).
IterableExpression like for in.
Lexer the lexer.
List like [1, 2, 3].
ListAccess like a[0].
Literal like 1.
NewLine @impl Statement \n.
Parser the parser.
Position of one token.
Program means the whole application.
Return like return varA.
StringExpression like 'hello world !'.
SubExpression like a = a && (b * 3), and then '(b * 3)' is SubExpression.
Token a part of code.
Variable means var.

# Interfaces

Statement abstract.
Value one value of some like variable.

# Type aliases

BuiltinFunction function handler.
Scope stores variables.