Last active
May 21, 2016 04:18
-
-
Save copygirl/2445ecf33c51bdc33eb2ac03c6236b60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| * O/==================================\O * | |
| * |====[ obsidian Engine Language ]====| * | |
| * |====[ ~ Definition ~ ]====| * | |
| * O\==================================/O * | |
| * | |
| * Motivated by JAI, another language in development: | |
| * https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md | |
| * Also taking some inspiration from C#. | |
| * Work In Progress ... obviously. | |
| */ | |
| // Comment | |
| /* Block | |
| Comment */ | |
| /* Nested /* Block */ Comment */ | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Built-in Types ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ | |
| void :: () | |
| sbyte :: Int8 | |
| byte :: UInt8 | |
| short :: Int16 | |
| ushort :: UInt16 | |
| int :: Int32 | |
| uint :: Uint32 | |
| long :: Int64 | |
| ulong :: UInt64 | |
| float :: Float32 | |
| double :: Float64 | |
| bool :: Boolean | |
| string :: String | |
| // This is also how you can define aliases for types | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Variable Definition and Assignment ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ | |
| { | |
| // Definition | |
| a_number : int | |
| // Assignment | |
| a_number = 10 | |
| // Both at once | |
| hello_string : string = "Hello" | |
| // With type inference | |
| world_string := "World" | |
| // Constants | |
| an_important_byte : byte : 10 | |
| answer_to_life_the_universe_and_everything :: 42 | |
| //10 | |
| // Error: Expected "Statement", got "Constant Value (Number)" | |
| //20 + 30 | |
| // Error: Expected "Statement", got "Arithmetic" | |
| //unknown_variable = 69 | |
| // Error: Unknown identifier "unknown_variable" | |
| //a_number : int | |
| // Error: Multiple definition of "a_number" in the same scope | |
| //an_important_byte = 20 | |
| // Error: Can't reassign constant "an_important_byte" | |
| //a_number = "not a number" | |
| // Error: Can't assign value of type "String" to variable of type "Int32" | |
| } | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Statements and Expressions ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| == Statements == | |
| Statements are syntax statements that do not evaluate to anything. | |
| some_variable := 0 | |
| .. is a "Declaration" statement | |
| some_variable = -1 | |
| .. is an "Assignment" statement | |
| NOTE: Not sure whether to make this one also an expression or not. | |
| MyFirstFunction :: () -> { print("Hello, World!") } | |
| AddTwo :: (value) -> { value + 2 } | |
| .. are "Declaration (Constant)" statements | |
| MyFirstFunction() | |
| .. is a "Call" statement (since MyFirstFunction returns void) | |
| == Expressions == | |
| Expressions evaluate to a value of some type. | |
| Pure expressions may not be used where a statement is expected. | |
| 10 | |
| .. is a "Constant Value (Number)" expression (pure) of type "Int32" that evaluates to 10. | |
| NOTE: In some contexts, "Constant Value" will take on a different type. | |
| 10 + 5 | |
| .. is an "Arithmetic" expression (pure) of type "Int32" that evaluates to 15. | |
| (name : string) -> { 10 + 5 } | |
| .. is a "Function" expression (pure) of type "(string) -> (int)" | |
| that evaluates to the defined function. | |
| AddTwo(5) | |
| .. is a "Call" expression (since AddTwo returns int) | |
| == Semicolon == | |
| Do you remember ; from other languages? In OEL, | |
| it's not valid to end a line with a semicolon: | |
| print("Testing"); | |
| Error: Expected "Expression", got "Newline" | |
| Hint: Don't use semicolons at the end of a line | |
| What you *can* do is use ; to separate multiple | |
| statements / expressions on the same line: | |
| print_value := 5; print(print_value) | |
| */ | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Blocks, Scopes and Namespaces ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ | |
| // Blocks create a new scope, anything defined | |
| // inside is only available within them. | |
| { | |
| block_constant :: 10 | |
| block_variable := 20 | |
| } | |
| //block_variable = 30 | |
| // Error: Unknown identifier "block_variable" | |
| // Hint: Identifier "block_variable" is defined in anonymous child block | |
| // You can define namespaces by assigning blocks to a constant identifier | |
| // NOTE: Not sure about this feature. Revisit when doing importing / exporting. | |
| MyNamespace :: { | |
| namespace_variable : int | |
| } | |
| MyNamespace.namespace_variable = 1337 | |
| //MyOtherNamespace := { } | |
| // Error: Expected "Expression", but got "Statement Block" | |
| // Hint: Namespaces have to be defined as constant | |
| /* ~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Tuples ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~ */ | |
| { | |
| // Definition | |
| a_tuple :: (5, 3, 1) // Tuple<int, int, int> | |
| b_tuple :: ("foo", 7) // Tuple<string, int> | |
| not_tuple := (5) // int | |
| // Destructuring | |
| (five, three, one) := a_tuple | |
| // is the same as | |
| five = a_tuple[0] | |
| three = a_tuple[1] | |
| one = a_tuple[2] | |
| // NOTE: Not sure about indexers here since they can be different types. | |
| // .Item1, Item2, ... (ala .NET) looks kind of bad. | |
| // .0, .1, ... looks like it should be a syntax error. | |
| // is also the same as | |
| (_, three) = a_tuple | |
| (_, _, one) = a_tuple | |
| five = a_tuple | |
| // NOTE: Not sure about this either should / | |
| // would also allow the following then: | |
| not_tuple = (10, 5) | |
| //a_tuple[0] = 2 | |
| // Error: Can't assign "Tuple<int, int, int>[0]", it is readonly | |
| //a_tuple = (4, 3, 2, 1, 0) | |
| // Error: Can't assign value of type "Tuple<int, int, int, int, int>" | |
| // to variable "a_tuple" (type "Tuple<int, int, int>") | |
| // == Multiline Tuples == | |
| // Similarly to blocks and semicolons, tuples can be | |
| // defined the other way around as well, like this: | |
| multiline_tuple := ( | |
| 5 | |
| 6 | |
| 7 | |
| ) | |
| //multiline_tuple = ( | |
| // 10, | |
| // 11, | |
| // 12 | |
| //) | |
| // Error: Expected "Expression", got "Newline" | |
| // Hint: Don't use commas at the end of a line in multiline tuples | |
| // == Named Tuples == | |
| // This creates a new "type" with named | |
| // elements that point to the indexed elements | |
| named :: (name := "named", type : byte = 5) // Tuple<string, byte> | |
| name := named_tuple.name | |
| type := named_tuple.type | |
| // Destructuring reassignment | |
| (first, second) = named_tuple | |
| // Use the named elements to destructure (not in order) | |
| (type, name) = named_tuple | |
| // Destructuring definition | |
| (t, n) : (string, byte) | |
| // Destructuring named tuple with custom names | |
| (t = type, n = name) = named_tuple | |
| //incorrectly_named :: (named := "fool", 1, 3) | |
| // Error: Can't mix tuples with unnamed and named elements | |
| //(tt = type, nn) := named_tuple | |
| // Error: Can't mix tuples with unnamed and named elements | |
| //non_match : byte | |
| //(type, non_match) = named_tuple | |
| // Error: Matched some but not all elements of named tuple ("type", but not "non_match") | |
| } | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== Functions ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~ */ | |
| { | |
| DoNothing :: () -> { } | |
| DoNothingTwice :: () -> { | |
| DoNothing() | |
| DoNothing() | |
| } | |
| // TODO | |
| } | |
| /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| * ====== TODOs, Ideas and Dreams ====== * | |
| * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| - Structs | |
| - (Extension) Methods | |
| - Importing / Exporting | |
| - Operators | |
| - Operator overloading | |
| - Custom operators | |
| - Units of Measure (see F#) | |
| - Generics | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment