{"id":17153424,"url":"https://github.com/generall/aligner","last_synced_at":"2025-04-13T12:44:17.914Z","repository":{"id":18365992,"uuid":"21546267","full_name":"generall/aligner","owner":"generall","description":"Sublime Text plugin for automatic code alignment.","archived":false,"fork":false,"pushed_at":"2016-10-28T10:37:25.000Z","size":77,"stargazers_count":36,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T13:47:37.308Z","etag":null,"topics":["aligner","bnf","grammar","plugin","regular-expression","ruby","text-editor"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/generall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-06T18:50:22.000Z","updated_at":"2023-08-24T23:57:44.000Z","dependencies_parsed_at":"2022-09-02T18:01:31.561Z","dependency_job_id":null,"html_url":"https://github.com/generall/aligner","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generall%2Faligner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generall%2Faligner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generall%2Faligner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generall%2Faligner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/generall","download_url":"https://codeload.github.com/generall/aligner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717240,"owners_count":21150387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aligner","bnf","grammar","plugin","regular-expression","ruby","text-editor"],"created_at":"2024-10-14T21:46:11.506Z","updated_at":"2025-04-13T12:44:17.887Z","avatar_url":"https://github.com/generall.png","language":"Ruby","readme":"Aligner [![Build Status](https://travis-ci.org/generall/aligner.svg?branch=master)](https://travis-ci.org/generall/aligner)\n=======\n\nSublime Text plugin for automatic code alignment.\n\nThis project is a tool for automatic code alignment. \nFormatting source code so that similar syntactic structures are arranged one above the other is often used to improve readability.\n\nFirst of all, for convenience, the lines of code are split into tokens having a generic type.\nFor example, the identifiers have type `:id`, and the brackets have type `:bracket`.\nThe project implemented a type hierarchy, which simplifies the setup.\nIt is defined in `heirarchy.rb`.\n\n\nEach type must match the regular expression that recognizes token of this type.\nMoreover, the sequence of regular expressions must follow the hierarchy.\nThat is more general regular expressions are used later.\nThis sequence is described in the class `TypeData`, the file `staff.rb`.\n\n\nTo achieve maximum flexibility and independence of the type of language in which the source code is written,\nparser of the context-free grammars is implemented.\n\nIt works in conjunction with the algorithm based on dynamic programming,\nwhich finds matching having a maximum weight of two arrays of tokens.\n\nThe grammar in BNF is in file `grammar.rb`.\nGrammar should be designed so that if the rule of convolution can be applied,\nit should be applied, otherwise any sequence of tokens should still be correct.\n\nHere is the example of grammar:\n```\n@@grammar.add_rule(:main, [:expr    ], [:reducible]);\n@@grammar.add_rule(:expr, [:expr, :p], [:reducible]);\n@@grammar.add_rule(:expr, [:p       ], [:reducible]);\nt1 = [:expr, TokenTemplate.new(['=']), :expr]\n@@grammar.add_rule(:expr, t1)\n@@grammar.add_rule(:p, [:t], [:reducible])\n@@grammar.add_rule(:t, [TokenTemplate.new(:id)], [:reducible]);\n```\n\nThis grammar defines the assignment operation.\nThe first argument to the procedure of adding rules - nonterminal. \n`:main` - axiom of the grammar.\nThe second argument is the rule itself. It may consist of nonterminals and templates of tokens.\nA template can define a valid token type, a specific value, and excluded values.\n\nGrammar shown corresponds to the following recorded in the canonical Backus–Naur form:\n\n```\nmain ::= expr\nexpr ::= expr p | p | expr '=' expr\np    ::= t\nt    ::= \u003cany identifier\u003e\n```\n\nFlag `:reducible` indicates that this rule has no effect on meta-expression being fitted.\nMeta-expression is an array of tokens, which also contains other meta-expression.\nEach level of the obtained tree structure is compared in the matching process only with the corresponding level of the other meta-expression.\nConsider the example:\n```\nf(a, b + c   )\nf(   b + c, a)\n```\nand\n```\nf(a    , b + c)\nf(b + c, a    )\n```\nWhen using the grammar, the program causes the alignment of the second type,\nin spite of the fact that different function arguments are similar in spelling.\nSuch behavior is, of course, leads to improvement of readability.\n\nTo maximize the quality for each language you need to write its own grammar.\n\n## Examples of work\n\nFrom\n```\n@@types_inheritance[:space] = nil;\n@@types_inheritance[:quote] = nil;\n@@types_inheritance[:regexp] = nil;\n@@types_inheritance[:id] = nil;\n@@types_inheritance[:spchar] = nil;\n```\n\nTo\n\n```\n@@types_inheritance[:space ] = nil;\n@@types_inheritance[:quote ] = nil;\n@@types_inheritance[:regexp] = nil;\n@@types_inheritance[:id    ] = nil;\n@@types_inheritance[:spchar] = nil;\n```\n---\n\nFrom\n```\nswitch (state)                                \n{                                            \n    case State.QLD: city = \"Brisbane\"; break; \n    case State.WA: city = \"Perth\"; break;     \n    case State.NSW: city = \"Sydney\"; break;   \n    default: city = \"???\"; break;             \n}            \n```\n\nTo\n\n```\nswitch (state)                                \n{\n    case State.QLD:city = \"Brisbane\"; break;\n    case State.WA :city = \"Perth\"   ; break;\n    case State.NSW:city = \"Sydney\"  ; break;\n    default       :city = \"???\"     ; break;\n}                                            \n```\n\n##Learning\n\nDue to the fact that different people are accustomed to different ways of setting padding between tokens,\nyou must use the simplest method of fine-tuning.\nThe project implements a method of learning. The input is properly formatted string.\nThe resulting information is aggregated and used in the future for proper indenting.\n\nThere are 2 types of training: minimum and maximum indents.\n\nTraining starts with the command `ruby learner_test.rb \u003clang_type\u003e`.\nIt is not required by default.\nThe resulting information is stored in files `max_by_type_\u003clang_type\u003e.dat` and `min_by_type_\u003clang_type\u003e.dat`.\n\n##Installation\n\nFirst of all, make sure that your system has a ruby interpreter `ver. \u003e= 1.9`.\nIn Ubuntu you can use following command:\n```\nsudo apt-get install ruby\n```\n\nTo install the plugin, clone it to your Siblime Text 2/3 Package directory with following command:\n\n```\ncd ~/.config/sublime-text-3/Packages\ngit clone https://github.com/generall/aligner.git AutoAligner\n```\nOr you may install it with Package Control using name `AutoAligner`.\n\nDefault hotkey for alignment is: `[\"ctrl+k\",\"ctrl+a\"]`.\n\n##Prospection\n\nHere is a list of things that have to be improved.\n\n* Automatic detection of similar lines for fully automated code alignment.\n* Customization for different languages.\n\t* extended grammar\n\t* extended set of types of token\n    * Customized languages:\n        * C\n        * java\n* Extended machine learning for alignment decision\n\t* experiments with Markov chain learing\n* to be continued...\n\n## The expected course of action to add the grammar.\n\nIn file `staff.rb` add new regexp array by following pattern:\n```\n@@regexp_array[:new_grammar_name] =\n[\n\t\t# [\u003creg_exp\u003e, \u003ctag\u003e, \u003cis_necessary\u003e, \u003cmin_simularity\u003e, \u003cmin_previous_space\u003e, \u003cmin_follow_space\u003e ]\n\t\t[/^'(\\\\.|[^'])*'/                 , :quote       , true , 0.1, 0, 1], \n\t\t...\n] \n```\n\nAdd BNF to file `grammar.rb`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerall%2Faligner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenerall%2Faligner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerall%2Faligner/lists"}