/// <summary> /// Performs a syntax transform of the source code which is passed in as a string. The transform to be performed is also passed as an argument /// </summary> /// <param name="sourceText">Text of the source code which is to be transformed</param> /// <param name="transformKind">The kind of Syntax Transform that needs to be performed on the source</param> /// <returns>Transformed source code as a string</returns> public static string Transform(string sourceText, TransformKind transformKind) { SyntaxTree sourceTree = SyntaxFactory.ParseSyntaxTree(sourceText); TransformVisitor visitor = new TransformVisitor(sourceTree, transformKind); return(visitor.Visit(sourceTree.GetRoot()).ToFullString()); }
/// <summary> /// Performs a syntax transform of the source code which is passed in as a string. The transform to be performed is also passed as an argument /// </summary> /// <param name="sourceText">Text of the source code which is to be transformed</param> /// <param name="transformKind">The kind of Syntax Transform that needs to be performed on the source</param> /// <returns>Transformed source code as a string</returns> public static string Transform(string sourceText, TransformKind transformKind) { var sourceTree = SyntaxFactory.ParseSyntaxTree(sourceText); TransformVisitor visitor = new TransformVisitor(sourceTree, transformKind); return visitor.Visit(sourceTree.GetRoot()).ToFullString(); }
protected string TransformToHtml(XPathDocument doc, TransformKind kind) { string sOutput = null; XslCompiledTransform transformer = new XslCompiledTransform(); XsltArgumentList args = new XsltArgumentList(); switch (kind) { case TransformKind.kcptParse: sOutput = CreateTempFile(m_sParse, "htm"); transformer.Load(Path.Combine(TransformPath, m_sFormatParse)); break; case TransformKind.kcptTrace: sOutput = CreateTempFile(m_sTrace, "htm"); transformer.Load(Path.Combine(TransformPath, m_sFormatTrace)); string sIconPath = CreateIconPath(); args.AddParam("prmIconPath", "", sIconPath); break; case TransformKind.kcptWordGrammarDebugger: string sDepthLevel = m_XmlHtmlStack.Count.ToString(); sOutput = CreateTempFile(CreateWordGrammarDebuggerFileName(), "htm"); transformer.Load(Path.Combine(TransformPath, "FormatXAmpleWordGrammarDebuggerResult.xsl")); break; } TextWriter writer = File.CreateText(sOutput); ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; Font myFont = FontHeightAdjuster.GetFontForNormalStyle(m_cache.LangProject.DefaultAnalysisWritingSystem, m_mediator, wsf); args.AddParam("prmAnalysisFont", "", myFont.FontFamily.Name); args.AddParam("prmAnalysisFontSize", "", myFont.Size.ToString() + "pt"); int vernWs = m_cache.LangProject.DefaultVernacularWritingSystem; myFont = FontHeightAdjuster.GetFontForNormalStyle(vernWs, m_mediator, wsf); args.AddParam("prmVernacularFont", "", myFont.FontFamily.Name); args.AddParam("prmVernacularFontSize", "", myFont.Size.ToString() + "pt"); string sRTL = "N"; IWritingSystem wsObj = wsf.get_EngineOrNull(vernWs); if (wsObj != null && wsObj.RightToLeft) { sRTL = "Y"; } args.AddParam("prmVernacularRTL", "", sRTL); transformer.Transform(doc, args, writer); writer.Close(); return(sOutput); }
public override string CreateResultPage(string result) { bool fIsTrace = result.Contains("<Trace>"); m_parseResult = new XmlDocument(); m_parseResult.LoadXml(ConvertHvosToStrings(result, fIsTrace)); AddMsaNodes(false); string sInput = CreateTempFile(m_sTrace, "xml"); m_parseResult.Save(sInput); TransformKind kind = (fIsTrace ? TransformKind.kcptTrace : TransformKind.kcptParse); string sOutput = TransformToHtml(sInput, kind); return(sOutput); }
protected string TransformToHtml(string sInputFile, TransformKind kind) { string sOutput = null; var args = new List <XmlUtils.XSLParameter>(); switch (kind) { case TransformKind.kcptParse: sOutput = TransformToHtml(sInputFile, m_sParse, m_sFormatParse, args); break; case TransformKind.kcptTrace: string sIconPath = CreateIconPath(); args.Add(new XmlUtils.XSLParameter("prmIconPath", sIconPath)); sOutput = TransformToHtml(sInputFile, m_sTrace, m_sFormatTrace, args); break; } return(sOutput); }
/// <summary> /// Create an HTML page of the results /// </summary> /// <param name="result">XML string of the XAmple trace output</param> /// <returns>URL of the resulting HTML page</returns> public override string CreateResultPage(string result) { string sAdjusted; bool fIsTrace; AdjustResultContent(result, out sAdjusted, out fIsTrace); m_parseResult = new XmlDocument(); m_parseResult.LoadXml(ConvertHvosToStrings(sAdjusted, fIsTrace)); AddMsaNodes(fIsTrace); string sInput = CreateTempFile(m_ksXAmpleTrace, "xml"); m_parseResult.Save(sInput); TransformKind kind = (fIsTrace ? TransformKind.kcptTrace : TransformKind.kcptParse); string sOutput = TransformToHtml(sInput, kind); return(sOutput); }
private static HandleIcon GetHandleIcon(BondType bt, TransformKind tk) { HandleIcon result; switch (bt) { case BondType.Handle: result = (tk == Enums.TransformKind.Scale) ? HandleIcon.Handle : HandleIcon.Rotate; break; case BondType.Join: result = HandleIcon.Join; break; case BondType.Anchor: result = HandleIcon.Anchor; break; case BondType.Lock: result = HandleIcon.Lock; break; case BondType.Pin: result = HandleIcon.Pin; break; case BondType.Spring: result = HandleIcon.Spring; break; default: result = HandleIcon.Handle; break; } return(result); }
public TransformVisitor(SyntaxTree tree, TransformKind transKind) { this.tree = tree; this.transformKind = transKind; }
protected string TransformToHtml(XPathDocument doc, TransformKind kind) { string sOutput = null; XslCompiledTransform transformer = new XslCompiledTransform(); XsltArgumentList args = new XsltArgumentList(); switch (kind) { case TransformKind.kcptParse: sOutput = CreateTempFile(m_sParse, "htm"); transformer.Load(Path.Combine(TransformPath, m_sFormatParse)); break; case TransformKind.kcptTrace: sOutput = CreateTempFile(m_sTrace, "htm"); transformer.Load(Path.Combine(TransformPath, m_sFormatTrace)); string sIconPath = CreateIconPath(); args.AddParam("prmIconPath", "", sIconPath); break; case TransformKind.kcptWordGrammarDebugger: string sDepthLevel = m_XmlHtmlStack.Count.ToString(); sOutput = CreateTempFile(CreateWordGrammarDebuggerFileName(), "htm"); transformer.Load(Path.Combine(TransformPath, "FormatXAmpleWordGrammarDebuggerResult.xsl")); break; } TextWriter writer = File.CreateText(sOutput); ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; Font myFont = FontHeightAdjuster.GetFontForNormalStyle(m_cache.LangProject.DefaultAnalysisWritingSystem, m_mediator, wsf); args.AddParam("prmAnalysisFont", "", myFont.FontFamily.Name); args.AddParam("prmAnalysisFontSize", "", myFont.Size.ToString() + "pt"); int vernWs = m_cache.LangProject.DefaultVernacularWritingSystem; myFont = FontHeightAdjuster.GetFontForNormalStyle(vernWs, m_mediator, wsf); args.AddParam("prmVernacularFont", "", myFont.FontFamily.Name); args.AddParam("prmVernacularFontSize", "", myFont.Size.ToString() + "pt"); string sRTL = "N"; IWritingSystem wsObj = wsf.get_EngineOrNull(vernWs); if (wsObj != null && wsObj.RightToLeft) sRTL = "Y"; args.AddParam("prmVernacularRTL", "", sRTL); transformer.Transform(doc, args, writer); writer.Close(); return sOutput; }
public TransformKind ToggleKind() { transformKind = (transformKind == TransformKind.Scale) ? TransformKind.Rotate : TransformKind.Scale; //transformKind = ((int)transformKind + 0x10 > 0x60) ? TransformKind.Scale : (TransformKind)((int)(transformKind + 0x10)); return(transformKind); }
public void SetAsRotate() { transformKind = TransformKind.Rotate; }
public void Reset() { transformKind = TransformKind.Scale; }