This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
4715 lines (4573 loc) · 172 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ElixirConf 2015 - The Road to IntelliJ Elixir 1.0.0</title>
<meta name="description" content="How I went from "I wonder if there's an Rubymine plugin for Elixir?" to writing one myself and eventually using it to find bugs in native Elixir.">
<meta name="author" content="Luke Imhoff">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section class="stack">
<section>
<h1>ElixirConf 2015</h1>
<h2>The Road to IntelliJ Elixir 1.0.0</h2>
<p>2015-10-02 to 2015-10-03</p>
<p>Luke Imhoff</p>
<table>
<tbody>
<tr>
<th>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" id="Capa_1" x="0px" y="0px" width="14px" height="10px"
viewBox="0 0 14 10" enable-background="new 0 0 14 10" xml:space="preserve">
<g>
<path d="M7,7L5.268,5.484L0.316,9.729C0.496,9.896,0.739,10,1.007,10h11.986c0.267,0,0.509-0.104,0.688-0.271L8.732,5.484L7,7z"></path>
<path d="M13.684,0.271C13.504,0.103,13.262,0,12.993,0H1.007C0.74,0,0.498,0.104,0.318,0.273L7,6L13.684,0.271z"></path>
<polygon points="0,0.878 0,9.186 4.833,5.079 "></polygon>
<polygon points="9.167,5.079 14,9.186 14,0.875 "></polygon>
</g>
</svg>
</th>
<td>[email protected]</td>
</tr>
<tr>
<th>
<svg version="1.1" class="github-icon-svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16"
enable-background="new 0 0 16 16" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#C2C2C2" d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761
c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32
c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472
c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037
C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65
c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261
c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082
c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129
c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z"></path>
</svg>
</th>
<td>
<a href="https://github.com/KronicDeth" target="_blank">@KronicDeth</a>
</td>
</tr>
<tr>
<th>
<svg version="1.1" class="twitter-icon-svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<path fill="#C2C2C2" d="M15.969,3.058c-0.586,0.26-1.217,0.436-1.878,0.515c0.675-0.405,1.194-1.045,1.438-1.809
c-0.632,0.375-1.332,0.647-2.076,0.793c-0.596-0.636-1.446-1.033-2.387-1.033c-1.806,0-3.27,1.464-3.27,3.27
c0,0.256,0.029,0.506,0.085,0.745C5.163,5.404,2.753,4.102,1.14,2.124C0.859,2.607,0.698,3.168,0.698,3.767
c0,1.134,0.577,2.135,1.455,2.722C1.616,6.472,1.112,6.325,0.671,6.08c0,0.014,0,0.027,0,0.041c0,1.584,1.127,2.906,2.623,3.206
C3.02,9.402,2.731,9.442,2.433,9.442c-0.211,0-0.416-0.021-0.615-0.059c0.416,1.299,1.624,2.245,3.055,2.271
c-1.119,0.877-2.529,1.4-4.061,1.4c-0.264,0-0.524-0.015-0.78-0.046c1.447,0.928,3.166,1.469,5.013,1.469
c6.015,0,9.304-4.983,9.304-9.304c0-0.142-0.003-0.283-0.009-0.423C14.976,4.29,15.531,3.714,15.969,3.058z"></path>
</svg>
</th>
<td>
<a href="https://twitter.com/KronicDeth" target="_blank">@KronicDeth</a>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Hello, my name is Luke Imhoff. I am the maintainer of intellij-elixir, the Elixir plugin
for Jetbrains IDEs, including IntelliJ itself and Rubymine. I have contributed to the
Elixir standard library and found bugs in the native tokenizer and parser through my
work on intellij-elixir. I help run the Austin Elixir meetup.
</p>
</aside>
</section>
<section>
<h1>This Presentation</h1>
<dl>
<dt>Slides</dt>
<dd>
<dl>
<dt>Viewable</dt>
<dd>
<a href="https://kronicdeth.github.io/the-road-to-intellij-elixir-1.0.0">
https://kronicdeth.github.io/the-road-to-intellij-elixir-1.0.0
</a>
</dd>
<dt>Source</dt>
<dd>
<a href="https://github.com/KronicDeth/the-road-to-intellij-elixir-1.0.0/tree/gh-pages">
https://github.com/KronicDeth/the-road-to-intellij-elixir-1.0.0/tree/gh-pages
</a>
</dd>
</dl>
</dd>
<dt>Project Source</dt>
<dd>
<a href="https://github.com/KronicDeth/intellij-elixir/tree/v1.0.0">
https://github.com/KronicDeth/intellij-elixir/tree/v1.0.0
</a>
</dd>
</dl>
<aside class="notes">
<p>
For viewers that want to follow along with their own copy of the slides or project
source, they can be accessed at the shown addresses.
</p>
</aside>
</section>
<section>
<h1>Outline</h1>
<ul>
<li>
<a href="#/introduction">Introduction</a>
</li>
<li>
<a href="#/bnf">BNF</a>
</li>
<li>
<a href="#/syntax">Syntax</a>
</li>
<li>
<a href="#/interpolation">Interpolation</a>
</li>
<li>
<a href="#/matched-expressions">Matched Expressions</a>
</li>
<li>
<a href="#/no-parentheses-function-calls">No Parentheses Function Calls</a>
</li>
<li>
<a href="#/jinterface">JInterface</a>
</li>
<li>
<a href="#/significant-whitespace">Significant Whitespace</a>
</li>
<li>
<a href="#/stab">Stab</a>
</li>
<li>
<a href="#/unmatched-expressions">Unmatched Expressions</a>
</li>
<li>
<a href="#/parsing-elixir-lang-elixir">
Parsing
<code>elixir-lang/elixir</code>
</a>
</li>
</ul>
</section>
</section>
<section class="stack">
<section id="introduction">
<h1>Introduction</h1>
<ul>
<li>
<a href="#/introduction-why-an-intellij-plugin">
Why an IntelliJ Plugin?
</a>
</li>
<li>
<a href="#/introduction-timeline">
Timeline
</a>
</li>
</ul>
</section>
<section id="introduction-why-an-intellij-plugin">
<h1>Why an IntelliJ Plugin?</h1>
<ul>
<li>I use Rubymine for Ruby development</li>
<li>Wanted vim key bindings</li>
<li>Wanted Cmd+Click Go To Definition for Elixir</li>
<li>Wanted Search Everywhere for Elixir</li>
<li>There was a tutorial</li>
</ul>
<aside class="notes">
<p>
People may wonder why I took it upon myself to make an IDE plugin for Elixir, when I
could have used a vim or emacs plugin.
</p>
<p>
I've used both emacs and vim. I started with emacs when I worked at Cray, only
switching to vim when I needed something that worked over a high-latency, low-bandwidth
CDMA modem on the high-way.
</p>
<p>
I started using Rubymine when my boss at a previous job, Nicholas Cancelliere,
introduced me to it. I was shocked that an IDE for a dynamic language like Ruby could
support Find Usage, Go To Definition, and Refactor. I had been use to using ctags for
vim.
</p>
<p>
I haven't complete abandoned using vim either. I still use syntax highlighting plugins
for vim in iTerm when I need to edit configuration files and I use the IDEAVim plugin
for Jetbrains IDEs like Rubymine, Webstorm, and IntelliJ.
</p>
<p>
Without Rubymine I don't think I'd have been able to as quickly dive through the complex
code-base in Metasploit and the graphical debugger allowed me to teach myself the
internals of Rails and other DSLs.
</p>
<p>
I understood that many of the features I liked about Rubymine were shared across
JetBrains' various IDEs, so if I could write the parts of a plugin to get JetBrains APIs
to understand Elixir syntax and semantics, the features I really wanted would just work
without me having to understand how to write the parts that were cross-language.
</p>
<p>
However, just getting syntax lexing and parsing right ended up taking a year...
</p>
</aside>
</section>
<section id="introduction-timeline">
<h1>Timeline</h1>
<table style="font-size: 85%">
<thead>
<tr>
<th rowspan="2">Date</th>
<th colspan="2">Days</th>
<th colspan="2">Commits</th>
<th colspan="2">Version</th>
</tr>
<tr>
<th>Delta</th>
<th>Total</th>
<th>Delta</th>
<th>Total</th>
<th>Commits/Day</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>2014-07-27</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>1.00</td>
<td>Initial</td>
</tr>
<tr>
<td>2014‑08‑02</td>
<td>6</td>
<td>6</td>
<td>18</td>
<td>19</td>
<td>3.00</td>
<td>0.0.1</td>
</tr>
<tr>
<td>2014‑08‑03</td>
<td>1</td>
<td>7</td>
<td>14</td>
<td>33</td>
<td>14.00</td>
<td>0.0.2</td>
</tr>
<tr>
<td>2014‑08‑08</td>
<td>5</td>
<td>12</td>
<td>10</td>
<td>43</td>
<td>2.00</td>
<td>0.0.3</td>
</tr>
<tr>
<td>2014‑09‑13</td>
<td>36</td>
<td>48</td>
<td>64</td>
<td>107</td>
<td>1.78</td>
<td>0.1.0</td>
</tr>
<tr>
<td>2014‑09‑20</td>
<td>7</td>
<td>55</td>
<td>4</td>
<td>111</td>
<td>0.57</td>
<td>0.1.1</td>
</tr>
<tr>
<td>2014‑09‑25</td>
<td>5</td>
<td>60</td>
<td>12</td>
<td>123</td>
<td>2.50</td>
<td>0.1.2</td>
</tr>
<tr>
<td>2014‑10‑14</td>
<td>19</td>
<td>79</td>
<td>23</td>
<td>146</td>
<td>1.21</td>
<td>0.1.3</td>
</tr>
<tr>
<td>2014‑11‑30</td>
<td>47</td>
<td>126</td>
<td>226</td>
<td>373</td>
<td>4.81</td>
<td>0.2.0</td>
</tr>
<tr>
<td>2015‑04‑03</td>
<td>124</td>
<td>250</td>
<td>521</td>
<td>894</td>
<td>4.20</td>
<td>0.2.1</td>
</tr>
<tr>
<td>2015‑04‑10</td>
<td>7</td>
<td>257</td>
<td>27</td>
<td>921</td>
<td>3.86</td>
<td>0.3.0</td>
</tr>
<tr>
<td>2015‑04‑27</td>
<td>17</td>
<td>274</td>
<td>66</td>
<td>987</td>
<td>3.88</td>
<td>0.3.1</td>
</tr>
<tr>
<td>2015‑05‑01</td>
<td>4</td>
<td>278</td>
<td>8</td>
<td>995</td>
<td>2.00</td>
<td>0.3.2</td>
</tr>
<tr>
<td>2015‑05‑15</td>
<td>14</td>
<td>292</td>
<td>34</td>
<td>1029</td>
<td>2.43</td>
<td>0.3.3</td>
</tr>
<tr>
<td>2015‑06‑04</td>
<td>20</td>
<td>312</td>
<td>86</td>
<td>1115</td>
<td>4.30</td>
<td>0.3.4</td>
</tr>
<tr>
<td>2015‑07‑08</td>
<td>34</td>
<td>346</td>
<td>83</td>
<td>1198</td>
<td>2.44</td>
<td>0.3.5</td>
</tr>
<tr>
<td>2015‑07‑27</td>
<td>19</td>
<td>365</td>
<td>158</td>
<td>1356</td>
<td>2.44</td>
<td>1.0.0</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
I was exactly 1 year between the initial commit of the project skeleton to the v1.0.0 tag.
</p>
</aside>
</section>
</section>
<section class="stack">
<section id="bnf">
<h1>BNF</h1>
<ul>
<li>
<a href="#/bnf-backus-naur-form">Backus Naur Form</a>
</li>
<li>
<a href="#/bnf-yecc">YECC</a>
</li>
<li>
<a href="#/bnf-grammar-kit">Grammar Kit</a>
</li>
<li>
<a href="#/bnf-v0.0.1">v0.0.1</a>
</li>
</ul>
</section>
<section id="bnf-backus-naur-form">
<h1>Backus-Naur Form</h1>
<table>
<thead>
<tr>
<th>Read as</th>
<th>Symbol</th>
</tr>
</thead>
<tbody>
<tr>
<td>Metasyntactic Variable</td>
<td>
<pre><code class="bnf"><variable></code></pre>
</td>
</tr>
<tr>
<td>is defined as</td>
<td>
<pre><code class="bnf">::=</code></pre>
</td>
</tr>
<tr>
<td>or</td>
<td>
<pre><code class="bnf">|</code></pre>
</td>
</tr>
</tbody>
</table>
<pre><code data-trim>
<expr> ::= <integer> | <expr> <op> <integer>
</code></pre>
<aside class="notes">
<p>
One of the standard ways of defining a syntax is in BNF, or Backus-Naur Form, which
was first used for the Algol 60 standard.
</p>
<p>
Both YECC and GrammarKit use a form of BNF, so I assumed it was just a matter of
porting elixir dot Y-R-L to elixir dot B-N-F.
</p>
</aside>
</section>
<section id="bnf-yecc">
<h1>YECC</h1>
<figure>
<figcaption>
<a href="https://github.com/elixir-lang/elixir/blob/12f89a30b46279398fc7143e433681c2194b03d9/lib/elixir/src/elixir_parser.yrl#L77-L82">
lib/elixir/src/elixir_parser.yrl
</a>
</figcaption>
<pre><code data-trim style="font-size: 300%; line-height: 100%">
grammar -> eoe : nil.
grammar -> expr_list : to_block('$1').
grammar -> eoe expr_list : to_block('$2').
grammar -> expr_list eoe : to_block('$1').
grammar -> eoe expr_list eoe : to_block('$2').
grammar -> '$empty' : nil.
</code></pre>
</figure>
<aside class="notes">
<p>
YECC is a parser generator written in Erlang (and part of the standard distribution)
that is based on yacc (with an 'a' instead of an 'e'), which is a parser generator
written in C.
</p>
<p>
The YECC syntax differs from B-N-F in that it uses a skinny arrow (<code>-></code>)
instead of colon colon equals (<code>::=</code>) and instead of using pipe
(<code>|</code>) for OR, lines with the same rule name are repeated with alternative
definitions. Finally, YECC supports running Erlang code on the tokens using dollar
number (<code>$n</code>) for positional references to the matches tokens.
</p>
<p>
dollar empty (<code>$empty</code>) is a special token that matches no input. In
formal grammars this is usually referred to as (lowercase) epsilon (<code>ɛ</code>).
</p>
</aside>
</section>
<section id="bnf-grammar-kit">
<h1>Grammar Kit</h1>
<figure>
<figcaption>
<a href="https://github.com/KronicDeth/intellij-elixir/blob/v1.0.0/src/org/elixir_lang/Elixir.bnf">
src/org/elixir_lang/Elixir.bnf
</a>
</figcaption>
<pre><code data-trim style="font-size: 165%; line-height: 100%">
private elixirFile ::= endOfExpression? (expressionList endOfExpression?)?
private expressionList ::= expression (endOfExpression expression | adjacentExpression)*
</code></pre>
</figure>
<aside class="notes">
<p>
Grammar Kit is a parser generator written in Java and created by JetBrains.
</p>
<p>
GrammarKit's B-N-F format <strong>does</strong> use colon colon equals (<code>::=</code>)
like Backus-Naur Form, but it has some more power constructs above pipe (<code>|</code>)
for OR.
</p>
<p>
Question mark (<code>?</code>) can be used for 0 or 1, parentheses (<code>()</code>)
can be used for grouping; and star can be used for 0 or more. Empty can be implied
by question mark (<code>?</code>) or star (<code>*</code>) matching nothing or there
being nothing on the right-hand-side of the colon colon equals (<code>::=</code>).
</p>
<p>
You'll also notice that there is no inline Java code after the rule definition unlike
in YECC where there as Erlang code. This is because GrammarKit automatically generates
an AST, which it calls a PSI (or Program Structure Interface) Tree from the matched
rules, so there's no need to define how to build the tree.
</p>
<p>
Having GrammarKit generate the AST is both good and bad. It's good because it removes
a lot of redundant code, but it's bad because rules must evaluate in the correct order
to reflect the desired nesting and associativity without any manual fixups, which are
possible with the Erlang code in YECC.
</p>
</aside>
</section>
<section id="bnf-v0.0.1">
<h1>v0.0.1</h1>
<table style="font-size: 85%">
<thead>
<tr>
<th rowspan="2">Date</th>
<th colspan="2">Days</th>
<th colspan="2">Commits</th>
<th colspan="2">Version</th>
</tr>
<tr>
<th>Delta</th>
<th>Total</th>
<th>Delta</th>
<th>Total</th>
<th>Commits/Day</th>
</tr>
</thead>
<tbody>
<tr>
<td>2014‑08‑02</td>
<td>6</td>
<td>6</td>
<td>18</td>
<td>19</td>
<td>3.00</td>
</tr>
</tbody>
</table>
<ol>
<li>Translate from YECC to Grammar Kit</li>
<li>Freeze IDE</li>
</ol>
<aside class="notes">
<p>
YECC and Grammar Kit both support a form of BNF and Grammar Kit seems like it would
support even a more compact grammar because question mark (<code>?</code>), star
(<code>star</code>), pipe (<code>|</code>) and parentheses (<code>()</code>) could
eliminate some of the redundancy needed in the multi-clause rules in YECC.
</p>
<p>
After only 6 days I had quote unquote translated the BNF from yecc to Grammar Kit and
ended up with a parser that froze the IDE, which Julius "h4cc" Beckmann reported. That
left the slow process of translating the grammar correctly over the next 359 days. At
the time of the freeze, I didn't even really understand translating the BNF didn't work,
all I knew was I needed to go slower and build the grammar up from simpler, testable
pieces.
</p>
</aside>
</section>
</section>
<section class="stack">
<section id="syntax">
<h1>Syntax</h1>
<ul>
<li>
<a href="#/syntax-analysis">Syntactic Analysis</a>
</li>
<li>
<a href="#/syntax-lexing">Lexing/Tokenizing</a>
</li>
<li>
<a href="#/syntax-ignored">Ignoring Characters</a>
</li>
</ul>
</section>
<section id="syntax-analysis">
<h1>Syntactic Analysis</h1>
<table>
<thead>
<tr>
<th>Step</th>
<th>Elixir</th>
<th>IntelliJ Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<th>Lexing</th>
<td>
Erlang
</td>
<td>
JFlex
</td>
</tr>
<tr>
<th>Parsing</th>
<td>
YECC
</td>
<td>
GrammarKit
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
So, I went back and actually started to do the JetBrains tutorial step by step instead
of jumping ahead and searched Wikipedia, trying to find CompSci articles that explained
the correct way to do this.
</p>
<p>
In order to support color syntax highlighting and mark syntax errors with the nice
red squiggly under line, IntelliJ Elixir needed to be able to analyze Elixir syntax.
</p>
<p>
Syntactic analysis is usually broken down into two parts: the first breaks the raw text
into tokens and the second checks if those tokens are arranged in the correct order.
</p>
<p>
In most programming languages, both lexers and parsers are built using generators that
have an external DSL. In Elixir, the lexer is built using Erlang directly because
Erlang pattern matching is compact enough that a generator is unnecessary.
Additionally, Elixir syntax contains some features that normal lexer generator aren't
expecting.
</p>
<p>
For IntelliJ Elixir, I used JFlex because it was the lexer generator recommended by
JetBrain's plugin tutorial.
</p>
<p>
For parsing Elixir does use a generator, called yecc, which generates Erlang code.
</p>
<p>
For IntelliJ Elixir, I used JetBrains' GrammarKit.
</p>
<p>
When I first started IntelliJ Elixir I didn't understand the important difference
between these two stacks, but I hope to explain what I learned along the way to you.
</p>
</aside>
</section>
<section id="syntax-lexing">
<h1>Lexing/Tokenizing</h1>
<ol>
<li>Match Input</li>
<li>Emit Token</li>
</ol>
<aside class="notes">
<p>
The first step of syntactic analysis is lexing, also known as tokenizing. Lexing
breaks up the raw text into tokens, such as keywords, literals, operators, and
identifiers.
</p>
<p>
Input is matched using some pattern. In native Elixir, this is pattern matching on
Erlang string prefixes. In IntelliJ Elixir's JFlex file, it's regular expressions.
</p>
</aside>
</section>
<section id="syntax-ignored">
<h1>Ignoring Characters</h1>
<table class="stretch">
<thead>
<tr>
<th>Token</th>
<th>Erlang</th>
<th>JFlex</th>
</tr>
</thead>
<tbody>
<tr>
<td>Comments</td>
<td>
<a href="https://github.com/elixir-lang/elixir/blob/v0.14.3/lib/elixir/src/elixir_tokenizer.erl#L133-L137">
<pre><code class="erlang" data-trim style="font-size: 85%; line-height: 100%">
tokenize([$#|String], Line, Scope, Tokens) ->
Rest = tokenize_comment(String),
tokenize(Rest, Line, Scope, Tokens);
tokenize_comment("\r\n" ++ _ = Rest) -> Rest;
tokenize_comment("\n" ++ _ = Rest) -> Rest;
tokenize_comment([_|Rest]) -> tokenize_comment(Rest);
tokenize_comment([]) -> [].
</code></pre>
</a>
</td>
<td>
<a href="https://github.com/KronicDeth/intellij-elixir/blob/v0.0.2/src/org/elixir_lang/Elixir.flex#L21-L63">
<pre><code data-trim>
COMMENT = "#" [^\r\n]* {EOL}?
<YYINITIAL> {
{COMMENT} { yybegin(BODY); return ElixirTypes.COMMENT; }
}
<BODY> {
{COMMENT} { return ElixirTypes.COMMENT; }
}
</code></pre>
</a>
</td>
</tr>
<tr>
<td>EOL</td>
<td>
<a href="https://github.com/elixir-lang/elixir/blob/v0.14.3/lib/elixir/src/elixir_tokenizer.erl#L320-L324">
<pre><code class="erlang" data-trim>
tokenize("\n" ++ Rest, Line, Scope, Tokens) ->
tokenize(Rest, Line + 1, Scope, eol(Line, newline, Tokens));
tokenize("\r\n" ++ Rest, Line, Scope, Tokens) ->
tokenize(Rest, Line + 1, Scope, eol(Line, newline, Tokens));
eol(_Line, _Mod, [{',',_}|_] = Tokens) -> Tokens;
eol(_Line, _Mod, [{eol,_,_}|_] = Tokens) -> Tokens;
eol(Line, Mod, Tokens) -> [{eol,Line,Mod}|Tokens].
</code></pre>
</a>
</td>
<td>
<a href="https://github.com/KronicDeth/intellij-elixir/blob/v0.0.2/src/org/elixir_lang/Elixir.flex#L18-L59">
<pre><code data-trim style="font-size: 95%; line-height: 100%;">
EOL = \n|\r|\r\n
<YYINITIAL> {
({EOL}|{WHITE_SPACE})+ { yybegin(BODY);
return TokenType.WHITE_SPACE; }
}
<BODY> {
{EOL}({EOL}|{WHITE_SPACE})* { return ElixirTypes.EOL; }
}
</code></pre>
</a>
</td>
</tr>
<tr>
<td>Whitespace</td>
<td>
<a href="https://github.com/elixir-lang/elixir/blob/v0.14.3/lib/elixir/src/elixir_tokenizer.erl#L478-L479">
<pre><code class="erlang" data-trim style="font-size: 90%; line-height: 100%">
tokenize([T|Rest], Line, Scope, Tokens) when ?is_horizontal_space(T) ->
tokenize(strip_horizontal_space(Rest), Line, Scope, Tokens);
strip_horizontal_space([H|T]) when ?is_horizontal_space(H) ->
strip_horizontal_space(T);
strip_horizontal_space(T) ->
T.
</code></pre>
</a>
</td>
<td>
<a href="https://github.com/KronicDeth/intellij-elixir/blob/v0.0.2/src/org/elixir_lang/Elixir.flex#L21-L63">
<pre><code data-trim>
<BODY> {
{WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
}
</code></pre>
</a>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
In addition to turning runs of characters into single tokens, the lexer can be used
to filter out runs that don't affect the meaning of code, such as spaces, extra new
lines and comments.
</p>
<p>
The Erlang lexer processes the raw text as a char list. Pattern matching on the head of
the list and then recursively calling <code>tokenize</code> on the rest of the raw text.
The Erlang lexer only keeps track of the effect of ignored characters on the current
line number, which was the only metadata in Elixir v0.14.3.
</p>
<p>
In contrast, the JFlex lexer processes the raw text as unicode characters. Regular
expressions and references to other named regular expressions (as seen in COMMENT using
EOL) can be used to match text with the longest match in a given state. In the
Erlang Lexer, the order matches the order of the clauses. The JFlex lexer emits a token
for even ignored characters because in an editor, unlike a compiler, one cares about
comments, whitespace and extra newlines.
</p>
</aside>
</section>
</section>
<section class="stack">
<section id="interpolation">
<h1>Interpolation</h1>
<ul>
<li>
<a href="#/interpolation-interpolation">Interpolation</a>
</li>
<li>
<a href="#/interpolation-computational-hierarchy">Computational Hierarchy</a>
</li>
<li>
<a href="#/interpolation-elixir-native">Elixir Native</a>
</li>
<li>
<a href="#/interpolation-jflex">JFlex</a>
</li>
</ul>
</section>
<section id="interpolation-interpolation">
<h1>Interpolation</h1>
<pre><code class="elixir strech" data-trim style="font-size: 195%; line-height: 100%">
iex> greeting = "Hello #{"W#{"or"}ld"}"
"Hello World"
iex> tuple = "A tuple #{inspect {"Containing an #{:interpolated} string"}}"
"A tuple {\"Containing an interpolated string\"}"
</code></pre>
<ul>
<li>
Starts with <code>#{</code> and ends with <code>}</code>
</li>
<li>
Valid in Char Lists, Strings, and (interpolating) Sigils
</li>
<li>
Recursive
</li>
</ul>
<aside class="notes">
<p>
Adding support for interpolation was tricky. At first glance the <code>#{</code> and
<code>}</code> that surround interpolation should work just like curly braces in a
language like C or Java, but the braces in C or Java can just be lexed and the parser
can decide about whether they are matched. In languages like Ruby or Elixir that
support interpolation, whether you're parsing fragments for the string, char list or
sigils or if you're in normal code needs to be tracked as fragments will be syntax
highlighted and parsed differently than normal code. Finally, code inside interpolation
can itself have strings, char lists, or sigils that also contain interpolation,
recursively.
</p>
<p>
This recursion means that a non-deterministic finite automaton as generated by JFlex
can't parse Elixir!
</p>
</aside>
</section>
<section id="interpolation-computational-hierarchy">
<h1>Computational Heirarchy</h1>
<table>
<thead>
<tr>
<th>Language Class</th>
<th>Computational Model</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Regular</td>
<td>Finite Automaton/State Machine</td>
<td>Multiples of 3 in binary</td>
</tr>
<tr>
<td>Context-Free</td>
<td>Pushdown Automaton</td>
<td>Balanced Parentheses</td>
</tr>
<tr>
<td>Decidable</td>
<td>(Always-halting) Turing machine</td>
<td><code>a<sup>n</sup>b<sup>n</sup>c<sup>n</sup></code></td>
</tr>
<tr>
<td>Semidecidable</td>
<td>Turing machine</td>
<td>Halting Problem</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Finite Automatons can lex regular languages, which are languages that match formal
regular expressions. Formal regular expression only allow pipe (<code>|</code>) for or,
parentheses (<code>()</code>) for grouping, and asterisk (<code>*</code>) for Kleene
star, which means zero or more. They also can have question mark (<code>?</code>) to
mean zero or one, if they can't use a symbol for no input, which would be lowercase
epsilon formally. Formal regular expressions are missing the extended regular
expression features like back references that would allow recursion.
</p>
<p>
Context-free languages are a step above regular expressions and can be lexed by pushdown
automatons, which have a stack for keeping track of state. A pushdown automaton can use
the current state along with the current input to decide whether parentheses are matched
by pushing opening parentheses onto a stack and popping on closing parentheses. If
you try to pop when the stack is empty, then you have an unmatched closing parenthesis
and if the string ends with a non-empty stack then you have an unmatched opening
parenthesis.
</p>
<p>
When writing compilers and IDEs, designers have to care about the computational
hierarchy because performance guarantees get fuzzy and get more complex until you hit
semidecidable and Turing machines, which may just spin forever on bad input.
</p>
</aside>
</section>
<section id="interpolation-elixir-native">
<h1>Elixir Native Interpolation</h1>
<figure>
<figcaption>
<a href="https://github.com/elixir-lang/elixir/blob/v0.14.3/lib/elixir/src/elixir_tokenizer.erl#L234-L529">
<code>lib/elixir/src/elixir_tokenizer.erl</code>
</a>
</figcaption>
<pre><code class="erlang stretch" data-trim style="font-size: 140%; line-height: 100%">
tokenize([$"|T], Line, Scope, Tokens) ->
handle_strings(T, Line, $", Scope, Tokens);
tokenize([$'|T], Line, Scope, Tokens) ->
handle_strings(T, Line, $', Scope, Tokens);
handle_strings(T, Line, H, Scope, Tokens) ->
case elixir_interpolation:extract(Line, Scope, true, T, H) of
{error, Reason} ->
interpolation_error(Reason, [H|T], Tokens, " (for string starting at line ~B)", [Line]);
{NewLine, Parts, [$:|Rest]} when ?is_space(hd(Rest)) ->
Unescaped = unescape_tokens(Parts),
Key = case Scope#elixir_tokenizer.existing_atoms_only of
true -> kw_identifier_safe;
false -> kw_identifier_unsafe
end,
tokenize(Rest, NewLine, Scope, [{Key, Line, Unescaped}|Tokens]);
{NewLine, Parts, Rest} ->
Token = {string_type(H), Line, unescape_tokens(Parts)},
tokenize(Rest, NewLine, Scope, [Token|Tokens])
end.
</code></pre>
</figure>
<figure>
<figcaption>
<a href="https://github.com/elixir-lang/elixir/blob/v0.14.3/lib/elixir/src/elixir_interpolation.erl#L39-L50">
<code>lib/elixir/src/elixir_interpolation.erl</code>