Skip to content

Commit b4939ce

Browse files
jneenjneen
andauthored
Moonscript: add from keyword (#2233)
* moonscript: use a lazy { ... } block instead of overriding eager_load! * moonscript: add the `from` keyword * remove ident string (?) which was just \w+ anyways * use more standard ruby regex features --------- Co-authored-by: jneen <jneen@jneen.net>
1 parent 56751d2 commit b4939ce

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/rouge/lexers/moonscript.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ class Moonscript < RegexLexer
1717
option :disabled_modules, 'builtin modules to disable'
1818

1919
# depends on lua builtins
20-
def self.eager_load!
21-
super
22-
Lua.eager_load!
23-
end
20+
lazy { Lua.eager_load! }
2421

2522
def initialize(*)
2623
super
@@ -50,31 +47,29 @@ def builtins
5047
end
5148

5249
state :base do
53-
ident = '(?:\w\w*)'
54-
55-
rule %r((?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?'), Num::Float
56-
rule %r((?i)\d+e[+-]?\d+), Num::Float
57-
rule %r((?i)0x[0-9a-f]*), Num::Hex
50+
rule %r((\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?')i, Num::Float
51+
rule %r(\d+e[+-]?\d+)i, Num::Float
52+
rule %r(0x\h*), Num::Hex
5853
rule %r(\d+), Num::Integer
59-
rule %r(@#{ident}*), Name::Variable::Instance
54+
rule %r(@\w+), Name::Variable::Instance
6055
rule %r([A-Z]\w*), Name::Class
6156
rule %r("?[^"]+":), Literal::String::Symbol
62-
rule %r(#{ident}:), Literal::String::Symbol
63-
rule %r(:#{ident}), Literal::String::Symbol
57+
rule %r(\w+:), Literal::String::Symbol
58+
rule %r(:\w+), Literal::String::Symbol
6459

6560
rule %r(\s+), Text::Whitespace
6661
rule %r((==|~=|!=|<=|>=|\.\.\.|\.\.|->|=>|[=+\-*/%^<>#!\\])), Operator
6762
rule %r([\[\]\{\}\(\)\.,:;]), Punctuation
6863
rule %r((and|or|not)\b), Operator::Word
6964

7065
keywords = Set.new %w{
71-
break class continue do else elseif end extends for if import in
66+
break class continue do else elseif end extends for if import in from
7267
repeat return switch super then unless until using when with while
7368
}
7469
rule %r((local|export)\b), Keyword::Declaration
7570
rule %r((true|false|nil)\b), Keyword::Constant
7671

77-
rule %r([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?) do |m|
72+
rule %r([a-z_]\w*(\.[a-z_]\w*)?)i do |m|
7873
name = m[0]
7974
if keywords.include?(name)
8075
token Keyword

0 commit comments

Comments
 (0)