Skip to content

Commit

Permalink
Add operators, keywords and reserved words to CoffeeScript lexer (#1061)
Browse files Browse the repository at this point in the history
This commit:

- adds missing keywords: `until`, `loop`, `do`, `yield` (old ones),
   `debugger` (an obscure one inhereted from JavaScript), and
   `await`, `import`, `export` (added in CoffeeScript 2);
- adds missing reserved words based on the RESERVED list in CoffeeScript 
   source code (see https://coffeescript.org/annotated-source/lexer.html#constants); and
- makes `in` and `of` into operators.
  • Loading branch information
edemaine authored and pyrmont committed May 28, 2019
1 parent 9e29a54 commit 4ca2e67
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/rouge/lexers/coffeescript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ def self.detect?(text)

def self.keywords
@keywords ||= Set.new %w(
for in of while break return continue switch when then if else
throw try catch finally new delete typeof instanceof super
extends this class by
for by while until loop break continue return
switch when then if else do yield throw try catch finally await
new delete typeof instanceof super extends this class
import export debugger
)
end

def self.reserved
@reserved ||= Set.new %w(
case function var void with const let enum
native implements interface package private protected public static
)
end

Expand Down Expand Up @@ -77,8 +85,8 @@ def self.builtins
rule(%r(^(?=\s|/|<!--))) { push :slash_starts_regex }
mixin :comments_and_whitespace
rule %r(
[+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
[|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
[+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\bin\b|\bof\b|
[?]|:|=|[|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
)x, Operator, :slash_starts_regex

rule /[-=]>/, Name::Function
Expand Down

0 comments on commit 4ca2e67

Please sign in to comment.