public static NodeGroup GetGroups(PluginRoot Plugin, CodeString Code, char BracketLeft = '{', char BracketRight = '}') { var Ret = new NodeGroup(Code); var State = Plugin.State; var List = RecognizerHelper.SplitToParameters(State, Code, ','); if (List == null) { return(null); } for (var i = 0; i < List.Length; i++) { var Param = List[i]; if (Param.Length > 1 && Param[0] == BracketLeft && Param[Param.Length] == BracketLeft) { Param = Param.Substring(1, Param.Length - 1).Trim(); Ret.Children.Add(Expressions.GetGroups(Plugin, Param)); } else { var Node = Expressions.Recognize(Param, Plugin); if (Node == null) { return(null); } Ret.Children.Add(Node); } } return(Ret); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { var InnerCode = BetweenOperatos(Code); if (!InnerCode.IsValid) { return(ExprRecResult.Unknown); } var String = RecognizerHelper.ProcessString(InnerCode, Plugin, '~'); if (String == null) { return(ExprRecResult.Failed); } if (String.Length != 1) { Plugin.State.Messages.Add(MessageId.CharInvalidLength, Code); return(ExprRecResult.Failed); } var Global = Plugin.Container.GlobalContainer; Ret = new ConstExpressionNode(Global.CommonIds.Char, new CharValue(String[0]), Code); return(ExprRecResult.Succeeded); }
public SimpleRecResult GetGenericParams(CompilerState State, ref CodeString Code, out CodeString[] Out, bool EnableMessages = true) { Out = null; if (Code.Length > 0 && Code[Code.Length - 1] == '>') { var BracketPos = Code.GetBracketPos(State, true); if (BracketPos == -1) { return(SimpleRecResult.Failed); } var ParamStart = BracketPos + 1; var StrParams = Code.TrimmedSubstring(State, ParamStart, Code.Length - ParamStart - 1); if (!StrParams.IsValid) { return(SimpleRecResult.Failed); } Out = RecognizerHelper.GetParamList(State, StrParams); if (Out == null) { return(SimpleRecResult.Failed); } Code = Code.Substring(0, BracketPos).Trim(); } return(SimpleRecResult.Unknown); }
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, ref CodeString Code, List <Modifier> Out) { var State = Container.State; CodeString Inside, Cutted; var Result = RecognizerHelper.ExtractBracket(State, String, '(', ref Code, out Inside, out Cutted); if (Result == SimpleRecResult.Succeeded) { var Params = RecognizerHelper.GetParamList(State, Inside, 1); if (Params == null) { return(SimpleRecResult.Failed); } var Node = Constants.CreateCStrNode(Container, Params[0]); if (Node == null) { return(SimpleRecResult.Failed); } var AsmName = Node.String; if (string.IsNullOrEmpty(AsmName)) { State.Messages.Add(MessageId.DeficientExpr, Params[0]); return(SimpleRecResult.Failed); } for (var i = 0; i < Out.Count; i++) { if (Out[i] is AssemblyNameModifier) { State.Messages.Add(MessageId.NotExpected, Cutted); return(SimpleRecResult.Failed); } } Out.Add(new AssemblyNameModifier(Cutted, AsmName)); return(SimpleRecResult.Succeeded); } return(Result); }
public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out) { var State = Container.State; CodeString Inside, Cutted; var Result = RecognizerHelper.ExtractBracket(State, String, '(', ref Code, out Inside, out Cutted); if (Result == SimpleRecResult.Succeeded) { var Params = RecognizerHelper.GetParamList(State, Inside, 1); if (Params == null) { return(SimpleRecResult.Failed); } var Node = Constants.CreateCIntNode(Container, Params[0]); if (Node == null) { return(SimpleRecResult.Failed); } var Align = (int)Node.Integer; if (!DataStoring.VerifyAlign(Align)) { State.Messages.Add(MessageId.InvalidAlign, Cutted); return(SimpleRecResult.Failed); } for (var i = 0; i < Out.Count; i++) { if (Out[i] is AlignModifier) { State.Messages.Add(MessageId.NotExpected, Cutted); return(SimpleRecResult.Failed); } } Out.Add(new AlignModifier(Cutted, Align)); return(SimpleRecResult.Succeeded); } return(Result); }
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 ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { var InnerCode = BetweenOperatos(Code); if (!InnerCode.IsValid) { return(ExprRecResult.Unknown); } var String = RecognizerHelper.ProcessString(InnerCode, Plugin, '~'); if (String == null) { return(ExprRecResult.Failed); } var Global = Plugin.Container.GlobalContainer; Ret = new ConstExpressionNode(Global.CommonIds.String, new StringValue(String), Code); return(ExprRecResult.Succeeded); }
private void SetDefaultRecognizerByCurrentInputMethodLanguageTag() { // Query recognizer name based on current input method language tag (bcp47 tag) Language currentInputLanguage = _textServiceManager.InputLanguage; if (currentInputLanguage != _previousInputLanguage) { // try query with the full BCP47 name string recognizerName = RecognizerHelper.LanguageTagToRecognizerName(currentInputLanguage.LanguageTag); if (recognizerName != string.Empty) { for (int index = 0; index < _recoView.Count; index++) { if (_recoView[index].Name == recognizerName) { _inkRecognizerContainer.SetDefaultRecognizer(_recoView[index]); _previousInputLanguage = currentInputLanguage; break; } } } } }
Macro ProcMacro(CodeString MLine) { var MacroName = MLine.Word(); if (!MacroName.IsValidIdentifierName) { State.Messages.Add(MessageId.NotValidName, MacroName); return(null); } var Params = new CodeString(); var Handlers = State.Language.GlobalHandlers; if (MLine.Length > 0 && MLine[0] == '(') { var zp = MLine.GetBracketPos(false, Handlers); if (zp > 0) { Params = MLine.Substring(1, zp - 1).Trim(); MLine = MLine.Substring(zp + 1).Trim(); } } List <string> ParamList = null; if (Params.IsValid) { var PStrList = RecognizerHelper.SplitToParameters(State, Params, ','); if (PStrList == null) { return(null); } ParamList = new List <string>(); for (var i = 0; i < PStrList.Length; i++) { var String = PStrList[i].ToString(); if (!PStrList[i].IsValidIdentifierName) { State.Messages.Add(MessageId.WrongParamList, PStrList[i]); return(null); } if (ParamList.Contains(String)) { State.Messages.Add(MessageId.IdAlreadyDefined, PStrList[i]); return(null); } ParamList.Add(String); } } MLine = MLine.Trim(); if (MLine.Length > 0) { var Plugin = new PluginForDefine(Container, ParamList); var Node = Expressions.CreateExpression(MLine, Plugin); if (Node != null) { return(new Macro(MacroName, Node, ParamList)); } else { return(null); } } return(new Macro(MacroName, null, ParamList)); }
public CodeString[] SplitToParameters(CompilerState State, CodeString Self, bool EnableMessages = true) { return(RecognizerHelper.SplitToParameters(State, Self, ',', EnableMessages)); }
public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret) { var Position = Code.Length - 1; if (Position >= 0 && Code[Position] == ']') { var State = Container.State; var ZPos = Code.GetBracketPos(State, true, Options.EnableMessages); if (ZPos == -1) { return(SimpleRecResult.Failed); } var Left = Code.TrimmedSubstring(State, 0, ZPos, Options.EnableMessages); if (!Left.IsValid) { return(SimpleRecResult.Failed); } var TOptions = Options; TOptions.Func = x => x.RealId is Type; var TypeOfVals = Identifiers.Recognize(Container, Left, TOptions); if (TypeOfVals == null) { return(SimpleRecResult.Failed); } var RTypeOfVals = TypeOfVals.RealId as Type; if (RTypeOfVals == null || (RTypeOfVals.TypeFlags & TypeFlags.CanBeArrayType) == 0) { if (Options.EnableMessages) { State.Messages.Add(MessageId.UnknownId, Code); } return(SimpleRecResult.Failed); } var StrParams = Code.Substring(ZPos + 1, Position - ZPos - 1).Trim(); if (StrParams.IsEqual("?")) { Ret = new NonrefArrayType(Container, TypeOfVals, null); if (Options.Func == null || Options.Func(Ret)) { return(SimpleRecResult.Succeeded); } } else if (StrParams.IsEqual("*")) { if ((RTypeOfVals.TypeFlags & TypeFlags.CanBePointer) == 0) { if (Options.EnableMessages) { State.Messages.Add(MessageId.UnknownId, Code); } return(SimpleRecResult.Failed); } Ret = new PointerAndLength(Container, TypeOfVals); if (Options.Func == null || Options.Func(Ret)) { return(SimpleRecResult.Succeeded); } } var SplParams = RecognizerHelper.SplitToParameters(State, StrParams, ',', Options.EnableMessages, true); if (SplParams == null) { return(SimpleRecResult.Failed); } if (SplParams.Length == 0 || SplParams[0].Length == 0) { for (var i = 0; i < SplParams.Length; i++) { if (SplParams[i].Length > 0) { State.Messages.Add(MessageId.NotExpected, SplParams[i]); return(SimpleRecResult.Failed); } } var IndexCount = SplParams.Length == 0 ? 1 : SplParams.Length; Ret = new RefArrayType(Container, TypeOfVals, IndexCount); if (Options.Func == null || Options.Func(Ret)) { return(SimpleRecResult.Succeeded); } } else { var Plugin = Container.GetPlugin(); Plugin.GetPlugin <EvaluatorPlugin>().MustBeConst = true; var Lengths = new int[SplParams.Length]; for (var i = 0; i < SplParams.Length; i++) { var Node = Expressions.CreateExpression(SplParams[i], Plugin); var ConstCh = Node as ConstExpressionNode; if (ConstCh == null) { return(SimpleRecResult.Failed); } if (!(ConstCh.Type is NonFloatType)) { if (Options.EnableMessages) { State.Messages.Add(MessageId.MustBeInteger, StrParams); } return(SimpleRecResult.Failed); } if (!VerifyArrayLength(State, ConstCh, StrParams, Options.EnableMessages)) { return(SimpleRecResult.Failed); } Lengths[i] = (int)ConstCh.Integer; } Ret = new NonrefArrayType(Container, TypeOfVals, Lengths); if (Options.Func == null || Options.Func(Ret)) { return(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); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { if (Code.Length == 0) { return(ExprRecResult.Unknown); } var OldCode = Code; var State = Plugin.State; var Container = Plugin.Container; var Global = Container.GlobalContainer; var RadixSpecified = false; var Radix = 10; var Sign = RecognizerHelper.GetSign(ref Code); if (Code.Length == 0) { return(ExprRecResult.Unknown); } if (AtStartStrings != null) { var Result = Code.StartsWith(AtStartStrings, Skip); if (Result.Index != -1) { Code = Code.TrimmedSubstring(State, Result.String.Length); if (!Code.IsValid) { return(ExprRecResult.Failed); } RadixSpecified = true; Radix = AtStart[Result.Index].Radix; } } if (AtEndStrings != null) { var Result = Code.EndsWith(AtEndStrings, Skip); if (Result.Index != -1) { if (Radix != -1) { State.Messages.Add(MessageId.MultipleRadix, Code); return(ExprRecResult.Failed); } Code = Code.TrimmedSubstring(State, Result.String.Length); if (!Code.IsValid) { return(ExprRecResult.Failed); } RadixSpecified = true; Radix = AtStart[Result.Index].Radix; } } if (RecognizerHelper.GetSign(ref Code)) { Sign = !Sign; } if (Code.Length == 0 || (!char.IsDigit(Code[0]) && !RadixSpecified)) { return(ExprRecResult.Unknown); } var Options = new ConvStrToNumberOptions(); var Type = TypeExtractor(Container, ref Code); if (Type == null) { Options.Type = ConstValueType.Unknown; } else { var RType = Type.RealId as Type; Options.Type = RType.ConstValueType; } Code = Code.Trim(); if (Code.Length == 0) { return(ExprRecResult.Unknown); } Options.Radix = Radix; Options.Number = Code.String; Options.LetterCase = LetterCase.OnlyUpper; Options.EnableENotation = true; Options.Sign = Sign; ConstValue Value; var Res = RecognizerHelper.ConvStrToNumber(State, Code, Options, out Value); if (Res == SimpleRecResult.Unknown) { return(ExprRecResult.Unknown); } else if (Res == SimpleRecResult.Failed) { return(ExprRecResult.Failed); } if (Type == null) { Type = Constants.GetDefaultType(Container, Value.Type); if (Type.RealId is NumberType && !Value.CheckBounds(Type)) { var SystemType = Type.GetType(); do { var RType = Type.RealId as Type; Type = Global.CommonIds.GetIdentifier(SystemType, RType.Size * 2); if (Type == null) { if (typeof(SignedType).IsEquivalentTo(SystemType)) { Type = Global.CommonIds.GetLargestType(typeof(UnsignedType)); } else { Type = Global.CommonIds.GetLargestType(typeof(SignedType)); } break; } } while (!Value.CheckBounds(Type)); } } if (!Value.CheckBounds(State, Type, OldCode)) { return(ExprRecResult.Failed); } var Flags = Options.Type == ConstValueType.Unknown ? ExpressionFlags.AutoConvert : ExpressionFlags.None; Ret = new ConstExpressionNode(Type, Value, OldCode, Flags); return(ExprRecResult.Succeeded); }