| @@ -132,10 +132,19 @@ static int is_numeric(int ch) { | |||
| static int skip_whitespace(struct l2_lexer *lexer) { | |||
| int nl = 0; | |||
| while (is_whitespace(peek_ch(lexer))) { | |||
| int ch = read_ch(lexer); | |||
| if (ch == '\n') { | |||
| while (1) { | |||
| while (is_whitespace(peek_ch(lexer))) { | |||
| int ch = read_ch(lexer); | |||
| if (ch == '\n') { | |||
| nl = 1; | |||
| } | |||
| } | |||
| if (peek_ch(lexer) == '#') { | |||
| nl = 1; | |||
| while (read_ch(lexer) != '\n'); | |||
| } else { | |||
| break; | |||
| } | |||
| } | |||
| @@ -1,7 +1,10 @@ | |||
| arr := [10 20 30] | |||
| print arr | |||
| # Lookup into the array with dot-number | |||
| print arr.2 | |||
| # Assign to an index of the array | |||
| arr.1 = "nope" | |||
| print arr | |||
| @@ -1,16 +1,21 @@ | |||
| # Lookup array values dynamically | |||
| idx := 0 | |||
| arr := [100 20 30] | |||
| print arr.(idx) | |||
| # More complex expressions in the subscript operation | |||
| arr.(+ idx 1) = 50 | |||
| print arr | |||
| # Lookup into a temporary | |||
| print [10 20 30].(+ 1 1) | |||
| # Lookup into a namespace by atom | |||
| obj := {} | |||
| obj.('hello) = "what's up" | |||
| print obj.hello | |||
| # More complicated expression again | |||
| get-ident := {'foo} | |||
| obj.(get-ident()) = 100 | |||
| print obj.foo | |||
| @@ -1,28 +1,46 @@ | |||
| # Functions return their last expression | |||
| func := { | |||
| "hello" | |||
| } | |||
| # Call a function without arguments using () | |||
| print func() | |||
| # A function, returning a function, with a closure so that it can access | |||
| # variables from outside | |||
| str := "Hello World" | |||
| func := { | |||
| { | |||
| str | |||
| } | |||
| } | |||
| # func() returns a function, which can be called again with an extra () | |||
| print func()() | |||
| func := { | |||
| { | |||
| # $ is a variable containing the arguments passed to the function, | |||
| # so this nested function sets the global 'str' variable to whatever | |||
| # the function is passed | |||
| str = $.0 | |||
| } | |||
| } | |||
| # func() calls the 'func' function with no arguemnts, and the nested function | |||
| # is returned. That returned function is then called with 10 as a parameter. | |||
| func() 10 | |||
| # Since the nested function modified it, 'str' should now be the number 10 | |||
| print str | |||
| func := { | |||
| # Variables don't have to be global; this function returns a function which | |||
| # has a reference to the 'retval' variable | |||
| retval := "what's up" | |||
| {retval} | |||
| } | |||
| print func()() | |||
| # Lastly, just print a function literal | |||
| print {0} | |||
| @@ -3,10 +3,13 @@ obj := { | |||
| } | |||
| print obj.foo | |||
| # Assignments | |||
| obj.foo = 100 | |||
| print obj.foo | |||
| # Nested namespaces should work | |||
| obj.bar = {baz: "how's your day going?"} | |||
| print obj.bar.baz | |||
| # Empty namespace literal (should parse to namespace, not function) | |||
| print {} | |||