Skip to content

Syntax Ideas

Mario Alejandro Montoya edited this page Sep 5, 2020 · 2 revisions

Basic Types

Comments

-- Comments start with 2 'minus' symbol
--- Multiline 
commentaries
---

Numeric type

  • All integers are 64-bits.

Syntax: 1

  • All binary floating-point are 64-bits.

Syntax: 1.1f

  • For decimal floating-point are 64-bits, d subfix is not necessary (is the default float type)

Syntax: 1.1d = 1.1

Bit type

0b 1b 0100110b (Array)

Boolean type

Syntax: true false

Strings type

  • All strings are UTF-8 encoding guaranteed. You could delimiter strings with double-quotes or an apostrophe.

  • Using double-quotes if you want to escape apostrophes.

Syntax: "hello 'wonderful' world!"

  • Using apostrophes if you want to escape double-quotes.

Syntax: 'hello "wonderful" world!'

  • You could use triple quotes for multiline strings.*

Syntax:

"""hello from
multiline world!"""

You can do string interpolation

"hello {1 + 2}"

Dates and Time

  • Dates are written in ISO format
dt"2001-01-10T23:02:10"
d"2001-01-10"
t"23:02:10"

Operators

Logical ops

not and or
< <= => >
<>
=

Math ops

+ - * /

Assigment ops

:=
+= -= *= /=

Grouping ops

() grouping 
[] vector
|| row
[<>] writen as rows
[||] writen as cols

Block

do
end

Identifiers

var -- mutable
let -- inmutable

Name conventions

Color -- types
COLOR -- const
color -- vars/others
color_blue -- multi-words

Types

Int
Dec
Str
Float
Bit
Date
Time
DateTime
Char
Vec
Map
Tree
Any

Collections

Rows & Values

, -- separate columns
; -- separate rows

Vectors

nums = Vec[it:i32; 1; 2; 3]
nums = 1
nums = [1]

Tables

Fac := Map[| key id:Int, code:Str, cust:Str, salesman:Int|] -- header/type

-- written as rows 
Map := Map[|
  id:Int, name:Str;
  1, "hello"; -- row0
  2, "world" -- row1
|]

-- written as columns 
Tree := Tree[<
  id:Int = 1; 2; 3 -- col0
  name:Str = "hello"; "world"; "other" -- col1
>]

-- Define a primary key (pk) is optional, if pk is not used then the row is unique.

city :=  Map[| id:Int, code:Dec pk]

city := Tree[| id:Int, code:Dec, name:Str pk|]

Tuples/Rows

named:

city := | id=1,  name="miami" |

anon:

city := | 1, "miami" |

Structures

Enumerations (Sum types)

enum Color do
  Blue: Int
  Red: (String, String)
  Rgb: (red:Int, blue:Int, green:Int)
  Other
end


-- Only for numbers, string, characters and boolean values

enum HttpError do
  E404 := 404
  E500 := 500
end

Named Relations

rel City do  
  key id:Int pk, 
  code:Str, 
  cust:Str, 
  salesman:Int
end

Indexing

Numeric

a := [1, 2, 3] # 0
>> a = 1
[1, 3, 4] # [0, 2] = [1, 4]

Named columns

city ?select #name (#0 ?limit 1)
city #name #id
city ?select #name

Casting & Conversions

if is a:Vec[Int] do
  let a = cast a:Vec[Int]

Control flow

if

let value := 
if true do
   1
elif a > 2
  2
else 
   2
end

match

pending...

match thing do
1 do 1 end
2 do 1 end
_ do 4 end

is a:Vec _ do
  end
is Color.Rgb(a, b, c) do
  end
end

while

while true do
   println("this repeat forever")
end

for

for i in range(1,10) do --this count from 1 to 9
   println(i)
end

Functions

fun save(a:Int, b:Int) = Int do
end