design_muesli.muesli 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Muesli is a Multi Use Embeddable Scripting Language Indeed.
  2. # It is a scripting language with a TCL or shell like syntax, but somewhat
  3. # OOP and LISP like semantics.
  4. # First it will be an embeddable scripting language implemented in Go.
  5. # In what follows I will describe the design of the language though example.
  6. #
  7. # Why is there a # before these lines? # begins a comment, until the end of the
  8. # line. MUESLI does not execute comments but they are collected
  9. # for documentation purposes. More on that topic later
  10. # Muesli is a line based language.
  11. # A newline preceded by a \ is ignored, even after a comment so \
  12. this is still comment
  13. # Muesli consists of newline separated statements, however, a newline
  14. # after { or the do keyword is ignored and does not count as a separator.
  15. #{ This is a block comment, it nests
  16. but the {} pairs must match.
  17. }
  18. # Empty lines are ignored.
  19. # ...
  20. # Muesli supports integer constants with type Int
  21. 1
  22. 2
  23. 378
  24. +108
  25. -878
  26. # ... Character constants with escapes with type Rune
  27. # This may also be unicode code points if above ascii range.
  28. 'a'
  29. # It also supports multi line string constants with escapes, with type String
  30. "Hello world\"
  31. "
  32. # and multi line strings without escapes
  33. `
  34. "Pop" goes the
  35. weasel's tail.
  36. `
  37. # And booleans constants of type Bool
  38. !true !false
  39. # And simple floating point constants, but no exponential notation, with type Float
  40. +0.5
  41. -7.000005
  42. # Lists can be created between [ ] and may be heterogenous or homogenous.
  43. # The [ ] must be space separated.
  44. # The type is Any[] if heterogenous,
  45. [ foo "bar" ]
  46. # The type is Int@ below
  47. [ 1 2 3 ]
  48. # A sequence of a lower case letter followed by anything that is not whitespace.
  49. # For example: this-IS*a/single+Word._
  50. # The value of a word is a string with the word itself.
  51. # If the word is at the beginning of the line it is invoked as a command.
  52. # Muesli's basic syntax is that of the command. Spaces separate the arguments.
  53. # of the command. The first word is the command, the rest are the arguments.
  54. print "hello" world 7 0.9
  55. # the previous command outputs: "hello world 7 0.9" to standard output
  56. # A command has one or more results that can be captured with a parenthesis
  57. print ( mul 3 ( sum 5 7 ) )
  58. # Commands can be grouped into blocks. The value of the block is that of it's last command.
  59. {
  60. print "hello"
  61. print "world"
  62. }
  63. # Commands can also take blocks as parameters. Don't put a newline between } and {
  64. # to be sure multiple blocks get passed
  65. command {
  66. print "first block"
  67. } and also {
  68. print "second block"
  69. }
  70. # In Muesli all values are typed. Types can be defined by the built type command.
  71. type Door ( object locked Bool keys Item[] )
  72. # Commands can be defined by the built in 'to' command.
  73. # They can have many arguments and many results.
  74. to open [door Door key Item] Bool {
  75. if (contains (member door key) key) {
  76. set
  77. }
  78. }
  79. # Unlike TCL, MUESLI values are typed, and commands
  80. # can be overloaded based on the types the types of their arguments.
  81. # Types are much like words, but they begin with an upper case letter, up to the
  82. # next whitespace.
  83. # A type that end in [] is a list, [][] a list of lists, etc, and a type
  84. # that end in ... represents a variable argument, which must be last.
  85. # Muesli tries to match the types, from narrow to wide for objects in the order
  86. # Outer class, Embedded Class, Object, Any,
  87. # and for primitive types <Bool|Int|String|Float|Word|Type>, Primitive, Any
  88. # You can override commands with more specific ones but not existing ones
  89. # that have the same specificity.
  90. # Variables are nor part of the language but of the built in commands
  91. # Variables are set in the current scope with
  92. set a 10
  93. # And fetched in the current scope with get
  94. print (get a 10)
  95. # To acces a variable in the scope one above current use upset/upget.
  96. upset a 10
  97. # However, there is syntactic sugar:
  98. # =foo bar gets mapped to (set foo bar)
  99. =a 10
  100. # $foo means (get foo)
  101. print $a
  102. # combinations of = followed by $ are allowed for indirect variable assignment
  103. =foo a
  104. =$foo 20
  105. print $a
  106. # Control structures are merely built in functions.
  107. if (less a 10) {
  108. print "Less"
  109. } else {
  110. print "More"
  111. }
  112. # That's all there is to the syntax. Apart from the built in commands,
  113. # the semantics are up to you to implement as
  114. # embedded commands.
  115. /*
  116. BLOCK
  117. PUSHS "More"
  118. CALL print
  119. PUSHBLOCK
  120. PUSHW else
  121. BLOCK
  122. PUSHS "Less"
  123. CALL print
  124. PUSHBLOCK
  125. PUSHI 10
  126. PUSHW a
  127. CALL less
  128. CALL if
  129. */