private SelectStatement ResolveStatement(ReadOnlySpan <TSQLToken> tokens, ref int fileIndex, CompilerContext context) { statement = new SelectStatement(); SkipSelectPrequelStatements(tokens, ref fileIndex, context); statement.Expression = DetermineSourceColumns(tokens, ref fileIndex, context); ResolveIntoClause(tokens, ref fileIndex, context); var objects = StatementResolveHelper.ResolveFromStatement(tokens, ref fileIndex, context); AddObjectsToContext(objects, context); Beautifier.BeautifyColumns(statement.Expression, context); AddSynonymousObjects(objects); StatementResolveHelper.ResolveWhereStatement(tokens, ref fileIndex, context); ResolveGroupByClause(tokens, ref fileIndex, context); ResolveOrderByClause(tokens, ref fileIndex, context); //Resolve FOR-CLAUSE ResolveUnionclause(tokens, ref fileIndex, context); PopObjectsFromContextStack(context); statement.Expression.Name = "SELECT"; return(statement); }
public TestJSBeautifierIndentation() { this.beautifier = new Beautifier(); BeautifierOptions bo = this.beautifier.Opts; bo.IndentWithTabs = true; }
private void Button1_Click(object sender, RoutedEventArgs e) { var input = textBox; var output = richTextBox; Beautifier beautifier = new Beautifier(); beautifier.BeatyFromTo(input.Text, output); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("fukc: giev fiel"); return; } var fileName = args[0]; if (args[0].StartsWith("http://") || args[0].StartsWith("https://")) { Console.WriteLine("htpp? ok. gon dolwnod fiel."); try { fileName = "./6obcy.js"; using (var wc = new WebClient()) wc.DownloadFile(args[0], "./6obcy.js"); } catch { Console.WriteLine("fukc: fiel dlownad falied"); return; } } if (!File.Exists(fileName)) { Console.WriteLine("fukc: giev crorcet fiel ok?"); return; } Console.WriteLine("gon ask bro for hepl ok?"); Console.WriteLine("---"); var src = new ObcySourceFile(fileName); var deobf = src.Deobfuscate(); Console.WriteLine("---"); Console.WriteLine("thank bro! will prietifey."); var beautifier = new Beautifier(); var actuallyReadableCode = beautifier.Beautify(deobf); File.WriteAllText( Path.GetFileNameWithoutExtension(src.FileName) + ".deobf.js", actuallyReadableCode ); Console.WriteLine("im outta here."); }
public TestJSBeautifier() { this.beautifier = new Beautifier(); this.beautifier.Opts.IndentSize = 4; this.beautifier.Opts.IndentChar = ' '; this.beautifier.Opts.PreserveNewlines = true; this.beautifier.Opts.JslintHappy = false; this.beautifier.Opts.KeepArrayIndentation = false; this.beautifier.Opts.BraceStyle = BraceStyle.Collapse; this.beautifier.Flags.IndentationLevel = 0; this.beautifier.Opts.BreakChainedMethods = false; }
static void Decode(DecodeArgs decoderArgs) { try { Console.WriteLine("Decoding {0}", decoderArgs.JsxbinFilepath); string jsxbin = File.ReadAllText(decoderArgs.JsxbinFilepath, Encoding.ASCII); string jsx = AbstractNode.Decode(jsxbin, decoderArgs.PrintStructure); jsx = new Beautifier().Beautify(jsx); File.WriteAllText(decoderArgs.JsxFilepath, jsx, Encoding.UTF8); Console.WriteLine("Jsxbin successfully decoded to {0}", decoderArgs.JsxFilepath); } catch (Exception ex) { Console.WriteLine("Decoding failed. If this problem persists, please raise an issue on github. Error message: {0}. Stacktrace: {1}.", ex.Message, ex.StackTrace); } }
private async void SendButton_Click(object sender, RoutedEventArgs e) { string url = urlTextBox.Text; string type = typeComboBox.Text; string header = "";// headerTextBlock.Text; //TODO Comunicator cm = new Requester.Comunicator(); string response = await cm.Send(url, type, header); previewHTML.NavigateToString(response); var output = formatedRichTextBox; Beautifier beautifier = new Beautifier(); beautifier.BeatyRichTextBox(response, output); rawTextBlock.Text = response; }
void init_with_code(string js_code, int line, int column, bool no_pretty) { inits(); InitializeComponent(); textEditor.Options.EnableHyperlinks = false; textEditor.Options.HighlightCurrentLine = true; textEditor.Options.ConvertTabsToSpaces = true; textEditor.PreviewMouseLeftButtonDown += TextEditor_PreviewMouseLeftButtonDown; var bb = new Beautifier(new BeautifierOptions { IndentWithTabs = false, IndentSize = 4 }); raw = js_code; pretty = bb.Beautify(raw); try { var p1 = new JavaScriptParser(raw, new ParserOptions { Loc = true }); var p2 = new JavaScriptParser(pretty, new ParserOptions { Loc = true }); s1 = p1.ParseScript(true); s2 = p2.ParseScript(true); if (line == -1 || column == -1) { (l, c) = (1, 1); } else { (l, c) = (line, column); } this.no_pretty = no_pretty; Loaded += ScriptViewer_Loaded; } catch { Beautify.IsEnabled = false; textEditor.Text = raw; } }
/// <summary> /// Outputs the script converted into a beautiful form. /// </summary> /// <returns></returns> public JsScript GetFormattedScript() { if (IsFormatted) { return(this); } var tool = new Beautifier(new BeautifierOptions { IndentWithTabs = false, IndentSize = 4 }); var pretty = tool.Beautify(RawCode); return(new JsScript(pretty, Url, IsEmbeddedInHtml, EmbeddedLine, EmbeddedColumn) { IsFormatted = true }); }
public void Beautify() { Beautifier b = new Beautifier(new BeautifierOptions { BraceStyle = BraceStyle.Expand, BreakChainedMethods = false, EvalCode = true, IndentChar = '\t', IndentSize = 1, IndentWithTabs = true, JslintHappy = true, KeepArrayIndentation = true, KeepFunctionIndentation = true, MaxPreserveNewlines = 1, PreserveNewlines = true }); scintilla.Text = b.Beautify(scintilla.Text); }
/// <summary> /// A SELECT statement containing an INTO clause is not a data query but a data manipulation /// This method pushes such a SELECT statement to the related list /// </summary> internal void AddSelectWithIntoClause(SelectStatement statement) { var manipulation = new DataManipulation(); foreach (var expr in statement.Expression.ChildExpressions) { if (expr.Type.Equals(ExpressionType.COLUMN)) { var singleManipulation = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(statement.TargetObject, InternalConstants.UNRELATED_COLUMN_NAME) }; singleManipulation.ChildExpressions.Add(expr); manipulation.Expressions.Add(singleManipulation); } } DataManipulations.Add(manipulation); }
private void GenerateQuery(RequiredDataContainer Container, string Database) { QueryableEntity Aluno = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Aluno")); QueryableEntity Endereco = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Endereco")); RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator( Aluno, (Relationship)Container.EntityRelationshipModel.FindByName("AlunoMora"), new List <QueryableEntity>() { Endereco }, Container.ERMongoMapping); SortArgument SortArg = new SortArgument(Aluno, Aluno.Element.GetIdentifierAttribute(), MongoDBSort.Ascending); SortStage SortOp = new SortStage(new List <SortArgument>() { SortArg }, Container.ERMongoMapping); List <AlgebraOperator> OperatorList = new List <AlgebraOperator>() { RJoinOp, SortOp }; FromArgument FromArg = new FromArgument(Aluno, Container.ERMongoMapping); QueryGenerator QueryGen = new QueryGenerator(FromArg, OperatorList); string Query = QueryGen.Run(); Beautifier jsB = new Beautifier(); queryBox.Text = jsB.Beautify(Query); QueryRunner QueryRunner = new QueryRunner("mongodb://localhost:27017", Database); string Result = QueryRunner.GetJSON(Query); resultBox.Text = Result.PrettyPrintJson(); }
static void Main(string[] args) { Rectangle a = new Rectangle(3, 3, 4); foreach (var item in a.Array) { Console.WriteLine(item); } Console.ReadLine(); List <Rectangle> rectangles = new List <Rectangle> { new Rectangle(), new Rectangle(3, 5), //Rectangle.Factory(), }; var beautifier = new Beautifier(); foreach (var tégla in rectangles) { beautifier.Beautify += tégla.Color; beautifier.OnBeautify("ződ"); Console.WriteLine(tégla); } Console.ReadLine(); /* * Console.WriteLine("Eredeti: {0} ", rectangles[0]); * rectangles[0].ChangeLocation(1, 1).ChangeColor("Barna"); * Console.WriteLine("Megváltoztatva: {0} ", rectangles[0]); * foreach (var item in rectangles) * { * Console.WriteLine(item); * Console.ReadKey(); * * } */ }
public void Accept(ICodeFormatterVisitor visitor) { foreach (ICodeFormatterAcceptor acceptor in Model.VariableActionModel) { acceptor.Accept(visitor); } foreach (ICodeFormatterAcceptor acceptor in Model.MainActionModel) { acceptor.Accept(visitor); } Beautifier beautifier = new Beautifier(); beautifier.Opts.IndentSize = 4; beautifier.Opts.IndentChar = ' '; beautifier.Opts.PreserveNewlines = true; beautifier.Opts.JslintHappy = false; beautifier.Opts.KeepArrayIndentation = false; beautifier.Opts.BraceStyle = BraceStyle.Collapse; beautifier.Flags.IndentationLevel = 0; beautifier.Opts.BreakChainedMethods = false; CodeOutput = beautifier.Beautify(visitor.CodeOutput); }
/// <summary> /// Loops through all collected database objects and add a /// whole-object-synonymous for each object that is not referenced /// in a column /// </summary> private void AddSynonymousObjects(List <DatabaseObject> databaseObjects) { foreach (var dbo in databaseObjects) { if (!dbo.Type.Equals(DatabaseObjectType.REAL)) { continue; } bool isReferenced = false; foreach (var expr in statement.Expression.ChildExpressions) { if (!expr.Type.Equals(ExpressionType.COLUMN)) { continue; } Helper.SplitColumnNotationIntoSingleParts(expr.Name, out string databaseName, out string schemaName, out string dboName, out string columnName); if (dbo.Name.Equals(dboName)) { isReferenced = true; break; } } if (!isReferenced) { var sourceSynonymous = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(dbo, InternalConstants.WHOLE_OBJECT_SYNONYMOUS), WholeObjectSynonymous = true }; statement.Expression.ChildExpressions.Add(sourceSynonymous); } } }
public DataManipulation Resolve(ReadOnlySpan <TSQLToken> tokens, ref int fileIndex, CompilerContext context) { manipulation = new DataManipulation(); fileIndex++; //skip 'insert' //TODO Resolve TOP Expression if (tokens[fileIndex].Text.ToLower().Equals("into")) { fileIndex++; //skip 'into' } targetObject = StatementResolveHelper.ResolveDatabaseObject(tokens, ref fileIndex, context, true); DetermineTargetColumns(tokens, ref fileIndex, context); //TODO Resolve Table Hint if (tokens[fileIndex].Text.Equals("values", StringComparison.InvariantCultureIgnoreCase)) { fileIndex += 2; //skip 'values (' DetermineSourceObjects(tokens, ref fileIndex, context); } else if (tokens[fileIndex].Text.Equals("select", StringComparison.InvariantCultureIgnoreCase)) { var selectStatement = new SelectStatementResolver().Resolve(tokens, ref fileIndex, context); sources = selectStatement.ChildExpressions; } if (targets.Count == 0) { for (int index = 0; index < sources.Count; index++) { Expression resolvedSource; if (sources[index].Type.Equals(ExpressionType.COMPLEX) || sources[index].Type.Equals(ExpressionType.CONSTANT)) { continue; } else if (sources[index].Type.Equals(ExpressionType.ALIAS)) { resolvedSource = sources[index].ChildExpressions[0]; } else { resolvedSource = sources[index]; } var singleManipulation = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(targetObject, InternalConstants.UNRELATED_COLUMN_NAME) }; singleManipulation.ChildExpressions.Add(resolvedSource); manipulation.Expressions.Add(singleManipulation); } } else if (StatementResolveHelper.HaveEqualAmountOfRealExpression(sources, targets)) { for (int index = 0; index < targets.Count; index++) { if (!sources[index].Type.Equals(ExpressionType.COLUMN) && !sources[index].Type.Equals(ExpressionType.SCALAR_FUNCTION)) { continue; } var singleManipulation = new Expression(ExpressionType.COLUMN) { Name = targets[index].Name }; singleManipulation.ChildExpressions.Add(sources[index]); manipulation.Expressions.Add(singleManipulation); } } else { throw new InvalidSqlException("Amount of targets does not match the number of sources"); } if (fileIndex < tokens.Length && tokens[fileIndex].Text.Equals(";")) { fileIndex++; } var beautified = new List <Expression>(); foreach (var exp in manipulation.Expressions) { beautified.Add(Beautifier.BeautifyColumns(exp, context)); } manipulation.Expressions = beautified; return(manipulation); }
// methods private async Task SendRequestFromGUI() { infoTextBlock.Text = "Loading ..."; rawTextBlock.Document.Blocks.Clear(); FullTextBlock.Document.Blocks.Clear(); previewHTML.Navigate((Uri)null); try { Requester.Requester cm = new Requester.Requester(); string url = urlTextBox.Text; string method = methodComboBox.Text; Dictionary <string, string> header = new Dictionary <string, string>(); foreach (Requester.DataGridValue item in dataGridHeader.Items.SourceCollection) { if (item.active && item.key != null) { header.Add(item.key, item.value); } } string body = new TextRange( bodyTextBlock.Document.ContentStart, bodyTextBlock.Document.ContentEnd ).Text; Dictionary <string, string> dataGridParamsInDictionary = new Dictionary <string, string>(); foreach (Requester.DataGridValue item in dataGridParams.Items.SourceCollection) { if (item.active) { dataGridParamsInDictionary.Add(item.key, item.value); } } url = cm.ApplyParamsToUrl(url, dataGridParamsInDictionary); RequestResponse response = await cm.Send(method, url, body, header); if (response.content != null && response.content != "") { previewHTML.NavigateToString(response.content); } rawTextBlock.Document.Blocks.Add(new Paragraph(new Run(response.content))); // make slowest part in parallel formatedRichTextBox.Dispatcher.Invoke(new Action(() => { var output = formatedRichTextBox; output.Document.Blocks.Clear(); Beautifier beautifier = new Beautifier(); beautifier.BeautyRichTextBox(response.content, output); })); FullTextBlock.Document.Blocks.Add(new Paragraph(new Run(response.statusCode.Key + " (" + response.statusCode.Value + ")"))); FullTextBlock.Document.Blocks.Add(new Paragraph(new Run(response.header))); FullTextBlock.Document.Blocks.Add(new Paragraph(new Run(response.timing + "ms"))); FullTextBlock.Document.Blocks.Add(new Paragraph(new Run(response.content))); StatusCodeTextBox.Text = response.statusCode.Key + " (" + response.statusCode.Value + ")"; string[] statusCodeColors = new string[] { "#bdbdbd", // 1xx "#2e7d32", // 2xx "#1565c0", // 3xx "#c62828", // 4xx "#6a1b9a", // 5xx }; StatusCodeTextBox.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(statusCodeColors[(int)(response.statusCode.Key / 100 - 1)])); infoTextBlock.Text = "Loading complete"; } catch (Exception e) { if (e.InnerException != null) { StatusCodeTextBox.Text = "404 (Page Not Found)"; StatusCodeTextBox.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#c62828")); infoTextBlock.Text = e.InnerException.Message; } else { infoTextBlock.Text = e.Message; } } }
public DataManipulation Resolve(ReadOnlySpan <TSQLToken> tokens, ref int fileIndex, CompilerContext context) { manipulation = new DataManipulation(); fileIndex++; //skip 'update' var targetObject = StatementResolveHelper.ResolveDatabaseObject(tokens, ref fileIndex, context, true); fileIndex++; //skip 'set' do { //Resolves the target object. Note that this target can be an alias that is resolved later in the FROM statement var target = StatementResolveHelper.ResolveExpression(tokens, ref fileIndex, context); AddTargetObject(target, targetObject); fileIndex++; //skip '=' var source = StatementResolveHelper.ResolveExpression(tokens, ref fileIndex, context); //resolve source column target.ChildExpressions.Add(source); manipulation.Expressions.Add(target); if (fileIndex < tokens.Length && tokens[fileIndex].Text.Equals(",")) { fileIndex++; //skip ',' continue; } else { break; } } while (true); var objects = StatementResolveHelper.ResolveFromStatement(tokens, ref fileIndex, context); AddObjectsToContext(objects, context); if (objects.Count > 1) { targetObject = AssignRealTarget(objects, targetObject); var targetSynonymous = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(targetObject, InternalConstants.WHOLE_OBJECT_SYNONYMOUS), WholeObjectSynonymous = true }; foreach (var dbo in objects) { if (!dbo.Type.Equals(DatabaseObjectType.REAL) || dbo.Equals(targetObject)) { continue; } var sourceSynonymous = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(dbo, InternalConstants.WHOLE_OBJECT_SYNONYMOUS), WholeObjectSynonymous = true }; targetSynonymous.ChildExpressions.Add(sourceSynonymous); manipulation.Expressions.Add(targetSynonymous); } } var beautified = new List <Expression>(); foreach (var expr in manipulation.Expressions) { beautified.Add(Beautifier.BeautifyColumns(expr, context)); } manipulation.Expressions = beautified; StatementResolveHelper.ResolveWhereStatement(tokens, ref fileIndex, context); PopObjectsFromContextStack(context); return(manipulation); }
public DataManipulation Resolve(ReadOnlySpan <TSQLToken> tokens, ref int fileIndex, CompilerContext context) { manipulation = new DataManipulation(); fileIndex++; //skip "merge" //skip top expression SkipTopExpression(tokens, ref fileIndex, context); if (tokens[fileIndex].Text.ToLower().Equals("into")) { fileIndex++; } targetObject = StatementResolveHelper.ResolveDatabaseObject(tokens, ref fileIndex, context); context.AddDatabaseObjectToCurrentContext(targetObject); if (!tokens[fileIndex].Text.ToLower().Equals("using")) { throw new InvalidSqlException("Trying to resolve a merge-statement without using keyword"); } var source = ResolveUsingStatement(tokens, ref fileIndex, context); context.AddDatabaseObjectToCurrentContext(source); if (!tokens[fileIndex].Text.Equals("on", StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidSqlException("Expected 'ON' keyword when resolving a 'MERGE'-statement"); } fileIndex++; //skip 'on' SearchConditionResolver.Resolve(tokens, ref fileIndex, context); while (tokens[fileIndex].Text.Equals("when", StringComparison.InvariantCultureIgnoreCase)) { ResolveWhenExpression(tokens, ref fileIndex, context); } var beautified = new List <Expression>(); foreach (var exp in manipulation.Expressions) { beautified.Add(Beautifier.BeautifyColumns(exp, context)); } manipulation.Expressions = beautified; while (!tokens[fileIndex].Text.ToLower().Equals(";")) { fileIndex++; if (fileIndex == tokens.Length) { throw new InvalidSqlException("Trying to resolve a merge-statement without proper ';' determination"); } } fileIndex++; //skip ';' context.CurrentDatabaseObjectContext.Pop(); return(manipulation); }
public bool JSBeautifier(Document document) { if (document == null || document.Type != "Text" || document.Language == null || document.Language == "Plain Text" ) { return(false); } var oldActiveDocument = Dte.ActiveDocument; try { document.Activate(); var languageOptions = Dte.Properties["TextEditor", document.Language]; var insertTabs = (bool)languageOptions.Item("InsertTabs").Value; var isFilterAllowed = OptionsPage.AllowDenyFilter.IsAllowed(document.Name); var vsTextView = GetIVsTextView(document.FullName); if (vsTextView == null) { return(false); } var wpfTextView = GetWpfTextView(vsTextView); if (wpfTextView == null) { return(false); } _undoHistoryRegistry.TryGetHistory(wpfTextView.TextBuffer, out var history); using (var undo = history?.CreateTransaction("JSBeautify")) { vsTextView.GetCaretPos(out var oldCaretLine, out var oldCaretColumn); vsTextView.SetCaretPos(oldCaretLine, 0); var snapshot = wpfTextView.TextSnapshot; using (var edit = snapshot.TextBuffer.CreateEdit()) { string text = snapshot.GetText(); var beautifier = new Beautifier(); beautifier.Opts.IndentSize = 4; beautifier.Opts.IndentChar = ' '; beautifier.Opts.PreserveNewlines = true; beautifier.Opts.JslintHappy = true; beautifier.Opts.KeepArrayIndentation = true; beautifier.Opts.KeepFunctionIndentation = false; beautifier.Opts.BraceStyle = BraceStyle.Collapse; beautifier.Opts.BreakChainedMethods = false; beautifier.Flags.IndentationLevel = 0; text = beautifier.Beautify(text); edit.Replace(0, snapshot.Length, text); edit.Apply(); } vsTextView.GetCaretPos(out var newCaretLine, out var newCaretColumn); vsTextView.SetCaretPos(newCaretLine, oldCaretColumn); undo?.Complete(); } } finally { oldActiveDocument?.Activate(); } return(true); }