private void TranspileVarNamesPropertyList(sphereScript99Parser.PropertyListContext context) { if (context.NEWLINE() != null) { dataBuilder.Append(context.NEWLINE().GetText()); } if (context.propertyAssignment() == null) { return; } foreach (var assignment in context.propertyAssignment()) { var name = assignment.propertyName().GetText(); var value = assignment.propertyValue()?.GetText(); if (SharpStriper.TryStrip(value, out string strippedValue)) { dataVisitor.AppendPropertyAssignment(assignment, strippedValue); } else { dataVisitor.AppendPropertyAssignment(assignment); } } dataBuilder.EnsureNewline(); }
public override bool VisitQuotedLiteralArgument([NotNull] sphereScript99Parser.QuotedLiteralArgumentContext context) { if (!stripDoubleQuotes) { builder.Append('"'); } if (context.innerQuotedLiteralArgument() != null) { Visit(context.innerQuotedLiteralArgument()); } if (!stripDoubleQuotes) { builder.Append('"'); } return(true); }
public override bool VisitMemberName([NotNull] sphereScript99Parser.MemberNameContext context) { var lastSegmentText = context.children.Last().GetText(); var lastUnderscoreIndex = lastSegmentText.LastIndexOf('_'); if (lastUnderscoreIndex >= 0 && lastUnderscoreIndex + 1 < lastSegmentText.Length) { var textAfterUnderscore = lastSegmentText.Substring(lastUnderscoreIndex + 1); if (int.TryParse(textAfterUnderscore, out int numberAfterUnderscore)) { parentTranspiler.AppendTerminalsVisitNodes(context.children.Take(context.children.Count - 1).ToArray()); builder.Append(lastSegmentText.Substring(0, lastUnderscoreIndex)); builder.Append('['); builder.Append(textAfterUnderscore); builder.Append(']'); return(true); } } parentTranspiler.Visit(context); return(true); }
public override bool VisitStrictNativeArgumentList([NotNull] sphereScript99Parser.StrictNativeArgumentListContext context) { var arguments = context.strictNativeArgument(); if (arguments != null && arguments.Length > 0) { transpiler.Visit(arguments[0]); foreach (var argument in arguments.Skip(1)) { builder.Append(argument.WS()); transpiler.Visit(argument.evalExpression()); } } return(true); }
public override bool VisitFirstMemberAccess([NotNull] sphereScript99Parser.FirstMemberAccessContext context) { var name = firstMemberAccessNameVisitor.Visit(context); IParseTree[] arguments = firstMemberAccessArgumentsVisitor.Visit(context); if (IsSpecialFunction(name)) { builder.EnsureEvalCall("eval", () => { builder.Append(name); builder.Append('('); if (name.Equals("strmatch", StringComparison.OrdinalIgnoreCase)) { builder.StartSpecialFunctionArguments(); transpiler.Visit(arguments[1]); builder.Append(','); transpiler.Visit(arguments[0]); builder.EndSpecialFunctionArguments(); } else { if (name.Equals("strcmpi", StringComparison.OrdinalIgnoreCase) || name.Equals("strcmp", StringComparison.OrdinalIgnoreCase)) { builder.StartSpecialFunctionArguments(); QuoteIntrinsicArgument(arguments[0]); builder.Append(','); QuoteIntrinsicArgument(arguments[1]); builder.EndSpecialFunctionArguments(); } else { UnquoteIntrinsicArgument(arguments[0]); } } builder.Append(')'); }); return(true); } return(false); }
public void AppendArguments(IEnumerable <IParseTree> arguments) { if (arguments == null) { return; } var argumentCount = arguments.Count(); if (argumentCount == 0) { return; } var firstArgument = arguments.First(); Visit(firstArgument); foreach (var argument in arguments.Skip(1)) { builder.Append(' '); Visit(argument); } }
public override bool VisitPropertyList([NotNull] sphereScript99Parser.PropertyListContext context) { if (context.NEWLINE() != null) { builder.Append(context.NEWLINE().GetText()); } if (context.propertyAssignment() == null) { return(true); } uint?flagValue = null; uint?attrValue = null; foreach (var assignment in context.propertyAssignment()) { var name = assignment.propertyName().GetText(); var value = assignment.propertyValue()?.GetText(); if (invalidPropertyValues.TryGetValue(name, out IReadOnlyCollection <string> invalidValues) && invalidValues.Contains(value)) { continue; } if (specificFlagValues.TryGetValue(name, out uint specificFlagValue)) { if (!value.Equals("0", StringComparison.OrdinalIgnoreCase)) { flagValue = flagValue.HasValue ? flagValue.Value | specificFlagValue : specificFlagValue; } } else if (specificAttrValues.TryGetValue(name, out uint specificAttrValue)) { if (!value.Equals("0", StringComparison.OrdinalIgnoreCase)) { attrValue = attrValue.HasValue ? attrValue.Value | specificAttrValue : specificAttrValue; } } else if (name.Equals("MORE1", StringComparison.OrdinalIgnoreCase) || name.Equals("MORE2", StringComparison.OrdinalIgnoreCase)) { parentVisitor.AppendPropertyAssignment(assignment, value.Trim('"')); } else if (SharpStriper.TryStrip(value, out string strippedValue)) { parentVisitor.AppendPropertyAssignment(assignment, strippedValue); } else if (!forbiddenProperties.Contains(name)) { parentVisitor.AppendPropertyAssignment(assignment); } } builder.EnsureNewline(); if (flagValue.HasValue) { builder.AppendLine($"FLAGS=0{flagValue.Value:X8}"); } if (attrValue.HasValue) { builder.AppendLine($"ATTR=0{attrValue.Value:X8}"); } return(true); }