internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error) { if (enableStack.Contains(false)) { error = null; return; } string strInput = input.AsSingleLine(); strInput = ClearInput(strInput); if (!PreprocessorIfdef.ArgumentRegex.IsMatch(strInput)) { error = new ParseError(ParseErrorType.Preprocessor_NameExpected); return; } if (!defines.Exists(p => p.Name == strInput)) { error = new ParseError(ParseErrorType.Preprocessor_UnknownDefineName); return; } defines.RemoveAll(p => p.Name == strInput); error = null; }
//Для include internal override List <SourceLine> Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error, Func <string, PreprocessorParseResult> recursiveFunc) { if (enableStack.Contains(false)) { error = null; return(null); } string strInput = input.AsSingleLine(); strInput = ClearInput(strInput); if (!Name1Regex.IsMatch(strInput) && !Name2Regex.IsMatch(strInput)) { error = new ParseError(ParseErrorType.Preprocessor_WrongNameFormat); return(null); } strInput = strInput.Trim('\"', '<', '>'); var result = recursiveFunc(strInput); if (result.error != null) { error = result.error; return(null); } else { error = null; return(result.sourceLines); } }
internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error) { if (enableStack.Contains(false)) { error = null; return; } AllowDefinedFunction = true; string strInput = input.AsSingleLine(); strInput = ClearInput(strInput); Expression exp; var expError = Expression.Parse(strInput, out exp, (token) => { if (token.UnaryFunction == null || token.UnaryFunction.FunctionString != "defined") { var def = defines.Find(p => p.Name == token.RawValue); if (def == null) { throw new WrongTokenException(); } token.RawValue = def.Value.AsSingleLine(); if (!token.IsSimple) { Expression expression; Expression.Parse(token.RawValue, out expression); token.Subtokens = expression.TokenTree.Subtokens; } return(null); } return(new ObjectReference((Integer)0, ReferenceType.Define)); }); if (expError != null) { error = expError; return; } bool result = exp.Calculate(null).AsBool(); enableStack.Push(result); error = null; AllowDefinedFunction = false; }
internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error) { if (enableStack.Contains(false)) { error = null; return; } string firstLine = ClearInput(input.AsSingleLine()); if (string.IsNullOrEmpty(firstLine)) { error = new ParseError(ParseErrorType.Preprocessor_NameExpected); return; } string[] parts = firstLine.Split(' '); string name = parts[0]; if (name.Contains('(') || name.Contains(')') || name.Contains(',')) { try { if (!ParametricDefine.ParametricDefineRegex.IsMatch(name)) { error = new ParseError(ParseErrorType.Preprocessor_WrongParametricDefineFormat); return; } } catch { error = new ParseError(ParseErrorType.Preprocessor_WrongParametricDefineFormat); return; } if (parts.Length == 1 && input.IsSingleLine) { error = new ParseError(ParseErrorType.Preprocessor_ParametricDefineWithoutExpression); return; } var firstValueLine = string.Join(")", firstLine.Split(')').Skip(1).ToArray()); var group = new StringGroup(firstValueLine); group.Strings.AddRange(input.Strings.Skip(1)); var newDef = new ParametricDefine(name, group); if (defines.Exists(p => p.Name == newDef.Name)) { error = new ParseError(ParseErrorType.Preprocessor_DefineNameAlreadyExists); return; } var value = newDef.Value; Define.ResolveDefines(defines, ref value, -1, null); newDef.Value = value; defines.Add(newDef); } else { if (!Define.GeneralDefineNameRegex.IsMatch(name)) { error = new ParseError(ParseErrorType.Preprocessor_WrongDefineName); return; } if (defines.Exists(p => p.Name == Name)) { error = new ParseError(ParseErrorType.Preprocessor_DefineNameAlreadyExists); return; } if (parts.Length == 1) { defines.Add(new Define(name)); } else { var firstValueLine = string.Join(" ", parts.Skip(1).ToArray()); var group = new StringGroup(firstValueLine); group.Strings.AddRange(input.Strings.Skip(1)); var newDef = new Define(name, group); var value = newDef.Value; Define.ResolveDefines(defines, ref value, -1, null); newDef.Value = value; defines.Add(newDef); } } error = null; }