public override object VisitAccess_text([NotNull] xmllangParser.Access_textContext context) { var varName = context.ID().ToString(); var prop = context.TEXT().ToString(); if (CurrentVarScope.GetVarValue(varName) == null) { throw new Exception(VisitorExceptionMessages.VarNotDefined); } CurrentFunction.Content.Append($"{varName}.{prop}"); return(VisitChildren(context)); }
public override object VisitTag_assignment([NotNull] xmllangParser.Tag_assignmentContext context) { TypeMap.TryGetValue(context.TAG().ToString(), out var type); var varName = context.ID().ToString(); if (CurrentVarScope.GetVarValue(varName) != null) { throw new Exception(VisitorExceptionMessages.VarAlreadyExists); } var tagName = context.STRING().ToString(); CurrentVarScope.CreateVar(varName, type, new XMLNode(tagName)); CurrentFunction.Content.Append($"var {varName} = new {type}({tagName});\n"); return(VisitChildren(context)); }
public override object VisitAttr_assignment([NotNull] xmllangParser.Attr_assignmentContext context) { TypeMap.TryGetValue(context.ATTR().ToString(), out var type); var varName = context.ID().ToString(); if (CurrentVarScope.GetVarValue(varName) != null) { throw new Exception(VisitorExceptionMessages.VarAlreadyExists); } // TODO: split to args var var attrName = context.STRING(0).ToString(); var attrValue = context.STRING(1).ToString(); CurrentVarScope.CreateVar(varName, type, new XMLAttribute(attrName, attrValue)); CurrentFunction.Content.Append($"var {varName} = new {type}({attrName}, {attrValue});\n"); return(VisitChildren(context)); }