Skip to content

Commit

Permalink
[Erlang] Rewrite Syntax
Browse files Browse the repository at this point in the history
Fixes sublimehq#1609
Fixes sublimehq#1724

According to sublimehq#481 this PR provides an Oniguruma free Erlang syntax
definition written from scratch.

Outline
=======

The syntax definition is based on the http://erlang.org/doc and
includes all sematic features of Erlang/OTP 21.2 which are required
for highlighting.

It follows https://www.sublimetext.com/docs/3/syntax.html and includes
concepts from https://github.com/sublimehq/Packages.

Nearly every aspect and detail of the syntax definition was designed
from ground up making use of the latest features of ST's syntax engine
and with the intent to apply the most recent best practice examples
found in other recently updated syntax definitions.

Changes
=======

* Add support for Erlang ShellScript (escript)
* Add support for Erlang Type Language (`-type`, `-spec` directive)
* Add lots of detailed test cases
* Add some invalid illegal matching where appropriate
* Add builtin constants and macros highlighting
* Improve the list of builtin functions
  ([BIFs](http://erlang.org/doc/man/erlang.html#exports))
* Improve indention settings
* Improve shebang/editorconfig detection in `first_line_match`
* Improve support for _Goto Definition_ and _Goto Reference_
* Improve parsing performance by round about 50%
* Fix quoted atom highlighting (function names, module names, field names, ...)
* Fix bitstring data type highlighting
* Fix string escape highlighting
* Fix string placeholders highlighting
* Fix identifier break handling (`@` is no word-break)
* Fix lots of context pop offs
* ...

Benchmarks
==========

The whole design and development process included benchmarking of
different solutions to find the best possible performance for the
different sets of rules. The following examples provide an impression
of the performance improvements achieved with the new design.

**10k binary**

  Bin  = << << (X*2) >> || <<X>> <= << 1,2,3 >> >>.

**10k maps**

  Expr#{name=>"adam",{age,24}:=fct(),4.0=>{july,29}}

**10k records**

  #record{field1="val1", Field2=3, field3, 'Field-4'={}, _=atom}

**10k fun types**

  -type fun() :: fun(() -> int()).

**10k spec**

  -spec is_foo(Pid) -> boolean() when Pid :: pid() | if(); (Pid) -> ok.

**ErlangOTP files**

https://github.com/erlang/otp/blob/master/lib/wx/include/gl.hrl
https://github.com/erlang/otp/blob/master/lib/stdlib/test/re_testoutput1_split_test.erl
https://github.com/erlang/otp/blob/master/lib/xmerl/test/xmerl_sax_std_SUITE.erl
https://github.com/erlang/otp/blob/master/lib/crypto/test/crypto_SUITE.erl

Results
=======

Type                           | before     | after       | difference
-------------------------------|------------|-------------|------------
10k binaries                   |     303ms  |      140ms  |   -53.8%
10k maps                       |     326ms  |      156ms  |   -52.1%
10k records                    |     399ms  |      130ms  |   -67.4%
10k fun type                   |      n.a.  |       79ms  |
10k spec                       |      n.a.  |      176ms  |
gl.hrl                         |      47ms  |       24ms  |   -48.9%
re_testoutput1_split_test.erl  |     448ms  |      305ms  |   -31.9%
xmerl_sax_std_SUITE.erl        |     389ms  |      127ms  |   -67.4%
crypto_SUITE.erl               |      79ms  |       27ms  |   -65.8%
  • Loading branch information
DeathAxe committed Feb 10, 2019
1 parent 265e2c6 commit 12a39b7
Show file tree
Hide file tree
Showing 31 changed files with 7,162 additions and 748 deletions.
2 changes: 0 additions & 2 deletions Erlang/Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.erlang</string>
<key>settings</key>
Expand Down
20 changes: 20 additions & 0 deletions Erlang/Completion Rules.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.erlang</string>
<key>settings</key>
<dict>
<key>cancelCompletion</key>
<string><![CDATA[(?x:
# anything up to a comment sign
^[^%]* (
# cancel after control keywords
\-\s*(else|endif) |
# line ends with `of`
(^|[^\w@])(endif|else|elsif|of)
)
)]]></string>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Erlang/Erlang.sublime-build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cmd": ["erl", "-compile", "$file"],
"file_regex":"^([^:]+):([0-9]*):?(.*):?(.*)",
"selector": "source.erl"
"selector": "source.erlang"
}
5 changes: 5 additions & 0 deletions Erlang/Erlang.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// Characters that are considered to separate words
// Note: default separators without `@`
"word_separators": "./\\()\"'-:,.;<>~!#$%^&*|+=[]{}`~?",
}
Loading

0 comments on commit 12a39b7

Please sign in to comment.