Skip to content

Commit

Permalink
Fix(pony): highlighting errors and remove two modes (#1979)
Browse files Browse the repository at this point in the history
Fixes a few highlighting bugs such as keyword lists not having spaces at
the end causing the last keyword of one line and the first keyword of
the next to be combined. Also fixed highlighting of `iso` in class
definitions and function heads without bodies in traits and interfaces.

This also removes the FUNCTION and CLASS modes until there is a more
clear benefit to using them. In a couple cases such as an interface
with multiple function heads without an `=>` indicating a body they
broke the highlighting of the second function head.
  • Loading branch information
gregcline authored and marcoscaceres committed Feb 24, 2019
1 parent 5290313 commit dbe4ffa
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 51 deletions.
1 change: 1 addition & 0 deletions AUTHORS.en.txt
Expand Up @@ -274,3 +274,4 @@ Contributors:
- Alejandro Isaza <al@isaza.ca> - Alejandro Isaza <al@isaza.ca>
- Laurent Voullemier <laurent.voullemier@gmail.com> - Laurent Voullemier <laurent.voullemier@gmail.com>
- Sean T. Allen <sean@monkeysnatchbanana.com> - Sean T. Allen <sean@monkeysnatchbanana.com>
- Greg Cline <gregrcline@gmail.com>
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ New languages:
New styles: New styles:


Improvements: Improvements:
- Pony: Fixed keywords without spaces at line ends, highlighting of `iso` in class definitions, and function heads without bodies in traits and interfaces. Removed FUNCTION and CLASS modes until they are found to be needed and to provide some of the fixes.


## Version 9.14.3 ## Version 9.14.3
New languages: New languages:
Expand Down
53 changes: 13 additions & 40 deletions src/languages/pony.js
Expand Up @@ -8,9 +8,9 @@ Description: Pony is an open-source, object-oriented, actor-model,
function(hljs) { function(hljs) {
var KEYWORDS = { var KEYWORDS = {
keyword: keyword:
'actor addressof and as be break class compile_error compile_intrinsic' + 'actor addressof and as be break class compile_error compile_intrinsic ' +
'consume continue delegate digestof do else elseif embed end error' + 'consume continue delegate digestof do else elseif embed end error ' +
'for fun if ifdef in interface is isnt lambda let match new not object' + 'for fun if ifdef in interface is isnt lambda let match new not object ' +
'or primitive recover repeat return struct then trait try type until ' + 'or primitive recover repeat return struct then trait try type until ' +
'use var where while with xor', 'use var where while with xor',
meta: meta:
Expand Down Expand Up @@ -48,47 +48,20 @@ function(hljs) {
begin: hljs.IDENT_RE + '\'', relevance: 0 begin: hljs.IDENT_RE + '\'', relevance: 0
}; };


var CLASS = { /**
className: 'class', * The `FUNCTION` and `CLASS` modes were intentionally removed to simplify
beginKeywords: 'class actor object primitive', end: '$', * highlighting and fix cases like
contains: [ * ```
{ * interface Iterator[A: A]
className: 'keyword', * fun has_next(): Bool
begin: 'is' * fun next(): A?
}, * ```
TYPE_NAME, * where it is valid to have a function head without a body
hljs.TITLE_MODE, */
hljs.C_LINE_COMMENT_MODE
]
}

var FUNCTION = {
className: 'function',
beginKeywords: 'new fun be', end: '=>',
contains: [
hljs.TITLE_MODE,
{
begin: /\(/, end: /\)/,
contains: [
TYPE_NAME,
PRIMED_NAME,
hljs.C_NUMBER_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
},
{
begin: /:/, endsWithParent: true,
contains: [TYPE_NAME]
},
hljs.C_LINE_COMMENT_MODE
]
}


return { return {
keywords: KEYWORDS, keywords: KEYWORDS,
contains: [ contains: [
CLASS,
FUNCTION,
TYPE_NAME, TYPE_NAME,
TRIPLE_QUOTE_STRING_MODE, TRIPLE_QUOTE_STRING_MODE,
QUOTE_STRING_MODE, QUOTE_STRING_MODE,
Expand Down
21 changes: 21 additions & 0 deletions test/markup/pony/control-flow.expect.txt
@@ -0,0 +1,21 @@
<span class="hljs-keyword">if</span> a == b <span class="hljs-keyword">and</span> b == a <span class="hljs-keyword">then</span>
env.out.print(<span class="hljs-string">"they are the same"</span>)
<span class="hljs-keyword">elseif</span> a &gt; b <span class="hljs-keyword">or</span> b &lt; a <span class="hljs-keyword">then</span>
env.out.print(<span class="hljs-string">"a is bigger"</span>)
<span class="hljs-keyword">else</span>
env.out.print(<span class="hljs-string">"b bigger"</span>)
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">while</span> count &lt;= <span class="hljs-number">10</span> <span class="hljs-keyword">do</span>
env.out.print(count.string())
count = count + <span class="hljs-number">1</span>
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> [<span class="hljs-string">"Bob"</span>; <span class="hljs-string">"Fred"</span>; <span class="hljs-string">"Sarah"</span>].values() <span class="hljs-keyword">do</span>
env.out.print(name)
<span class="hljs-keyword">end</span>

<span class="hljs-keyword">repeat</span>
env.out.print(<span class="hljs-string">"hello!"</span>)
counter = counter + <span class="hljs-number">1</span>
<span class="hljs-keyword">until</span> counter &gt; <span class="hljs-number">7</span> <span class="hljs-keyword">end</span>
21 changes: 21 additions & 0 deletions test/markup/pony/control-flow.txt
@@ -0,0 +1,21 @@
if a == b and b == a then
env.out.print("they are the same")
elseif a > b or b < a then
env.out.print("a is bigger")
else
env.out.print("b bigger")
end

while count <= 10 do
env.out.print(count.string())
count = count + 1
end

for name in ["Bob"; "Fred"; "Sarah"].values() do
env.out.print(name)
end

repeat
env.out.print("hello!")
counter = counter + 1
until counter > 7 end
2 changes: 1 addition & 1 deletion test/markup/pony/creator.expect.txt
@@ -1,3 +1,3 @@
<span class="hljs-function"><span class="hljs-keyword">new</span> <span class="hljs-title">create</span>(env: <span class="hljs-type">Env</span>, name: <span class="hljs-type">String</span>) =&gt;</span> <span class="hljs-keyword">new</span> create(env: <span class="hljs-type">Env</span>, name: <span class="hljs-type">String</span>) =&gt;
_env = env _env = env
_name = name _name = name
9 changes: 9 additions & 0 deletions test/markup/pony/iterface-trait.expect.txt
@@ -0,0 +1,9 @@
<span class="hljs-keyword">interface</span> <span class="hljs-type">Iterator</span>[<span class="hljs-type">A</span>: <span class="hljs-type">A</span>]
<span class="hljs-keyword">fun</span> has_next(): <span class="hljs-type">Bool</span>
<span class="hljs-keyword">fun</span> next(): <span class="hljs-type">T</span>?

<span class="hljs-keyword">trait</span> <span class="hljs-type">UnitTest</span>
<span class="hljs-keyword">fun</span> name(): <span class="hljs-type">String</span>
<span class="hljs-keyword">fun</span> <span class="hljs-meta">ref</span> set_up(h: <span class="hljs-type">TestHelper</span>) ? =&gt;
<span class="hljs-type">None</span>
<span class="hljs-keyword">fun</span> apply(h: <span class="hljs-type">TestHelper</span>) ?
9 changes: 9 additions & 0 deletions test/markup/pony/iterface-trait.txt
@@ -0,0 +1,9 @@
interface Iterator[A: A]
fun has_next(): Bool
fun next(): T?

trait UnitTest
fun name(): String
fun ref set_up(h: TestHelper) ? =>
None
fun apply(h: TestHelper) ?
6 changes: 3 additions & 3 deletions test/markup/pony/method.expect.txt
@@ -1,8 +1,8 @@
<span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">foo</span>(bar: <span class="hljs-type">String</span>): <span class="hljs-type">String</span> =&gt;</span> <span class="hljs-keyword">fun</span> foo(bar: <span class="hljs-type">String</span>): <span class="hljs-type">String</span> =&gt;
bar + <span class="hljs-string">"baz"</span> bar + <span class="hljs-string">"baz"</span>


<span class="hljs-function"><span class="hljs-keyword">new</span> <span class="hljs-title">create</span>(hunger: <span class="hljs-type">I32</span>) =&gt;</span> <span class="hljs-keyword">new</span> create(hunger: <span class="hljs-type">I32</span>) =&gt;
_hunger = hunger _hunger = hunger


<span class="hljs-function"><span class="hljs-keyword">be</span> <span class="hljs-title">feed</span>(food: <span class="hljs-type">I32</span>) =&gt;</span> <span class="hljs-keyword">be</span> feed(food: <span class="hljs-type">I32</span>) =&gt;
_hunger = _hunger - food _hunger = _hunger - food
12 changes: 8 additions & 4 deletions test/markup/pony/objects.expect.txt
@@ -1,7 +1,11 @@
<span class="hljs-class"><span class="hljs-keyword">primitive</span> <span class="hljs-type">I32</span> <span class="hljs-keyword">is</span> <span class="hljs-type">SignedInteger</span></span> <span class="hljs-keyword">primitive</span> <span class="hljs-type">I32</span> <span class="hljs-keyword">is</span> <span class="hljs-type">SignedInteger</span>


<span class="hljs-class"><span class="hljs-keyword">actor</span> <span class="hljs-type">Main</span></span> <span class="hljs-keyword">actor</span> <span class="hljs-type">Main</span>


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ref</span> <span class="hljs-type">List</span>[<span class="hljs-type">A</span>: <span class="hljs-type">A</span>] <span class="hljs-keyword">is</span> <span class="hljs-type">Seq</span>[<span class="hljs-type">A</span>] <span class="hljs-title">ref</span></span> <span class="hljs-keyword">class</span> <span class="hljs-meta">ref</span> <span class="hljs-type">List</span>[<span class="hljs-type">A</span>: <span class="hljs-type">A</span>] <span class="hljs-keyword">is</span> <span class="hljs-type">Seq</span>[<span class="hljs-type">A</span>] <span class="hljs-meta">ref</span>


<span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-keyword">is</span> <span class="hljs-type">Hashable</span></span> <span class="hljs-keyword">object</span> <span class="hljs-keyword">is</span> <span class="hljs-type">Hashable</span>

<span class="hljs-keyword">object</span> <span class="hljs-meta">iso</span>

<span class="hljs-keyword">primitive</span> <span class="hljs-type">Foo</span> <span class="hljs-keyword">is</span> <span class="hljs-type">Bar</span> <span class="hljs-meta">iso</span>
6 changes: 5 additions & 1 deletion test/markup/pony/objects.txt
Expand Up @@ -4,4 +4,8 @@ actor Main


class ref List[A: A] is Seq[A] ref class ref List[A: A] is Seq[A] ref


object is Hashable object is Hashable

object iso

primitive Foo is Bar iso
4 changes: 2 additions & 2 deletions test/markup/pony/prime.expect.txt
@@ -1,2 +1,2 @@
<span class="hljs-function"><span class="hljs-keyword">new</span> <span class="hljs-title">create</span>(name': <span class="hljs-type">String</span>) =&gt;</span> <span class="hljs-keyword">new</span> create(name': <span class="hljs-type">String</span>) =&gt;
name = name' + <span class="hljs-string">'a'</span> name = name' + <span class="hljs-string">'a'</span>

0 comments on commit dbe4ffa

Please sign in to comment.