Compare commits
2 commits
5a52887489
...
30ea8a2740
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30ea8a2740 | ||
|
|
0e929c7b86 |
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -1,2 +1,6 @@
|
|||
.idea
|
||||
|
||||
prompt.sh
|
||||
prompt.txt
|
||||
prompt.txt
|
||||
compile_grammar.sh
|
||||
waddle.bnf
|
||||
|
|
|
|||
35
README.md
35
README.md
|
|
@ -229,6 +229,41 @@ if(my.age.gt(18).and(my.status.is(Verified))){
|
|||
}
|
||||
```
|
||||
|
||||
#### If conditionals
|
||||
##### Plain If
|
||||
```waddle
|
||||
if (x.gt(0).and(y.gt(0))) {
|
||||
rtn True;
|
||||
}
|
||||
```
|
||||
##### If/Otherwise
|
||||
```waddle
|
||||
if (x.gt(0).and(y.gt(0))) {
|
||||
rtn True;
|
||||
} otherwise {
|
||||
rtn False;
|
||||
}
|
||||
```
|
||||
##### If/Orif
|
||||
```waddle
|
||||
if (x.gt(0).and(y.gt(0))) {
|
||||
rtn True;
|
||||
} orif (x.lt(0).and(y.lt(0))) {
|
||||
rtn False;
|
||||
}
|
||||
```
|
||||
##### If/Orif/Otherwise
|
||||
```waddle
|
||||
if (x.gt(0).and(y.gt(0))) {
|
||||
rtn True;
|
||||
} orif (x.lt(0).and(y.lt(0))) {
|
||||
rtn False;
|
||||
} otherwise {
|
||||
rtn False;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Explicit Type Conversion
|
||||
```waddle
|
||||
String myString.set(my.number.set(42).as(String));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<decimal_literal> ::= <digit>+ "." <digit>+
|
||||
| "-" <digit>+ "." <digit>+
|
||||
|
||||
<string_literal> ::= '"' [^"]* '"'
|
||||
<string_literal> ::= '"' [^\"]* '"'
|
||||
| "'" [^']* "'"
|
||||
|
||||
<boolean_literal> ::= "True" | "False"
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
<module_declaration> ::= "module" <identifier> "{"
|
||||
(<export_declaration>
|
||||
| <constant_declaration>
|
||||
| <declaration>)*
|
||||
"}"
|
||||
|
||||
<export_declaration> ::=
|
||||
<accessibility_modifier>"export"
|
||||
(<constant_declaration>
|
||||
| <type_declaration>
|
||||
| <function_declaration>)
|
||||
|
||||
<visibility_rule> ::=
|
||||
<accessibility_modifier>
|
||||
(<type_declaration>
|
||||
| <function_declaration>)
|
||||
|
|
@ -2,4 +2,3 @@
|
|||
"-"
|
||||
| ""
|
||||
| "+"
|
||||
| "export"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
<error_declaration> ::= <identifier>
|
||||
["/" <identifier>]?
|
||||
<error_declaration> ::= <inherited_error_type>
|
||||
"{" <error_body>? "}"
|
||||
|
||||
<inherited_error_type> ::= [<parent_error> "/"]? <child_error>
|
||||
|
||||
<parent_error> ::= <identifier>
|
||||
|
||||
<child_error> ::= <identifier>
|
||||
|
||||
<error_body> ::= (<variable_declaration>
|
||||
| <constant_declaration>
|
||||
| <function_declaration>)*
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,25 @@
|
|||
|
||||
<error_type> ::= <identifier> ["/" <identifier>]?
|
||||
|
||||
<parameter_list> ::= <required_parameter>
|
||||
("," <required_parameter>)*
|
||||
[("," <default_parameter>)*]
|
||||
<parameter_list> ::=
|
||||
<parameter_group>?
|
||||
|
||||
<required_parameter> ::= <identifier> ":" <parameter_type>
|
||||
<parameter_group> ::=
|
||||
<required_parameters>
|
||||
| <required_parameters> "," <default_parameters>
|
||||
| <default_parameters>
|
||||
|
||||
<default_parameter> ::= <identifier> ".default(" <literal> ")"
|
||||
<required_parameters> ::=
|
||||
<required_parameter>
|
||||
| <required_parameter> "," <required_parameters>
|
||||
|
||||
<default_parameters> ::=
|
||||
<default_parameter>
|
||||
| <default_parameter> "," <default_parameters>
|
||||
|
||||
<required_parameter> ::= <parameter_type> <identifier>
|
||||
|
||||
<default_parameter> ::= <parameter_type> <identifier> ".default(" <literal> ")"
|
||||
|
||||
<lambda_declaration> ::= "fn" "(" <parameter_list>? ")"
|
||||
"->" "[" <type> "]"
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
<object_instantiation> ::= "new" <type> "(" <argument_list>? ")"
|
||||
|
||||
<type> ::= <identifier> ["/" <identifier>]?
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<type_declaration> ::= <inherited_type>
|
||||
["->" <interface_identifier_list>]?
|
||||
<interface_implementation>?
|
||||
"{" <class_body> "}"
|
||||
|
||||
<class_body> ::= (<variable_declaration>
|
||||
|
|
@ -20,3 +20,14 @@
|
|||
[".set(" <expression> ")"]? ";"
|
||||
|
||||
<constant_declaration> ::= <type> <identifier> ".define(" <literal> ");"
|
||||
|
||||
<constructor_declaration> ::=
|
||||
<accessibility_modifier> "on_create" "(" <parameter_list>? ")"
|
||||
["fails" "with" <error_type_list>]?
|
||||
"{" <statement>* "}"
|
||||
|
||||
<destructor_declaration> ::=
|
||||
<accessibility_modifier> "on_destroy" "(" <parameter_list>? ")"
|
||||
["fails" "with" <error_type_list>]?
|
||||
"{" <statement>* "}"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
<interface_declaration> ::= "@" <interface_identifier> "{" <interface_body> "}"
|
||||
<interface_declaration> ::= "@" [<interface_parent> "/"]? <interface_child>
|
||||
"{" <interface_body> "}"
|
||||
|
||||
<interface_identifier> ::= <identifier>
|
||||
<interface_parent> ::= <identifier>
|
||||
|
||||
<interface_child> ::= <identifier>
|
||||
|
||||
<interface_body> ::= <interface_method_declaration>*
|
||||
|
||||
<interface_method_declaration> ::=
|
||||
<accessibility_modifier> "fn" <identifier> <function_signature> ";"
|
||||
|
||||
<interface_implementation> ::= <type_declaration> "->" <interface_identifier_list>
|
||||
<interface_implementation> ::= "->" <interface_identifier_list>
|
||||
|
||||
<interface_method_signature> ::=
|
||||
<accessibility_modifier>"fn" <identifier> <function_signature>
|
||||
|
||||
<interface_inheritance> ::=
|
||||
"@" <interface_identifier> "extends" <interface_identifier_list>
|
||||
"{" <interface_body> "}"
|
||||
|
|
|
|||
|
|
@ -1,24 +1,20 @@
|
|||
<program> ::= <module_declaration>* <use_statement>* <declaration>*
|
||||
|
||||
<module_declaration> ::= "module" <identifier> "{"
|
||||
(<export_declaration> | <declaration>)*
|
||||
"}"
|
||||
|
||||
<export_declaration> ::= <accessibility_modifier>"export"
|
||||
(<type_declaration> | <function_declaration>)
|
||||
<program> ::= <use_statement>* <top_level_definition>*
|
||||
|
||||
<use_statement> ::= "use" <identifier> ("." <identifier>)* ";"
|
||||
|
||||
<top_level_definition> ::=
|
||||
<type_declaration>
|
||||
| <interface_declaration>
|
||||
| <error_declaration>
|
||||
|
||||
import "core/base_types.bnf"
|
||||
import "core/identifiers.bnf"
|
||||
import "core/literals.bnf"
|
||||
import "core/visibility.bnf"
|
||||
import "core/modules.bnf"
|
||||
import "declarations/error_declarations.bnf"
|
||||
import "declarations/type_declarations.bnf"
|
||||
import "declarations/function_declarations.bnf"
|
||||
import "declarations/object_instantiation.bnf"
|
||||
import "operations/expressions.bnf"
|
||||
import "operations/method_calls.bnf"
|
||||
import "operations/control_flow.bnf"
|
||||
import "interfaces/interface_definitions.bnf"
|
||||
import "modules/**/*.bnf"
|
||||
|
|
|
|||
|
|
@ -2,55 +2,6 @@ use core.accessibility_modifier;
|
|||
use core.identifier;
|
||||
use core.type_system;
|
||||
|
||||
module Directory {
|
||||
syntax {
|
||||
type_system.extend({
|
||||
name: "Directory",
|
||||
category: "system_resource",
|
||||
immutable_operations: true
|
||||
});
|
||||
}
|
||||
|
||||
// Directory permissions enum
|
||||
type DirectoryPermission {
|
||||
String read = "r";
|
||||
String write = "w";
|
||||
String execute = "x";
|
||||
}
|
||||
|
||||
// Core Directory type
|
||||
type Directory {
|
||||
String path;
|
||||
Integer item_count;
|
||||
|
||||
+fn on_create(String dirpath) -> [Directory];
|
||||
|
||||
+fn list_contents() -> [String<>];
|
||||
+fn create() -> [Boolean];
|
||||
|
||||
+fn exists() -> [Boolean];
|
||||
+fn delete() -> [Boolean];
|
||||
+fn move(String destination) -> [Boolean];
|
||||
+fn copy(String destination) -> [Boolean];
|
||||
|
||||
+fn get_permissions() -> [DirectoryPermission<>];
|
||||
+fn set_permissions(DirectoryPermission<> permissions) -> [Boolean];
|
||||
}
|
||||
|
||||
// Directory operations
|
||||
+fn create(String path) -> [Directory];
|
||||
+fn exists(String path) -> [Boolean];
|
||||
+fn delete(String path) -> [Boolean];
|
||||
+fn move(String source, String destination) -> [Boolean];
|
||||
+fn copy(String source, String destination) -> [Boolean];
|
||||
+fn list_contents(String path) -> [String<>];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module Directory {
|
||||
// Language extension configuration
|
||||
syntax {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
<if_statement> ::= "if" "(" <boolean_expression> ")"
|
||||
"{" <statement>* "}"
|
||||
["else" "{" <statement>* "}"]?
|
||||
["orif" "(" <boolean_expression> ")" "{" <statement>* "}"]?
|
||||
["otherwise" "{" <statement>* "}"]?
|
||||
|
||||
<while_statement> ::= "while" "(" <expression> ")"
|
||||
"{" <statement>* "}"
|
||||
|
|
|
|||
|
|
@ -1,34 +1,32 @@
|
|||
<expression> ::= <my_identifier>
|
||||
| <literal>
|
||||
| <object_method_call>
|
||||
| <constant_expression>
|
||||
| <object_instantiation>
|
||||
| <constant_declaration>
|
||||
| <type_conversion_expression>
|
||||
| "(" <expression> ")"
|
||||
| <lambda_expression>
|
||||
| <lambda_declaration>
|
||||
|
||||
<type_conversion_expression> ::= <my_identifier> ".as(" <type> ")"
|
||||
|
||||
<boolean_expression> ::=
|
||||
<boolean_literal>
|
||||
| "(" <boolean_expression> ")"
|
||||
| <my_identifier>.eq(<expression>)
|
||||
| <my_identifier>.is(<expression>)
|
||||
| <my_identifier>.not(<expression>)
|
||||
| <my_identifier>.gt(<expression>)
|
||||
| <my_identifier>.lt(<expression>)
|
||||
| <my_identifier>.gte(<expression>)
|
||||
| <my_identifier>.lte(<expression>)
|
||||
| <my_identifier>.and(<boolean_expression>)
|
||||
| <my_identifier>.or(<boolean_expression>)
|
||||
| Boolean.and(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.or(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.not(<boolean_expression>)
|
||||
| Boolean.eq(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.is(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.gt(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.lt(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.gte(<boolean_expression>, <boolean_expression>)
|
||||
| Boolean.lte(<boolean_expression>, <boolean_expression>)
|
||||
| <my_identifier> ".eq(" <expression> ")"
|
||||
| <my_identifier> ".is(" <expression> ")"
|
||||
| <my_identifier> ".not(" <expression> ")"
|
||||
| <my_identifier> ".gt(" <expression> ")"
|
||||
| <my_identifier> ".lt(" <expression> ")"
|
||||
| <my_identifier> ".gte(" <expression> ")"
|
||||
| <my_identifier> ".lte(" <expression> ")"
|
||||
| <my_identifier> ".and(" <boolean_expression> ")"
|
||||
| <my_identifier> ".or(" <boolean_expression> ")"
|
||||
| "Boolean.and(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.or(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.not(" <boolean_expression> ")"
|
||||
| "Boolean.eq(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.is(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.gt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.lt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.gte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.lte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
|
||||
<constant_expression> ::= <my_identifier> ".define(" <literal> ")"
|
||||
Loading…
Reference in a new issue