// 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."); } }
// Syntax: // Member = '.' StaticMember . public ExpState ParseMember(Type theClass, LexList list, BindingFlags flags, bool implicitDot) { if (!implicitDot) { list.CheckStrAndAdvance(".", "Expected a dot followed by a static member name here."); } LexToken token = list.CurrentToken(); string name = list.GetIdentifier("Expected the name of a static member here."); FieldInfo fi = theClass.GetField(name, flags); if (fi != null) { return(new ExpState(fi)); } list.Prev(); return(null); }
// Each method declaration starts with a 'private' or a 'public' and then continues as per a method processed in MakeMethod.cs private CompileMethod DoOneMethod(LexList theLexList) { BindingFlags vis = BindingFlags.Public; if (theLexList.Str == "public") { vis = BindingFlags.Public; } else if (theLexList.Str == "private") { vis = BindingFlags.NonPublic; } else { theLexList.ThrowException("Expected this method to be marked either public or private."); } theLexList.Next(); CompileMethod cm = new CompileMethod(Parser, theLexList, ClassType, vis); theLexList.CheckStrAndAdvance("}", "Expected a closing } at the end of the method."); return(cm); }
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); }