/// <summary> /// Create CodeNode representing hierarchy sequence. /// </summary> /// <returns>CodeNode created according to layout.</returns> public CodeNode HierarchyLayout() { var node = new CodeNode(_lexer.Move(), NodeTypes.hierarchy); if (_checkToken("("))//function call { node.NodeType = NodeTypes.call; resolveBracket(() => { node.AddArgument(_nextTree()); return(false); }, "(", ",", ")", "Error in call, expected '{0}'"); //on fail throw exception node.EndingToken = _lexer.Current.Previous; //aby ukazoval na zavorku } if (_shiftToken(".")) { var child = HierarchyLayout(); if (child == null) { throw CSharpSyntax.ParsingException(_lexer.Current, "Expected identifier after '.'"); } node.Child = child; } if (_checkToken("[")) { var indexer = IndexerLayout(); node.SetIndexer(indexer); } if (_checkToken("{")) //initializer { var seq = InitializerLayout(); node.SetSubsequence(seq); } return(node); }
/// <summary> /// Create <see cref="CodeNode"/> representing implicitly typed array with initializer /// </summary> /// <returns></returns> public CodeNode ImplicitArray() { var node = new CodeNode(_lexer.Move(), NodeTypes.hierarchy); _shiftToken("]", "Expected '{0}' for implicitly typed array"); //_shiftToken("{", "Expected '{0}' initializer expected for implicitly type array"); var initializer = InitializerLayout(); node.SetSubsequence(initializer); node.EndingToken = _lexer.Current; return(node); }
private CodeNode treeItemsLayout(string delimiter, bool canSkipDelim) { var node = new CodeNode(_lexer.Current, NodeTypes.block); var lines = new List <CodeNode>(); resolveBracket(() => addNode(lines, canSkipDelim), "{", delimiter, "}", "Error in sequence, expected '" + delimiter + "'"); node.SetSubsequence(lines, _lexer.Current.Previous); if (_lexer.Current.Value == delimiter) { node.EndingToken = _lexer.Current; } return(node); }
/// <summary> /// Create CodeNode representing switch block. /// </summary> /// <returns>CodeNode created according to layout.</returns> public CodeNode SwitchLayout() { var switchNode = new CodeNode(_lexer.Move(), NodeTypes.block); condition(switchNode); _shiftToken("{", "expected '{' in switch layout"); var inSwitch = true; while (inSwitch) { var label = _current(); switch (label) { case "case": case "default": var labelBlock = new CodeNode(_lexer.Move(), NodeTypes.block); if (labelBlock.Value == "case") { labelBlock.AddArgument(_nextTree()); } _shiftToken(":", "expected '{0}' after '{1}', in switch statement", label); var lines = new List <CodeNode>(); while (_current() != "case" && _current() != "default" && _current() != "}") { lines.Add(_nextTree()); _shiftToken(";"); } labelBlock.SetSubsequence(lines, _lexer.Current); switchNode.AddArgument(labelBlock); break; case "}": inSwitch = false; break; default: throw CSharpSyntax.ParsingException(_lexer.Current, "unrecognized label '{0}' in switch statement", label); } } _shiftToken("}", "expected '{0}' in switch layout"); return(switchNode); }