Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Statements perceded by ## are preprocessor directives. Let directive aliases an identifier to another. Identifier can be anything, from a built-in type or a
- // keyword to a custom user storage. Preprocessor directives are evaluated at compile time. Preprocessor directives need to be defined and are available in the root // file scope.
- ##let false = true
- // This is an alias. Aliases are runtime let directives. They are identical to let directives but can be used dynamically with statements. They're block scoped.
- alias false = true
- // This is a simple storage with a few properties and methods attached to it. A storage is basically a data template. A storage with properties and/or methods
- // attached to it is called a class. Properties inside of a storage are called member properties Every method and member property in a storage is public by default.
- // Function attached to a storage is called a method. Every storage is exported to the global scope unless specified private.
- let storage AStorage = {
- let aProperty
- let anotherProperty
- // This is a constant member property which can not be reassigned outside of this storage.
- let const constantProperty
- // This is a private member property that can not be accessed outside of this storage.
- let private privateProperty
- // This is a private constant member property which can only be assigned and reassigned inside of the creator. Const always needs to come after the access modifier // (if present, if not, after let)
- let private const privateConstantProperty
- // This is a nested storage. Nested storages are root file scoped but can be only accessed through the parent. Nested storages can access parent's member
- // properties and methods.
- let storage NestedStorage {
- }
- }
- // This is a private storage that's not exported to global scope. They're root file scoped.
- let private storage PrivateStorage {
- }
- // This is a creator. Creators are normal methods defined with fragment functions. Creators are called when the storage they're attached to gets created.
- let fn AStorage.creator()() {
- }
- //Creator implementation:
- let fn creator() {
- return :___creator___
- }
- // This is a global property that's assigned to a new instance of the storage. To create a new instance of a storage, you use create. Create and storage creator
- // parentheses are optional (if no parameters are passed to them).
- let aStorageInstance = create AStorage() //or: create(AStorage)
- // This is a normal call on an storage instance. Method calls need to be perceded with :: if method is not defined in the current scope. Parentheses are optional if no parameters are expected.
- aStorageInstance::someMethod()
- // This is a parameterless method attached to a storage. Parameterless methods do not require parentheses. This method is public, inherited and overridable by
- // storage's children.
- let fn AStorage.someMethod() {
- }
- // This is a method attached to a nested storage. They behave identically as normal attached methods.
- let fn AStorage.NestedStorage.methodInNestedStorage {
- }
- // This is a method with parameters. Methods with parameters require parentheses. Parameters can be used as any other local properties.
- let fn AStorage.methodWithParams(let param1, let param2) {
- }
- // This is a method with parameters. Method parameters can have default values. Parameters with default values are called default parameters. Default parameters
- // behave as normal parameters but need to be at the end of the parameter list. If no value is passed to default parameter, it has the specified default value.
- // The value passed to the default parameter has to be of the same type as the default value of the default parameter.
- let fn AStorage.methodWithDefaultParams(let param1, let param2 = 1, let param3 = "aString") {
- // This is a method call. The parentheses and this:: are optional.
- this::someMethod()
- }
- // operator() is just a function that returns a fragment. You can override an operator without operator(), just by specifying ___operator___<operator here> and needed // parameters.
- let fn operator(==)(let left, let right) {
- }
- // This is a fragment. A fragment is like any other identifier but it can be used as an expression. Fragments can contain same characters as normal identifiers.
- :fragment
- // Operator implementation
- let fn operator(let operator) {
- return :___operator___ + to_fragment(operator)
- }
- // This is a fragment function. Fragment functions return a fragment and can be used as identifiers. Fragment functions can not be methods.
- let fn fragmentFunction() {
- return :aFragment
- }
- // This is the only function call example where you need to use parentheses, even on parameterless functions. Example:
- let fn fragmentFunction()fragmentExample { // This compiles into let aFragmentfragmentExample
- }
- let fragmentFunction // This compiles to let aFragment
- // This is a parameterless method which can not be overridden by storage's children due to it being const.
- let const fn AStorage.nonOverridableMethod {
- }
- // This is a private method. Private methods can only be accessed from inside of the storage. Private methods can not be constant because it doesn't make sense.
- let private fn AStorage.privateMethod {
- }
- // This is a protected method. Protected methods can only be accessed from inside the storage and the children.
- let protected fn AStorage.protectedMethod {
- }
- // This is a protected constant method. Protected contant methods can only be accessed from inside the storage and the children but can not be overridden by them.
- let protected const fn AStorage.protectedConstantMethod {
- }
- // This is a storage that extends another storage. If no other options are passed, it inherits all the data from the parent type - the methods and properties. If
- // any method or member property of a child has the same name as one of the parent's, child's member property or method overrides parent's if not const.
- let storage ExtendedAStorage = AStorage + {
- let someOtherProperty
- }
- // This is an overridden method. Override needs to be second method modifier. To call accessible methods on the parent, use base.
- let override fn ExtendedAStorage.someMethod {
- // This calls parent's implementation of this method. Base behaves like any other method call.
- base()
- // This is a method call on the parent. It behaves like any other method call.
- base::someMethodWithParams(1, 1)
- }
- // This is a global method decoupled from any storage. Global methods are called functions .
- let fn decoupledMethod {
- }
- // This is an extended function. Extended function are very unsafe and disencouraged to use in most cases. This will paste the parent function above everything in
- // the child function.
- let fn extendedMethod = decoupledMethod + {
- }
- // This is a storage extended inline. This storage behaves like any other extended storage but it is more of an alias because it's identical to it's parent. It's the
- // same as using alias.
- let storage InlineExtendedAStorage = AStorage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement