Skip to content

Commit 05af54c

Browse files
author
jneen
committed
use the keywords api for cython
1 parent 569865f commit 05af54c

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

lib/rouge/lexers/cython.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,12 @@ def self.builtins
7474

7575
# This rule matches identifiers that could be type declarations. The
7676
# lookahead matches (1) pointers, (2) arrays and (3) variable names.
77-
rule %r/#{identifier}(?=(?:\*+)|(?:[ \t]*\[)|(?:[ \t]+\w))/ do |m|
78-
if self.class.keywords.include?(m[0])
79-
token Keyword
80-
pop!
81-
elsif m[0] == 'def'
82-
token Keyword
83-
goto :funcname
84-
elsif %w(struct class).include?(m[0])
85-
token Keyword
86-
goto :classname
87-
elsif self.class.c_keywords.include?(m[0])
88-
token Keyword::Reserved
89-
else
90-
token Keyword::Type
91-
pop!
92-
end
77+
keywords %r/#{identifier}(?=(?:\*+)|(?:[ \t]*\[)|(?:[ \t]+\w))/ do |m|
78+
rule :keywords, Keyword, :pop!
79+
rule(Set['def']) { token Keyword; goto :funcname }
80+
rule(Set['struct', 'class']) { token Keyword::Reserved; goto :classname }
81+
rule :c_keywords, Keyword::Reserved
82+
default Keyword::Type, :pop!
9383
end
9484

9585
rule(//) { pop! }

0 commit comments

Comments
 (0)