fix: top level block, even isolated, is treated as a lambda too
This commit is contained in:
		
							parent
							
								
									c0cf190452
								
							
						
					
					
						commit
						4dc73b91c2
					
				@ -47,7 +47,7 @@ One interesting way of using closure isolation is to keep state of the functions
 | 
			
		||||
    >>> 0
 | 
			
		||||
    >>> 1
 | 
			
		||||
    >>> 2
 | 
			
		||||
    >> void
 | 
			
		||||
    >>> void
 | 
			
		||||
 | 
			
		||||
Inner `counter` is not accessible from outside, no way; still it is kept 
 | 
			
		||||
between calls in the closure, as inner function `doit`, returned from the
 | 
			
		||||
 | 
			
		||||
@ -16,14 +16,14 @@ class Compiler(
 | 
			
		||||
 | 
			
		||||
    private fun parseScript(start: Pos, tokens: CompilerContext): Script {
 | 
			
		||||
        val statements = mutableListOf<Statement>()
 | 
			
		||||
        while (parseStatement(tokens)?.also {
 | 
			
		||||
        while (parseStatement(tokens,braceMeansLambda = true)?.also {
 | 
			
		||||
                statements += it
 | 
			
		||||
            } != null) {/**/
 | 
			
		||||
        }
 | 
			
		||||
        return Script(start, statements)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun parseStatement(cc: CompilerContext): Statement? {
 | 
			
		||||
    private fun parseStatement(cc: CompilerContext,braceMeansLambda: Boolean = false): Statement? {
 | 
			
		||||
        while (true) {
 | 
			
		||||
            val t = cc.next()
 | 
			
		||||
            return when (t.type) {
 | 
			
		||||
@ -49,7 +49,10 @@ class Compiler(
 | 
			
		||||
 | 
			
		||||
                Token.Type.LBRACE -> {
 | 
			
		||||
                    cc.previous()
 | 
			
		||||
                    parseBlock(cc)
 | 
			
		||||
                    if( braceMeansLambda )
 | 
			
		||||
                        parseExpression(cc)
 | 
			
		||||
                    else
 | 
			
		||||
                        parseBlock(cc)
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Token.Type.RBRACE -> {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user