aligner
=======
Sublime Text plugin for automatic code alignment.
This project is a tool for automatic code alignment.
Formatting source code so that similar syntactic structures are arranged one above the other is often used to improve readability.
First of all, for convenience, the lines of code are split into tokens having a generic type.
For example, the identifiers have type `:id`, and the brackets have type `:bracket`.
The project implemented a type hierarchy, which simplifies the setup.
It is defined in `heirarchy.rb`.
Each type must match the regular expression that recognizes token of this type.
Moreover, the sequence of regular expressions must follow the hierarchy.
That is more general regular expressions are used later.
This sequence is described in the class `TypeData`, the file `staff.rb`.
To achieve maximum flexibility and independence of the type of language in which the source code is written,
parser of the context-free grammars is implemented.
It works in conjunction with the algorithm based on dynamic programming,
which finds matching having a maximum weight of two arrays of tokens.
The grammar in BNF is in file `grammar.rb`.
Grammar should be designed so that if the rule of convolution can be applied,
it should be applied, otherwise any sequence of tokens should still be correct.
Here is the example of grammar:
```
@@grammar.add_rule(:main, [:expr ], [:reducible]);
@@grammar.add_rule(:expr, [:expr, :p], [:reducible]);
@@grammar.add_rule(:expr, [:p ], [:reducible]);
t1 = [:expr, TokenTemplate.new(['=']), :expr]
@@grammar.add_rule(:expr, t1)
@@grammar.add_rule(:p, [:t], [:reducible])
@@grammar.add_rule(:t, [TokenTemplate.new(:id)], [:reducible]);
```
This grammar defines the assignment operation.
The first argument to the procedure of adding rules - nonterminal.
`:main` - axiom of the grammar.
The second argument is the rule itself. It may consist of nonterminals and templates of tokens.
A template can define a valid token type, a specific value, and excluded values.
Grammar shown corresponds to the following recorded in the canonical Backus–Naur form:
```
main ::= expr
expr ::= expr p | p | expr '=' expr
p ::= t
t ::= <any identifier>
```
Flag `:reducible` indicates that this rule has no effect on meta-expression being fitted.
Meta-expression is an array of tokens, which also contains other meta-expression.
Each level of the obtained tree structure is compared in the matching process only with the corresponding level of the other meta-expression.
Consider the example:
```
f(a, b + c )
f( b + c, a)
```
and
```
f(a , b + c)
f(b + c, a )
```
When using the grammar, the program causes the alignment of the second type,
in spite of the fact that different function arguments are similar in spelling.
Such behavior is, of course, leads to improvement of readability.
To maximize the quality for each language you need to write its own grammar.
## Examples of work
From
```
@@types_inheritance[:space] = nil;
@@types_inheritance[:quote] = nil;
@@types_inheritance[:regexp] = nil;
@@types_inheritance[:id] = nil;
@@types_inheritance[:spchar] = nil;
```
To
```
@@types_inheritance[:space ] = nil;
@@types_inheritance[:quote ] = nil;
@@types_inheritance[:regexp] = nil;
@@types_inheritance[:id ] = nil;
@@types_inheritance[:spchar] = nil;
```
---
From
```
switch (state)
{
case State.QLD: city = "Brisbane"; break;
case State.WA: city = "Perth"; break;
case State.NSW: city = "Sydney"; break;
default: city = "???"; break;
}
```
To
```
switch (state)
{
case State.QLD:city = "Brisbane"; break;
case State.WA :city = "Perth" ; break;
case State.NSW:city = "Sydney" ; break;
default :city = "???" ; break;
}
```
##Learning
Due to the fact that different people are accustomed to different ways of setting padding between tokens,
you must use the simplest method of fine-tuning.
The project implements a method of learning. The input is properly formatted string.
The resulting information is aggregated and used in the future for proper indenting.
There are 2 types of training: minimum and maximum indents.
Training starts with the command `ruby learner_test.rb <lang_type>`.
It is not required by default.
The resulting information is stored in files `max_by_type_<lang_type>.dat` and `min_by_type_<lang_type>.dat`.
##Installation
First of all, make sure that your system has a ruby interpreter `ver. >= 1.9`.
In Ubuntu you can use following command:
```
sudo apt-get install ruby
```
To install the plugin, clone it to your Siblime Text 2/3 Package directory with following command:
```
cd ~/.config/sublime-text-3/Packages
git clone https://github.com/generall/aligner.git AutoAligner
```
Or you may install it with Package Control using name `AutoAligner`.
Default hotkey for alignment is: `["ctrl+k","ctrl+a"]`.
##Prospection
Here is a list of things that have to be improved.
* Automatic detection of similar lines for fully automated code alignment.
* Customization for different languages.
* extended grammar
* extended set of types of token
* Customized languages:
* C
* java
* Extended machine learning for alignment decision
* experiments with Markov chain learing
* to be continued...
## The expected course of action to add the grammar.
In file `staff.rb` add new regexp array by following pattern:
```
@@regexp_array[:new_grammar_name] =
[
# [<reg_exp>, <tag>, <is_necessary>, <min_simularity>, <min_previous_space>, <min_follow_space> ]
[/^'(\\.|[^'])*'/ , :quote , true , 0.1, 0, 1],
...
]
```
Add BNF to file `grammar.rb`.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sublime text3 verilog&VHDL;语言专版 (772个子文件)
01524fae79697630d0454ba3fabd9414 3.25MB
make.bat 5KB
Startup.cache 305KB
PHP Source.sublime-syntax.cache 31KB
Matlab.sublime-syntax.cache 26KB
Objective-C.sublime-syntax.cache 25KB
CSS.sublime-syntax.cache 17KB
C#.sublime-syntax.cache 16KB
Objective-C++.sublime-syntax.cache 15KB
Python.sublime-syntax.cache 15KB
JavaScript.sublime-syntax.cache 14KB
R.sublime-syntax.cache 14KB
C++.sublime-syntax.cache 14KB
Meta Info Summary.cache 13KB
C.sublime-syntax.cache 11KB
Scala.sublime-syntax.cache 11KB
Markdown.sublime-syntax.cache 11KB
Clojure.sublime-syntax.cache 11KB
LaTeX.sublime-syntax.cache 10KB
Bash.sublime-syntax.cache 10KB
Ruby.sublime-syntax.cache 10KB
VHDL.sublime-syntax.cache 9KB
D.sublime-syntax.cache 9KB
Java.sublime-syntax.cache 9KB
AppleScript.sublime-syntax.cache 9KB
Rust.sublime-syntax.cache 8KB
commands-builtin-shell-bash.sublime-syntax.cache 7KB
Perl.sublime-syntax.cache 7KB
ASP.sublime-syntax.cache 7KB
ActionScript.sublime-syntax.cache 7KB
VHDL.tmLanguage.cache 6KB
OCaml.sublime-syntax.cache 6KB
Erlang.sublime-syntax.cache 6KB
VHDL.tmLanguage.cache 6KB
Groovy.sublime-syntax.cache 5KB
HTML.sublime-syntax.cache 5KB
Lisp.sublime-syntax.cache 5KB
Go.sublime-syntax.cache 5KB
Batch File.sublime-syntax.cache 5KB
Syntax Summary.cache 5KB
Makefile.sublime-syntax.cache 5KB
Tcl.sublime-syntax.cache 4KB
YAML.sublime-syntax.cache 4KB
Orcad_TCL.tmLanguage.cache 3KB
Git Commit.sublime-syntax.cache 3KB
Orcad_TCL.tmLanguage.cache 3KB
RegExp.sublime-syntax.cache 3KB
do.tmLanguage.cache 3KB
Haskell.sublime-syntax.cache 3KB
do.tmLanguage.cache 3KB
SQL.sublime-syntax.cache 3KB
sdc.tmLanguage.cache 2KB
Monokai Classic.tmTheme.cache 2KB
Monokai Pro.tmTheme.cache 2KB
XML.sublime-syntax.cache 2KB
Monokai Pro (Filter Machine).tmTheme.cache 2KB
Monokai Pro (Filter Octagon).tmTheme.cache 2KB
Monokai Pro (Filter Spectrum).tmTheme.cache 2KB
sdc.tmLanguage.cache 2KB
SystemVerilog.tmLanguage.cache 2KB
Tk.tmLanguage.cache 2KB
SystemVerilog.tmLanguage.cache 2KB
Tk.tmLanguage.cache 2KB
Verilog.tmLanguage.cache 2KB
Git Config.sublime-syntax.cache 2KB
Verilog.tmLanguage.cache 2KB
Verilog.tmLanguage.cache 2KB
TeX.sublime-syntax.cache 2KB
Textile.sublime-syntax.cache 2KB
Mariana.tmTheme.cache 2KB
OCamllex.sublime-syntax.cache 2KB
Breakers.tmTheme.cache 2KB
JavaDoc.sublime-syntax.cache 2KB
OCamlyacc.sublime-syntax.cache 2KB
Monokai.tmTheme.cache 2KB
reStructuredText.sublime-syntax.cache 2KB
Git Attributes.sublime-syntax.cache 2KB
Lua.sublime-syntax.cache 2KB
DOT.sublime-syntax.cache 1KB
JSON.sublime-syntax.cache 1KB
Ruby on Rails.sublime-syntax.cache 1KB
Git Rebase.sublime-syntax.cache 1KB
Sixteen.tmTheme.cache 1KB
Git Common.sublime-syntax.cache 1KB
Regular Expressions (JavaScript).sublime-syntax.cache 1KB
Regular Expressions (PHP).sublime-syntax.cache 1KB
Rd (R Documentation).sublime-syntax.cache 1KB
Pascal.sublime-syntax.cache 1KB
Regular Expressions (Python).sublime-syntax.cache 1KB
Bibtex.sublime-syntax.cache 1KB
HTML (Tcl).sublime-syntax.cache 1010B
Io.tmLanguage.cache 991B
Ruby Haml.sublime-syntax.cache 985B
Java Server Pages (JSP).sublime-syntax.cache 909B
Diff.sublime-syntax.cache 788B
Git Link.sublime-syntax.cache 742B
LaTeX Log.sublime-syntax.cache 668B
HTML-ASP.sublime-syntax.cache 640B
Build.sublime-syntax.cache 604B
Literate Haskell.sublime-syntax.cache 588B
共 772 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- 「已注销」2019-01-12很好用,good!
- lisq7892019-04-19不错的编辑器,谢谢分享
- 火山10092019-04-21可以的额!
刻一
- 粉丝: 113
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DatabaseWatermarkingBasedonTextFormat
- -移动通信-网络课程设计与研究
- 基于Python的PCA人脸识别算法的原理及实现代码+文档详解.zip
- 甘肃移动全业务工程建设项目管理流程优化研究
- 549springboot + vue 民宿管理平台.zip (可运行源码+数据库文件+文档)
- ZArchiver.Pro_0.9.5.apk
- vmware环境配置.mp4
- 548springboot + vue 大学生社团活动平台.zip(可运行源码+数据库文件+文档)
- 微信小程序 辩论倒计时小程序源码 作业设计demo 计算机专业参考
- 深入探究文件IO,嵌入式Linux
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功