protected virtual BlockNode ParseBlock(IPrimaryParentNode parent, SpecialCharacterToken leftBracket) { // PARSE: <block constructor> ::= '[' <block body> ']' // <block body> ::= [<block argument>* '|'] [<temporaries>] [<statements>] // <block argument> ::= ':' identifier BlockNode result = new BlockNode(parent, leftBracket); // PARSE: [<block argument>* '|'] // ISSUE: It this a bug in X3J20. Shouldn't it be: [<block argument>+ '|'] // The current definition allows blocks like: [ | ] ... or ... [ | self doStuff ] ... or ... [ | | temp | temp := self something ] // We assume X3J20 bug and expect: [<block argument>+ '|'] VerticalBarToken argumentsBar = null; List <BlockArgumentNode> arguments = new List <BlockArgumentNode>(); Token token = this.GetNextTokenxx(Preference.VerticalBar | Preference.NegativeSign); // Check if the block has arguments if (Parser.IsBlockArgumentPrefix(token)) { // ... yes arguments ... parse them ... while (true) { if (Parser.IsBlockArgumentPrefix(token)) { // <block argument> arguments.Add(this.ParseBlockArgument(result, (SpecialCharacterToken)token)); } else if (token is VerticalBarToken) { // The '|' after the arguments. argumentsBar = (VerticalBarToken)token; token = this.GetNextTokenxx(Preference.NegativeSign | Preference.VerticalBar); break; // Done with block arguments } else { this.ReportParserError(result, SemanticErrors.MissingBlockClosingArgsBar, token); break; } // Get the next token token = this.GetNextTokenxx(Preference.VerticalBar | Preference.NegativeSign); } } // PARSE: [<temporaries>] ParseTemporariesResult ptr = this.ParseTemporaries(result, token); // PARSE: <statements> token = this.GetNextTokenxx(Preference.NegativeSign); StatementNode statements = this.ParseStatement(result, token); // Ensure the block is properly closed. SpecialCharacterToken rightBracket = null; token = this.GetNextTokenxx(Preference.Default); if (!Parser.IsBlockEndDelimiter(token)) { this.ReportParserError(result, SemanticErrors.MissingBlockClosingBracket, token); this.ResidueToken = token; } else { rightBracket = (SpecialCharacterToken)token; } result.SetContents(arguments, argumentsBar, ptr.LeftBar, ptr.Temporaries, ptr.RightBar, statements, rightBracket); return(result); }