Browse Source

Ponder design of fields more.

Beoran 4 years ago
parent
commit
e2418a21b7
2 changed files with 64 additions and 23 deletions
  1. 41 23
      design_muesli.muesli
  2. 23 0
      parser.go

+ 41 - 23
design_muesli.muesli

@@ -88,12 +88,24 @@ command {
     print "second block"
 }
 
-# In Muesli all values are typed. Types can be defined by the builtin type command.
-type Door ( object locked Bool keys Item[] )
+# In Muesli all values are typed. Types can be defined by the builtin type 
+# command. User defined types always are derived from Object or from another
+# built in type. They add the fields mentioned with their given types. 
+type Door Object name String locked Bool keys Int[]
+
+# A value of defined type can be created using the new command
+set door1 (new Door "red door" true [])
 
 # Commands can be defined by the built in 'to' command. 
 # They can have many arguments and many results.
-to open[door Door key Item]  Bool {
+to openDoor [door Door key Item] Bool {
+    if (contains (member door key) key) {
+        set (member door open) true
+    }
+}
+
+# Methods can be also defined with the to command
+to Door open [key Item] Bool {
     if (contains (member door key) key) {
         set (member door open) true
     }
@@ -113,7 +125,7 @@ to open[door Door key Item]  Bool {
 # To create such an overload you should create a "cover" with the builtin 
 # cover command. Covers are commands that dispatch to other commands based on 
 # the types of the arguments. 
-cover open open[door Door key Item]
+cover open openDoor[door Door key Item]
 
 # Variables are not part of the language but there are builtin commands
 # to define them. Variables are set in the current scope with
@@ -167,26 +179,32 @@ if (less a 10) {
 $foo 
 #
 
+# There are built in functions for getting, setting and invoking the fields 
+# of object valued types:
+of $door1 name # "red door"
+make $door1 name "green door"
+invoke $door1 open $key 
+
+# Since these three are common, there is syntax available to
+# abbreviate this, using ' or 's or ,  and ;  :
+door1's name # same as (of $door1 name)
+door1's name  "green door" # same as (make $door1 name "green door")
+door1, open $key1 # same as invoke $door1 open $key1, open must be a 
+# callable method
+
+
+# It is possible to define keywords. These get replaced by a single token.
+# This allows to have an English-like or other natural language-like syntax.
+# For example, openDoor above can also be defined as follows:
+to openDoor list door Door key Item done Bool do
+    if as contains as of a door key so a key so do
+        make a door open true
+    end
+end
+
+
 # That's all there is to the syntax. Apart from the built in commands, 
 # the semantics are up to you to implement as 
-# embedded commands, or by redirecting the command output and input.
+# embedded commands or operators.
 # Do note that MUESLI uses dynamic scoping for ease of implementation
 
-#{
-
-BLOCK
-PUSHS "More"
-CALL print
-PUSHBLOCK
-PUSHW else
-BLOCK
-PUSHS "Less"
-CALL print
-PUSHBLOCK
-PUSHI 10
-PUSHW a
-CALL less
-CALL if
-
-}
-

+ 23 - 0
parser.go

@@ -84,6 +84,29 @@ as follows:
 - A name also evaluates as itself but is specific for commands.
 
 
+or, yet again:
+
+PROGRAM -> STATEMENTS.
+STATEMENTS -> STATEMENT eos STATEMENTS|.
+STATEMENT -> EXPRESSION OPERATION |.
+OPERATION -> operator STATEMENT |.
+EXPRESSION -> COMMAND | EVALUATION .
+COMMAND -> FIELD PARAMETERS. 
+FIELD -> NAME SELECTORS ASSIGNMENT.
+SELECTORS -> selector NAME SELECTORS |.
+ASSIGNMENT -> is PARAMETER |. 
+PARAMETERS -> PARAMETER PARAMETERS |.
+PARAMETER -> FIELD | EVALUATION .
+EVALUATION -> LITERAL | BLOCK | GETTER | SETTER | LIST | PARENTHESIS  .
+PARENTHESIS -> closeparen STATEMENT openparen.
+BLOCK -> openblock STATEMENTS closeblock.
+LIST -> openlist PARAMETERS closelist.
+LITERAL -> string | int | float.
+NAME -> word | symbol | type.
+SETTER -> set PARAMETER PARAMETER.
+GETTER -> get PARAMETER.
+
+
 */
 
 type Parser struct {