private static int CountCommas(LexList list, int rank, bool arrayIndexActualsAllowed) { Stack <string> stack = new Stack <string>(); if (arrayIndexActualsAllowed) { int saveIndex = list.Index - 1; bool finished = false; while (!list.AtEnd() && !finished) { switch (list.Str) { case ",": if (stack.Count == 0) { rank++; } break; case "(": stack.Push(")"); break; case "{": stack.Push("}"); break; case "[": stack.Push("]"); break; case ")": case "}": if (stack.Pop() != list.Str) { list.ThrowException("Unbalanced brackets in array initialiser"); } break; case "]": if (stack.Count == 0) { list.Prev(); finished = true; } else { if (stack.Pop() != list.Str) { list.ThrowException("Unbalanced brackets in array initialiser"); } } break; } list.Next(); } list.Index = saveIndex; } else { while (list.Str == ",") { list.Next(); rank++; } } return(rank); }
// ClassVisibility = ( 'partial' 'class' | 'class' 'partial' ) . private void DoClassVisibility() { if (InputList.AtEnd()) { InputList.ThrowException("Unexpected end of text."); } if (InputList.Str == "partial") { InputList.Next(); InputList.CheckStrAndAdvance("class", "Expected a 'class' after the 'partial'."); } else if (InputList.Str == "class") { InputList.Next(); InputList.CheckStrAndAdvance("partial", "Expected a 'partial' after the 'class'."); } else { InputList.ThrowException("Expected either a 'partial class' or a 'class partial' here."); } }
public MakeClass AddMethodsAndFields(LexList list, bool overwriteAllowed) { if (InputList != null) { PreviousInputLists.Add(InputList); } InputList = list; Type varType = null; var currentListOfMethods = new List <CompileMethod>(); try { Crosslink(); DoClassVisibility(); DoClassType(); InputList.CheckStrAndAdvance("{", "Expected an { after the class header."); while (true) { if (InputList.Str == "}" && InputList.NextIsAtEnd()) { break; } else if ((InputList.Str == "public" || InputList.Str == "private" || InputList.Str == "[") && !IsAFieldDefinition()) { CompileNextMethodHeader(InputList, overwriteAllowed, currentListOfMethods); } else if ((InputList.Str == "public" || InputList.Str == "private") && IsAFieldDefinition()) { InputList.Next(); varType = IsVarKind(); if (varType == null) { InputList.ThrowException("Unknown field type here"); } CompileNextFieldDefinition(InputList, varType); } else if ((varType = IsVarKind()) != null) { CompileNextFieldDefinition(InputList, varType); } else { InputList.ThrowException("Expected either a 'public' or 'private' keyword (to start a method) or a type (to start a field declaration) here or the closing } of the class."); } } InputList.CheckStrAndAdvance("}", "Expected a closing } here."); if (!InputList.AtEnd()) { InputList.ThrowException("Expected the end of the source text here."); } if (MadeFieldsDict.Count > 0) { MakeFieldInitialiser(currentListOfMethods); } FinishClass(currentListOfMethods); } catch (LexListException lle) { throw lle; } catch (Exception ex) { list.CurrentToken().ThrowException(ex.Message, list); } return(this); }