public bool TryParse(string location, IXmlLineInfo line, out ComponentPointTemplate componentPointTemplate) { if (!baseParser.TryParse(location, line, out var componentPoint)) { componentPointTemplate = null; return(false); } componentPointTemplate = new ComponentPointTemplate(componentPoint.RelativeToX, componentPoint.RelativeToY, new IModifierToken[] { new ConstantModifierToken { Offset = componentPoint.Offset.X }, }, new IModifierToken[] { new ConstantModifierToken { Offset = componentPoint.Offset.Y } }); return(true); }
public static bool TryParse(this IComponentPointTemplateParser parser, XAttribute location, out ComponentPointTemplate componentPointTemplate) { return(parser.TryParse(location.Value, location, out componentPointTemplate)); }
public static bool TryParse(this IComponentPointTemplateParser parser, XAttribute x, XAttribute y, out ComponentPointTemplate componentPointTemplate) { return(parser.TryParse(x.Value, y.Value, x, y, out componentPointTemplate)); }
public bool TryParse(string x, string y, IXmlLineInfo xLine, IXmlLineInfo yLine, out ComponentPointTemplate componentPointTemplate) { var errors = new StringWriter(); try { var lexer = new ComponentPointLexer(new AntlrInputStream(new StringReader(x)), errors, errors); var parser = new ComponentPointParser(new CommonTokenStream(lexer), errors, errors); var ctx = parser.r(); var xPosition = (ComponentPosition)Enum.Parse(typeof(ComponentPosition), ctx.position().GetText(), true); var xModifiers = new List <IModifierToken>(); var currentModifier = ctx.modifiers(); while (currentModifier.modifier() != null) { var modifier = currentModifier.modifier(); bool positive = modifier.plusminus().GetText() == "+"; if (modifier.CONSTANT() != null) { xModifiers.Add(new ConstantModifierToken { Offset = (positive ? 1 : -1) * double.Parse(modifier.CONSTANT().GetText()) }); } else { xModifiers.Add(new DefinitionModifierToken { Negated = !positive, Name = modifier.variable().VARIABLENAME().GetText() }); } currentModifier = currentModifier.modifiers(); } lexer = new ComponentPointLexer(new AntlrInputStream(new StringReader(y)), errors, errors); parser = new ComponentPointParser(new CommonTokenStream(lexer), errors, errors); ctx = parser.r(); var yPosition = (ComponentPosition)Enum.Parse(typeof(ComponentPosition), ctx.position().GetText(), true); var yModifiers = new List <IModifierToken>(); currentModifier = ctx.modifiers(); while (currentModifier.modifier() != null) { var modifier = currentModifier.modifier(); bool positive = modifier.plusminus().GetText() == "+"; if (modifier.CONSTANT() != null) { yModifiers.Add(new ConstantModifierToken { Offset = (positive ? 1 : -1) * double.Parse(modifier.CONSTANT().GetText()) }); } else { yModifiers.Add(new DefinitionModifierToken { Negated = !positive, Name = modifier.variable().VARIABLENAME().GetText() }); } currentModifier = currentModifier.modifiers(); } componentPointTemplate = new ComponentPointTemplate(xPosition, yPosition, xModifiers, yModifiers); return(true); } catch { componentPointTemplate = null; return(false); } finally { foreach (var message in errors.ToString().Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)) { var position = new FileRange(xLine.LineNumber, xLine.LinePosition, xLine.LineNumber, xLine.LinePosition + x.Length); logger.Log(LogLevel.Error, position, message, null); } } }