diff --git a/.gitignore b/.gitignore index 56bcbd6..3a55b65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +.idea + prompt.sh -prompt.txt \ No newline at end of file +prompt.txt +compile_grammar.sh +waddle.bnf diff --git a/README.md b/README.md index f760e9d..c7a93ae 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,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)); diff --git a/grammar/core/literals.bnf b/grammar/core/literals.bnf index 2e4bec1..02156a5 100644 --- a/grammar/core/literals.bnf +++ b/grammar/core/literals.bnf @@ -12,7 +12,7 @@ ::= + "." + | "-" + "." + - ::= '"' [^"]* '"' + ::= '"' [^\"]* '"' | "'" [^']* "'" ::= "True" | "False" diff --git a/grammar/core/modules.bnf b/grammar/core/modules.bnf deleted file mode 100644 index 3bf83cf..0000000 --- a/grammar/core/modules.bnf +++ /dev/null @@ -1,16 +0,0 @@ - ::= "module" "{" - ( - | - | )* -"}" - - ::= - "export" - ( - | - | ) - - ::= - - ( - | ) \ No newline at end of file diff --git a/grammar/core/visibility.bnf b/grammar/core/visibility.bnf index a089d7d..e03c6f6 100644 --- a/grammar/core/visibility.bnf +++ b/grammar/core/visibility.bnf @@ -2,4 +2,3 @@ "-" | "" | "+" - | "export" diff --git a/grammar/declarations/error_declarations.bnf b/grammar/declarations/error_declarations.bnf index c71b2e8..9a6a145 100644 --- a/grammar/declarations/error_declarations.bnf +++ b/grammar/declarations/error_declarations.bnf @@ -1,7 +1,13 @@ - ::= - ["/" ]? + ::= "{" ? "}" + ::= [ "/"]? + + ::= + + ::= + ::= ( | | )* + diff --git a/grammar/declarations/function_declarations.bnf b/grammar/declarations/function_declarations.bnf index e68ac48..6312dce 100644 --- a/grammar/declarations/function_declarations.bnf +++ b/grammar/declarations/function_declarations.bnf @@ -10,13 +10,25 @@ ::= ["/" ]? - ::= - ("," )* - [("," )*] + ::= + ? - ::= ":" + ::= + + | "," + | - ::= ".default(" ")" + ::= + + | "," + + ::= + + | "," + + ::= + + ::= ".default(" ")" ::= "fn" "(" ? ")" "->" "[" "]" diff --git a/grammar/declarations/object_instantiation.bnf b/grammar/declarations/object_instantiation.bnf deleted file mode 100644 index c435f7b..0000000 --- a/grammar/declarations/object_instantiation.bnf +++ /dev/null @@ -1,3 +0,0 @@ - ::= "new" "(" ? ")" - - ::= ["/" ]? diff --git a/grammar/declarations/type_declarations.bnf b/grammar/declarations/type_declarations.bnf index 49a9d81..9ac24b1 100644 --- a/grammar/declarations/type_declarations.bnf +++ b/grammar/declarations/type_declarations.bnf @@ -1,5 +1,5 @@ ::= - ["->" ]? + ? "{" "}" ::= ( @@ -20,3 +20,14 @@ [".set(" ")"]? ";" ::= ".define(" ");" + + ::= + "on_create" "(" ? ")" + ["fails" "with" ]? + "{" * "}" + + ::= + "on_destroy" "(" ? ")" + ["fails" "with" ]? + "{" * "}" + diff --git a/grammar/interfaces/interface_definitions.bnf b/grammar/interfaces/interface_definitions.bnf index 884c607..5f8163d 100644 --- a/grammar/interfaces/interface_definitions.bnf +++ b/grammar/interfaces/interface_definitions.bnf @@ -1,17 +1,16 @@ - ::= "@" "{" "}" + ::= "@" [ "/"]? + "{" "}" - ::= + ::= + + ::= ::= * ::= "fn" ";" - ::= "->" + ::= "->" ::= "fn" - - ::= - "@" "extends" - "{" "}" diff --git a/grammar/main.bnf b/grammar/main.bnf index 3e916d1..c243549 100644 --- a/grammar/main.bnf +++ b/grammar/main.bnf @@ -1,24 +1,20 @@ - ::= * * * - - ::= "module" "{" - ( | )* -"}" - - ::= "export" - ( | ) + ::= * * ::= "use" ("." )* ";" + ::= + + | + | + 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" diff --git a/grammar/modules/core/directory.wdl b/grammar/modules/core/directory.wdl index 6f1a38f..64c5885 100644 --- a/grammar/modules/core/directory.wdl +++ b/grammar/modules/core/directory.wdl @@ -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 { diff --git a/grammar/operations/control_flow.bnf b/grammar/operations/control_flow.bnf index a4f97ac..32f073e 100644 --- a/grammar/operations/control_flow.bnf +++ b/grammar/operations/control_flow.bnf @@ -13,7 +13,8 @@ ::= "if" "(" ")" "{" * "}" - ["else" "{" * "}"]? + ["orif" "(" ")" "{" * "}"]? + ["otherwise" "{" * "}"]? ::= "while" "(" ")" "{" * "}" diff --git a/grammar/operations/expressions.bnf b/grammar/operations/expressions.bnf index 0c84e6c..7a82e23 100644 --- a/grammar/operations/expressions.bnf +++ b/grammar/operations/expressions.bnf @@ -1,34 +1,32 @@ ::= | | - | - | + | | | "(" ")" - | + | ::= ".as(" ")" ::= | "(" ")" - | .eq() - | .is() - | .not() - | .gt() - | .lt() - | .gte() - | .lte() - | .and() - | .or() - | Boolean.and(, ) - | Boolean.or(, ) - | Boolean.not() - | Boolean.eq(, ) - | Boolean.is(, ) - | Boolean.gt(, ) - | Boolean.lt(, ) - | Boolean.gte(, ) - | Boolean.lte(, ) + | ".eq(" ")" + | ".is(" ")" + | ".not(" ")" + | ".gt(" ")" + | ".lt(" ")" + | ".gte(" ")" + | ".lte(" ")" + | ".and(" ")" + | ".or(" ")" + | "Boolean.and(" "," ")" + | "Boolean.or(" "," ")" + | "Boolean.not(" ")" + | "Boolean.eq(" "," ")" + | "Boolean.is(" "," ")" + | "Boolean.gt(" "," ")" + | "Boolean.lt(" "," ")" + | "Boolean.gte(" "," ")" + | "Boolean.lte(" "," ")" - ::= ".define(" ")" \ No newline at end of file