Exemple #1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var node = lbNodes.SelectedItem as Node;

            if (node != null)
            {
                try
                {
                    if (_currentChangeAst == null)
                    {
                        _currentChangeAst = new ChangeAST(_nodeChangeItems);
                    }
                    _currentChangeAst.InsertBefore(node, tbNodeText.Text);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }
            }
        }
Exemple #2
0
        private void Button_Click_8(object sender, RoutedEventArgs e)
        {
            var fileName = "parser.ts";

            if (!File.Exists(fileName))
            {
                var openFileDialog = new OpenFileDialog();
                if (openFileDialog.ShowDialog() == true)
                {
                    fileName = openFileDialog.FileName;
                }
                else
                {
                    return;
                }
            }

            var source = File.ReadAllText(fileName);

            var ast = new TypeScriptAST(source, fileName);

            var change = new ChangeAST();

            foreach (var module in ast.GetDescendants().OfType <ModuleDeclaration>())
            {
                var funcs          = module.Body.Children.OfType <FunctionDeclaration>().ToList();
                var enums          = module.Body.Children.OfType <EnumDeclaration>();
                var moduleInfoFunc = $@"
    export function getModuleInfo() {{
        return ""Module {module.IdentifierStr} contains {funcs.Count()} functions ({
                        funcs.Count(v => v.IdentifierStr.StartsWith("parse"))
                    } starts with parse), {enums.Count()} enums ..."";
    }}
";
                change.InsertBefore(module.Body.Children.First(), moduleInfoFunc);
            }
            var newSource = change.GetChangedSource(ast.SourceStr);

            tbExample2Res.Text = newSource;
            File.WriteAllText("parser2.ts", newSource);
        }