public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret) { var State = Container.State; if (RecognizerHelper.Find(this, State, Code.String).Position != -1) { var DeclListFlags = VarDeclarationListFlags.EnableUnnamed; if (Options.EnableMessages) { DeclListFlags |= VarDeclarationListFlags.EnableMessages; } var DeclList = VarDeclarationList.Create(Container, Code, null, DeclListFlags); if (DeclList == null) { return(SimpleRecResult.Failed); } Ret = DeclList.ToTupleType(Container, Options.EnableMessages); if (Ret == null) { return(SimpleRecResult.Failed); } if (Options.Func == null || Options.Func(Ret)) { return(SimpleRecResult.Succeeded); } } return(SimpleRecResult.Unknown); }
public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret) { var State = Container.State; var Result = RecognizerHelper.Find(this, State, Code.String); if (Result.Position != -1) { var Left = Code.TrimmedSubstring(State, 0, Result.Position, Options.EnableMessages); var Right = Code.TrimmedSubstring(State, Result.Position + 1, Options.EnableMessages); if (!Left.IsValid || !Right.IsValid) { return(SimpleRecResult.Failed); } Ret = Identifiers.GetMember(Container, Left, Right, Options); return(Ret == null ? SimpleRecResult.Failed : SimpleRecResult.Succeeded); } return(SimpleRecResult.Unknown); }
public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Out) { var State = Container.State; var Result = RecognizerHelper.Find(this, State, Code.String); if (Result.Position != -1) { var OldCode = Code; var Mods = Modifiers.Recognize(Container, ref Code); if (Mods == null) { return(SimpleRecResult.Failed); } Result.Position -= Code.Index - OldCode.Index; var Left = Code.TrimmedSubstring(State, 0, Result.Position, Options.EnableMessages); if (!Left.IsValid) { return(SimpleRecResult.Failed); } var Right = Code.TrimmedSubstring(State, Result.Position + Result.String.Length, Options.EnableMessages); if (!Right.IsValid) { return(SimpleRecResult.Failed); } var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue | VarDeclarationListFlags.EnableVoidOnly; if (Options.EnableMessages) { Flags |= VarDeclarationListFlags.EnableMessages; } var ParamDeclList = VarDeclarationList.Create(Container, Left, null, Flags); if (ParamDeclList == null) { return(SimpleRecResult.Failed); } if (ParamDeclList.Count == 1 && ParamDeclList[0].Type.RealId is VoidType) { ParamDeclList.RemoveAt(0); } var Params = ParamDeclList.ToFuncParams(Container.GetPlugin()); if (Params == null || Params.Contains(null)) { return(SimpleRecResult.Failed); } Flags &= ~VarDeclarationListFlags.EnableInitValue; var RetDeclList = VarDeclarationList.Create(Container, Right, null, Flags); if (RetDeclList == null) { return(SimpleRecResult.Failed); } Identifier RetType; if (RetDeclList.Count == 1 && !RetDeclList[0].Name.IsValid) { RetType = RetDeclList[0].Type; } else { RetType = RetDeclList.ToTupleType(Container, Options.EnableMessages); if (RetType == null) { return(SimpleRecResult.Failed); } } var CallConv = Container.DefaultCallConv; var Succeeded = true; var Static = false; Mods.ForEach(x => { if (x is CallingConventionModifier) { var CCM = x as CallingConventionModifier; CallConv = CCM.CallingConvention; } else if (x is FlagModifier) { var FM = x as FlagModifier; if ((FM.Flags & IdentifierFlags.Static) != 0) { Static = true; } if ((FM.Flags & ~IdentifierFlags.Static) != 0) { if (Options.EnableMessages) { State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code); } Succeeded = false; } } else { if (Options.EnableMessages) { State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code); } Succeeded = false; } }); if (!Succeeded) { return(SimpleRecResult.Failed); } Identifier FuncType = new TypeOfFunction(Container, CallConv, RetType, Params); Out = Static ? FuncType : new NonstaticFunctionType(Container, FuncType); if (Options.Func == null || Options.Func(Out)) { return(SimpleRecResult.Succeeded); } return(SimpleRecResult.Succeeded); } return(SimpleRecResult.Unknown); }