rouge 4.6.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +11 -4
- data/bin/rougify +3 -4
- data/lib/rouge/cli.rb +7 -10
- data/lib/rouge/demos/abap +30 -4
- data/lib/rouge/demos/dylan +8 -0
- data/lib/rouge/demos/gjs +23 -0
- data/lib/rouge/demos/gts +36 -0
- data/lib/rouge/demos/kick_assembler +14 -0
- data/lib/rouge/demos/pdf +29 -0
- data/lib/rouge/demos/thrift +15 -0
- data/lib/rouge/demos/veryl +24 -0
- data/lib/rouge/eager.rb +3 -0
- data/lib/rouge/formatters/html.rb +8 -1
- data/lib/rouge/formatters/html_debug.rb +16 -0
- data/lib/rouge/formatters/html_legacy.rb +15 -1
- data/lib/rouge/formatters/html_legacy_table.rb +57 -0
- data/lib/rouge/formatters/html_line_highlighter.rb +11 -4
- data/lib/rouge/formatters/html_line_table.rb +8 -3
- data/lib/rouge/formatters/html_linewise.rb +11 -2
- data/lib/rouge/formatters/html_pygments.rb +6 -1
- data/lib/rouge/formatters/html_table.rb +47 -21
- data/lib/rouge/formatters/terminal256.rb +3 -3
- data/lib/rouge/formatters/tex.rb +1 -1
- data/lib/rouge/guesser.rb +1 -1
- data/lib/rouge/guessers/disambiguation.rb +2 -2
- data/lib/rouge/guessers/glob_mapping.rb +2 -2
- data/lib/rouge/guessers/modeline.rb +2 -2
- data/lib/rouge/lexer.rb +40 -21
- data/lib/rouge/lexers/abap/builtins.rb +187 -0
- data/lib/rouge/lexers/abap.rb +70 -178
- data/lib/rouge/lexers/ada.rb +1 -1
- data/lib/rouge/lexers/apache/keywords.rb +3 -11
- data/lib/rouge/lexers/apache.rb +25 -24
- data/lib/rouge/lexers/apex.rb +2 -2
- data/lib/rouge/lexers/apiblueprint.rb +2 -2
- data/lib/rouge/lexers/bicep.rb +2 -2
- data/lib/rouge/lexers/biml.rb +36 -9
- data/lib/rouge/lexers/brightscript.rb +3 -4
- data/lib/rouge/lexers/c.rb +9 -5
- data/lib/rouge/lexers/cobol.rb +1 -1
- data/lib/rouge/lexers/console.rb +11 -5
- data/lib/rouge/lexers/cpp.rb +10 -12
- data/lib/rouge/lexers/crystal.rb +1 -1
- data/lib/rouge/lexers/css.rb +21 -2
- data/lib/rouge/lexers/cuda.rb +4 -4
- data/lib/rouge/lexers/cython.rb +26 -50
- data/lib/rouge/lexers/dafny.rb +1 -1
- data/lib/rouge/lexers/dart.rb +2 -0
- data/lib/rouge/lexers/datastudio.rb +1 -1
- data/lib/rouge/lexers/digdag.rb +2 -3
- data/lib/rouge/lexers/dylan.rb +109 -0
- data/lib/rouge/lexers/ecl.rb +3 -3
- data/lib/rouge/lexers/elixir.rb +14 -9
- data/lib/rouge/lexers/escape.rb +1 -1
- data/lib/rouge/lexers/factor.rb +1 -1
- data/lib/rouge/lexers/freefem.rb +2 -2
- data/lib/rouge/lexers/ghc_cmm.rb +1 -1
- data/lib/rouge/lexers/ghc_core.rb +1 -1
- data/lib/rouge/lexers/gherkin/keywords.rb +10 -6
- data/lib/rouge/lexers/gherkin.rb +28 -26
- data/lib/rouge/lexers/gjs.rb +39 -0
- data/lib/rouge/lexers/glsl/builtins.rb +17 -0
- data/lib/rouge/lexers/glsl.rb +50 -113
- data/lib/rouge/lexers/go.rb +8 -6
- data/lib/rouge/lexers/gradle.rb +2 -2
- data/lib/rouge/lexers/groovy.rb +6 -0
- data/lib/rouge/lexers/gts.rb +39 -0
- data/lib/rouge/lexers/hack.rb +4 -6
- data/lib/rouge/lexers/haxe.rb +2 -2
- data/lib/rouge/lexers/hlsl.rb +6 -6
- data/lib/rouge/lexers/hocon.rb +2 -2
- data/lib/rouge/lexers/hql.rb +15 -19
- data/lib/rouge/lexers/idris.rb +1 -1
- data/lib/rouge/lexers/igorpro/builtins.rb +1530 -0
- data/lib/rouge/lexers/igorpro.rb +49 -520
- data/lib/rouge/lexers/irb.rb +3 -3
- data/lib/rouge/lexers/isbl.rb +7 -43
- data/lib/rouge/lexers/j.rb +1 -1
- data/lib/rouge/lexers/json5.rb +2 -2
- data/lib/rouge/lexers/json_doc.rb +2 -2
- data/lib/rouge/lexers/jsp.rb +119 -119
- data/lib/rouge/lexers/jsx.rb +2 -2
- data/lib/rouge/lexers/kick_assembler.rb +100 -0
- data/lib/rouge/lexers/kotlin.rb +5 -0
- data/lib/rouge/lexers/lasso/keywords.rb +6 -6
- data/lib/rouge/lexers/lasso.rb +9 -11
- data/lib/rouge/lexers/liquid.rb +5 -6
- data/lib/rouge/lexers/llvm/keywords.rb +3 -12
- data/lib/rouge/lexers/llvm.rb +5 -16
- data/lib/rouge/lexers/lua/keywords.rb +11 -13
- data/lib/rouge/lexers/lua.rb +8 -7
- data/lib/rouge/lexers/lutin.rb +5 -4
- data/lib/rouge/lexers/m68k.rb +3 -3
- data/lib/rouge/lexers/mason.rb +110 -110
- data/lib/rouge/lexers/mathematica/keywords.rb +1 -3
- data/lib/rouge/lexers/mathematica.rb +6 -7
- data/lib/rouge/lexers/matlab/keywords.rb +2 -2
- data/lib/rouge/lexers/matlab.rb +5 -5
- data/lib/rouge/lexers/meson.rb +1 -1
- data/lib/rouge/lexers/mojo.rb +6 -2
- data/lib/rouge/lexers/moonscript.rb +19 -17
- data/lib/rouge/lexers/nesasm.rb +6 -6
- data/lib/rouge/lexers/nial.rb +7 -8
- data/lib/rouge/lexers/nim.rb +3 -3
- data/lib/rouge/lexers/nix.rb +10 -8
- data/lib/rouge/lexers/objective_c.rb +3 -3
- data/lib/rouge/lexers/objective_cpp.rb +3 -2
- data/lib/rouge/lexers/ocaml.rb +2 -2
- data/lib/rouge/lexers/openedge.rb +9 -9
- data/lib/rouge/lexers/pdf.rb +109 -0
- data/lib/rouge/lexers/php/keywords.rb +136 -188
- data/lib/rouge/lexers/php.rb +100 -11
- data/lib/rouge/lexers/plsql.rb +8 -9
- data/lib/rouge/lexers/postscript.rb +1 -1
- data/lib/rouge/lexers/powershell.rb +1 -1
- data/lib/rouge/lexers/python.rb +111 -66
- data/lib/rouge/lexers/qml.rb +2 -2
- data/lib/rouge/lexers/reasonml.rb +2 -2
- data/lib/rouge/lexers/rego.rb +53 -53
- data/lib/rouge/lexers/rescript.rb +2 -2
- data/lib/rouge/lexers/robot_framework.rb +12 -12
- data/lib/rouge/lexers/{coq.rb → rocq.rb} +15 -6
- data/lib/rouge/lexers/ruby.rb +33 -7
- data/lib/rouge/lexers/rust.rb +1 -0
- data/lib/rouge/lexers/sas.rb +164 -165
- data/lib/rouge/lexers/sass/common.rb +1 -1
- data/lib/rouge/lexers/sass.rb +2 -2
- data/lib/rouge/lexers/scss.rb +2 -2
- data/lib/rouge/lexers/sed.rb +1 -1
- data/lib/rouge/lexers/shell.rb +5 -5
- data/lib/rouge/lexers/slice.rb +2 -2
- data/lib/rouge/lexers/sparql.rb +1 -1
- data/lib/rouge/lexers/sqf/keywords.rb +5 -3
- data/lib/rouge/lexers/sqf.rb +3 -4
- data/lib/rouge/lexers/stan.rb +9 -15
- data/lib/rouge/lexers/svelte.rb +2 -2
- data/lib/rouge/lexers/swift.rb +2 -2
- data/lib/rouge/lexers/tcl.rb +1 -1
- data/lib/rouge/lexers/terraform.rb +3 -3
- data/lib/rouge/lexers/thrift.rb +120 -0
- data/lib/rouge/lexers/tsx.rb +3 -3
- data/lib/rouge/lexers/ttcn3.rb +1 -1
- data/lib/rouge/lexers/twig.rb +2 -2
- data/lib/rouge/lexers/typescript.rb +3 -3
- data/lib/rouge/lexers/varnish.rb +8 -8
- data/lib/rouge/lexers/veryl.rb +109 -0
- data/lib/rouge/lexers/viml/keywords.rb +5 -7
- data/lib/rouge/lexers/viml.rb +8 -10
- data/lib/rouge/lexers/vue.rb +2 -2
- data/lib/rouge/lexers/xquery.rb +2 -1
- data/lib/rouge/lexers/yaml.rb +13 -1
- data/lib/rouge/lexers/yang.rb +42 -74
- data/lib/rouge/lexers/zig.rb +10 -10
- data/lib/rouge/plugins/redcarpet.rb +3 -2
- data/lib/rouge/regex_lexer.rb +25 -14
- data/lib/rouge/themes/gruvbox.rb +3 -0
- data/lib/rouge/token.rb +1 -1
- data/lib/rouge/util.rb +1 -1
- data/lib/rouge/version.rb +1 -1
- data/lib/rouge.rb +70 -59
- data/lib/rubocop/cop/rouge/no_building_alternation_pattern_in_regexp.rb +71 -0
- data/lib/rubocop/cop/rouge/no_huge_collections.rb +37 -0
- data/rouge.gemspec +8 -5
- metadata +44 -9
- data/lib/rouge/lexers/isbl/builtins.rb +0 -17
- data/lib/rouge/lexers/matlab/builtins.rb +0 -11
- /data/lib/rouge/demos/{coq → rocq} +0 -0
|
@@ -9,19 +9,17 @@
|
|
|
9
9
|
module Rouge
|
|
10
10
|
module Lexers
|
|
11
11
|
class Lua
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
b["utf8"] = Set.new ["utf8.char", "utf8.charpattern", "utf8.codepoint", "utf8.codes", "utf8.len", "utf8.offset"]
|
|
24
|
-
end
|
|
12
|
+
BUILTINS = {}.tap do |b|
|
|
13
|
+
b["basic"] = Set["_g", "_version", "assert", "collectgarbage", "dofile", "error", "file:close", "file:flush", "file:lines", "file:read", "file:seek", "file:setvbuf", "file:write", "getmetatable", "ipairs", "load", "loadfile", "lua_cpath", "lua_cpath_5_3", "lua_errerr", "lua_errfile", "lua_errgcmm", "lua_errmem", "lua_errrun", "lua_errsyntax", "lua_hookcall", "lua_hookcount", "lua_hookline", "lua_hookret", "lua_hooktailcall", "lua_init", "lua_init_5_3", "lua_maskcall", "lua_maskcount", "lua_maskline", "lua_maskret", "lua_maxinteger", "lua_mininteger", "lua_minstack", "lua_multret", "lua_noref", "lua_ok", "lua_opadd", "lua_opband", "lua_opbnot", "lua_opbor", "lua_opbxor", "lua_opdiv", "lua_opeq", "lua_opidiv", "lua_ople", "lua_oplt", "lua_opmod", "lua_opmul", "lua_oppow", "lua_opshl", "lua_opshr", "lua_opsub", "lua_opunm", "lua_path", "lua_path_5_3", "lua_refnil", "lua_registryindex", "lua_ridx_globals", "lua_ridx_mainthread", "lua_tboolean", "lua_tfunction", "lua_tlightuserdata", "lua_tnil", "lua_tnone", "lua_tnumber", "lua_tstring", "lua_ttable", "lua_tthread", "lua_tuserdata", "lua_use_apicheck", "lua_yield", "lual_buffersize", "luaopen_base", "luaopen_coroutine", "luaopen_debug", "luaopen_io", "luaopen_math", "luaopen_os", "luaopen_package", "luaopen_string", "luaopen_table", "luaopen_utf8", "next", "pairs", "pcall", "print", "rawequal", "rawget", "rawlen", "rawset", "select", "setmetatable", "tonumber", "tostring", "type", "xpcall"]
|
|
14
|
+
b["modules"] = Set["package.config", "package.cpath", "package.loaded", "package.loadlib", "package.path", "package.preload", "package.searchers", "package.searchpath", "require"]
|
|
15
|
+
b["coroutine"] = Set["coroutine.create", "coroutine.isyieldable", "coroutine.resume", "coroutine.running", "coroutine.status", "coroutine.wrap", "coroutine.yield"]
|
|
16
|
+
b["debug"] = Set["debug.debug", "debug.gethook", "debug.getinfo", "debug.getlocal", "debug.getmetatable", "debug.getregistry", "debug.getupvalue", "debug.getuservalue", "debug.sethook", "debug.setlocal", "debug.setmetatable", "debug.setupvalue", "debug.setuservalue", "debug.traceback", "debug.upvalueid", "debug.upvaluejoin"]
|
|
17
|
+
b["io"] = Set["io.close", "io.flush", "io.input", "io.lines", "io.open", "io.output", "io.popen", "io.read", "io.stderr", "io.stdin", "io.stdout", "io.tmpfile", "io.type", "io.write"]
|
|
18
|
+
b["math"] = Set["math.abs", "math.acos", "math.asin", "math.atan", "math.ceil", "math.cos", "math.deg", "math.exp", "math.floor", "math.fmod", "math.huge", "math.log", "math.max", "math.maxinteger", "math.min", "math.mininteger", "math.modf", "math.pi", "math.rad", "math.random", "math.randomseed", "math.sin", "math.sqrt", "math.tan", "math.tointeger", "math.type", "math.ult"]
|
|
19
|
+
b["os"] = Set["os.clock", "os.date", "os.difftime", "os.execute", "os.exit", "os.getenv", "os.remove", "os.rename", "os.setlocale", "os.time", "os.tmpname"]
|
|
20
|
+
b["string"] = Set["string.byte", "string.char", "string.dump", "string.find", "string.format", "string.gmatch", "string.gsub", "string.len", "string.lower", "string.match", "string.pack", "string.packsize", "string.rep", "string.reverse", "string.sub", "string.unpack", "string.upper"]
|
|
21
|
+
b["table"] = Set["table.concat", "table.insert", "table.move", "table.pack", "table.remove", "table.sort", "table.unpack"]
|
|
22
|
+
b["utf8"] = Set["utf8.char", "utf8.charpattern", "utf8.codepoint", "utf8.codes", "utf8.len", "utf8.offset"]
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
end
|
data/lib/rouge/lexers/lua.rb
CHANGED
|
@@ -14,26 +14,27 @@ module Rouge
|
|
|
14
14
|
option :function_highlighting, 'Whether to highlight builtin functions (default: true)'
|
|
15
15
|
option :disabled_modules, 'builtin modules to disable'
|
|
16
16
|
|
|
17
|
+
lazy auto: false do
|
|
18
|
+
require_relative 'lua/keywords'
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
def initialize(opts={})
|
|
18
22
|
@function_highlighting = opts.delete(:function_highlighting) { true }
|
|
19
23
|
@disabled_modules = opts.delete(:disabled_modules) { [] }
|
|
20
24
|
super(opts)
|
|
25
|
+
|
|
26
|
+
self.class.eager_load! if @function_highlighting
|
|
21
27
|
end
|
|
22
28
|
|
|
23
29
|
def self.detect?(text)
|
|
24
30
|
return true if text.shebang? 'lua'
|
|
25
31
|
end
|
|
26
32
|
|
|
27
|
-
def self.builtins
|
|
28
|
-
Kernel::load File.join(Lexers::BASE_DIR, 'lua/keywords.rb')
|
|
29
|
-
builtins
|
|
30
|
-
end
|
|
31
|
-
|
|
32
33
|
def builtins
|
|
33
34
|
return [] unless @function_highlighting
|
|
34
35
|
|
|
35
36
|
@builtins ||= Set.new.tap do |builtins|
|
|
36
|
-
|
|
37
|
+
BUILTINS.each do |mod, fns|
|
|
37
38
|
next if @disabled_modules.include? mod
|
|
38
39
|
builtins.merge(fns)
|
|
39
40
|
end
|
|
@@ -77,7 +78,7 @@ module Rouge
|
|
|
77
78
|
push :gsub
|
|
78
79
|
elsif self.builtins.include?(name)
|
|
79
80
|
token Name::Builtin
|
|
80
|
-
elsif name
|
|
81
|
+
elsif name.include?('.')
|
|
81
82
|
a, b = name.split('.', 2)
|
|
82
83
|
token Name, a
|
|
83
84
|
token Punctuation, '.'
|
data/lib/rouge/lexers/lutin.rb
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
#
|
|
4
4
|
# adapted from lustre.rf (adapted from ocaml.rb), hence some ocaml-ism migth remains
|
|
5
|
+
|
|
6
|
+
require_relative 'lustre'
|
|
7
|
+
|
|
5
8
|
module Rouge
|
|
6
9
|
module Lexers
|
|
7
|
-
load_lexer 'lustre.rb'
|
|
8
|
-
|
|
9
10
|
class Lutin < Lustre
|
|
10
11
|
title "Lutin"
|
|
11
12
|
desc 'The Lutin programming language (Verimag)'
|
|
@@ -16,13 +17,13 @@ module Rouge
|
|
|
16
17
|
def self.keywords
|
|
17
18
|
@keywords ||= Set.new %w(
|
|
18
19
|
let in node extern system returns weak strong assert raise try catch
|
|
19
|
-
trap do exist erun run type ref exception include false true
|
|
20
|
+
trap do exist erun run type ref exception include false true
|
|
20
21
|
)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def self.word_operators
|
|
24
25
|
@word_operators ||= Set.new %w(
|
|
25
|
-
div and xor mod or not nor if then else pre)
|
|
26
|
+
div and xor mod or not nor if then else pre)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def self.primitives
|
data/lib/rouge/lexers/m68k.rb
CHANGED
|
@@ -40,7 +40,7 @@ module Rouge
|
|
|
40
40
|
|
|
41
41
|
tas trap trapcc TODO trapv tst
|
|
42
42
|
|
|
43
|
-
unlk unpk
|
|
43
|
+
unlk unpk
|
|
44
44
|
)
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -55,10 +55,10 @@ module Rouge
|
|
|
55
55
|
include incdir incbin end endf endfunc endmain endproc fpu func machine main mmu opword proc set opt section
|
|
56
56
|
rept endr
|
|
57
57
|
ifeq ifne ifgt ifge iflt ifle iif ifd ifnd ifc ifnc elseif else endc
|
|
58
|
-
even cnop fail
|
|
58
|
+
even cnop fail
|
|
59
59
|
output radix __G2 __LK
|
|
60
60
|
list nolist plen llen ttl subttl spc page listchar format
|
|
61
|
-
equ equenv equr
|
|
61
|
+
equ equenv equr reg
|
|
62
62
|
rsreset rsset offset
|
|
63
63
|
cargs
|
|
64
64
|
fequ.s fequ.d fequ.x fequ.p fequ.w fequ.l fopt
|
data/lib/rouge/lexers/mason.rb
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*- #
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
module Rouge
|
|
5
|
-
module Lexers
|
|
6
|
-
class Mason < TemplateLexer
|
|
7
|
-
title 'Mason'
|
|
8
|
-
desc 'The HTML::Mason framework (https://metacpan.org/pod/HTML::Mason)'
|
|
9
|
-
tag 'mason'
|
|
10
|
-
filenames '*.mi', '*.mc', '*.mas', '*.m', '*.mhtml', '*.mcomp', 'autohandler', 'dhandler'
|
|
11
|
-
mimetypes 'text/x-mason', 'application/x-mason'
|
|
12
|
-
|
|
13
|
-
def initialize(*)
|
|
14
|
-
super
|
|
15
|
-
@perl = Perl.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
|
|
19
|
-
TEXT_BLOCKS = %w(text doc)
|
|
20
|
-
PERL_BLOCKS = %w(args flags attr init once shared perl cleanup filter)
|
|
21
|
-
COMPONENTS = %w(def method)
|
|
22
|
-
|
|
23
|
-
state :root do
|
|
24
|
-
mixin :mason_tags
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
state :mason_tags do
|
|
28
|
-
rule %r/\s+/, Text::Whitespace
|
|
29
|
-
|
|
30
|
-
rule %r/<%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :text_block
|
|
31
|
-
|
|
32
|
-
rule %r/<%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :perl_block
|
|
33
|
-
|
|
34
|
-
rule %r/(<%(#{COMPONENTS.join('|')}))([^>]*)(>)/oi do |m|
|
|
35
|
-
token Comment::Preproc, m[1]
|
|
36
|
-
token Name, m[3]
|
|
37
|
-
token Comment::Preproc, m[4]
|
|
38
|
-
push :component_block
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# perl line
|
|
42
|
-
rule %r/^(%)(.*)$/ do |m|
|
|
43
|
-
token Comment::Preproc, m[1]
|
|
44
|
-
delegate @perl, m[2]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# start of component call
|
|
48
|
-
rule %r/<%/, Comment::Preproc, :component_call
|
|
49
|
-
|
|
50
|
-
# start of component with content
|
|
51
|
-
rule %r/<&\|/ do
|
|
52
|
-
token Comment::Preproc
|
|
53
|
-
push :component_with_content
|
|
54
|
-
push :component_sub
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# start of component substitution
|
|
58
|
-
rule %r/<&/, Comment::Preproc, :component_sub
|
|
59
|
-
|
|
60
|
-
# fallback to HTML until a mason tag is encountered
|
|
61
|
-
rule(/(.+?)(?=(<\/?&|<\/?%|^%|^#))/m) { delegate parent }
|
|
62
|
-
|
|
63
|
-
# if we get here, there's no more mason tags, so we parse the rest of the doc as HTML
|
|
64
|
-
rule(/.+/m) { delegate parent }
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
state :perl_block do
|
|
68
|
-
rule %r/<\/%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
69
|
-
rule %r/\s+/, Text::Whitespace
|
|
70
|
-
rule %r/^(#.*)$/, Comment
|
|
71
|
-
rule(/(.*?[^"])(?=<\/%)/m) { delegate @perl }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
state :text_block do
|
|
75
|
-
rule %r/<\/%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
76
|
-
rule %r/\s+/, Text::Whitespace
|
|
77
|
-
rule %r/^(#.*)$/, Comment
|
|
78
|
-
rule %r/(.*?[^"])(?=<\/%)/m, Comment
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
state :component_block do
|
|
82
|
-
rule %r/<\/%(#{COMPONENTS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
83
|
-
rule %r/\s+/, Text::Whitespace
|
|
84
|
-
rule %r/^(#.*)$/, Comment
|
|
85
|
-
mixin :mason_tags
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
state :component_with_content do
|
|
89
|
-
rule %r/<\/&>/ do
|
|
90
|
-
token Comment::Preproc
|
|
91
|
-
pop!
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
mixin :mason_tags
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
state :component_sub do
|
|
98
|
-
rule %r/&>/, Comment::Preproc, :pop!
|
|
99
|
-
|
|
100
|
-
rule(/(.*?)(?=&>)/m) { delegate @perl }
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
state :component_call do
|
|
104
|
-
rule %r/%>/, Comment::Preproc, :pop!
|
|
105
|
-
|
|
106
|
-
rule(/(.*?)(?=%>)/m) { delegate @perl }
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Rouge
|
|
5
|
+
module Lexers
|
|
6
|
+
class Mason < TemplateLexer
|
|
7
|
+
title 'Mason'
|
|
8
|
+
desc 'The HTML::Mason framework (https://metacpan.org/pod/HTML::Mason)'
|
|
9
|
+
tag 'mason'
|
|
10
|
+
filenames '*.mi', '*.mc', '*.mas', '*.m', '*.mhtml', '*.mcomp', 'autohandler', 'dhandler'
|
|
11
|
+
mimetypes 'text/x-mason', 'application/x-mason'
|
|
12
|
+
|
|
13
|
+
def initialize(*)
|
|
14
|
+
super
|
|
15
|
+
@perl = Perl.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
|
|
19
|
+
TEXT_BLOCKS = %w(text doc)
|
|
20
|
+
PERL_BLOCKS = %w(args flags attr init once shared perl cleanup filter)
|
|
21
|
+
COMPONENTS = %w(def method)
|
|
22
|
+
|
|
23
|
+
state :root do
|
|
24
|
+
mixin :mason_tags
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
state :mason_tags do
|
|
28
|
+
rule %r/\s+/, Text::Whitespace
|
|
29
|
+
|
|
30
|
+
rule %r/<%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :text_block
|
|
31
|
+
|
|
32
|
+
rule %r/<%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :perl_block
|
|
33
|
+
|
|
34
|
+
rule %r/(<%(#{COMPONENTS.join('|')}))([^>]*)(>)/oi do |m|
|
|
35
|
+
token Comment::Preproc, m[1]
|
|
36
|
+
token Name, m[3]
|
|
37
|
+
token Comment::Preproc, m[4]
|
|
38
|
+
push :component_block
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# perl line
|
|
42
|
+
rule %r/^(%)(.*)$/ do |m|
|
|
43
|
+
token Comment::Preproc, m[1]
|
|
44
|
+
delegate @perl, m[2]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# start of component call
|
|
48
|
+
rule %r/<%/, Comment::Preproc, :component_call
|
|
49
|
+
|
|
50
|
+
# start of component with content
|
|
51
|
+
rule %r/<&\|/ do
|
|
52
|
+
token Comment::Preproc
|
|
53
|
+
push :component_with_content
|
|
54
|
+
push :component_sub
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# start of component substitution
|
|
58
|
+
rule %r/<&/, Comment::Preproc, :component_sub
|
|
59
|
+
|
|
60
|
+
# fallback to HTML until a mason tag is encountered
|
|
61
|
+
rule(/(.+?)(?=(<\/?&|<\/?%|^%|^#))/m) { delegate parent }
|
|
62
|
+
|
|
63
|
+
# if we get here, there's no more mason tags, so we parse the rest of the doc as HTML
|
|
64
|
+
rule(/.+/m) { delegate parent }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
state :perl_block do
|
|
68
|
+
rule %r/<\/%(#{PERL_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
69
|
+
rule %r/\s+/, Text::Whitespace
|
|
70
|
+
rule %r/^(#.*)$/, Comment
|
|
71
|
+
rule(/(.*?[^"])(?=<\/%)/m) { delegate @perl }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
state :text_block do
|
|
75
|
+
rule %r/<\/%(#{TEXT_BLOCKS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
76
|
+
rule %r/\s+/, Text::Whitespace
|
|
77
|
+
rule %r/^(#.*)$/, Comment
|
|
78
|
+
rule %r/(.*?[^"])(?=<\/%)/m, Comment
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
state :component_block do
|
|
82
|
+
rule %r/<\/%(#{COMPONENTS.join('|')})>/oi, Comment::Preproc, :pop!
|
|
83
|
+
rule %r/\s+/, Text::Whitespace
|
|
84
|
+
rule %r/^(#.*)$/, Comment
|
|
85
|
+
mixin :mason_tags
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
state :component_with_content do
|
|
89
|
+
rule %r/<\/&>/ do
|
|
90
|
+
token Comment::Preproc
|
|
91
|
+
pop!
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
mixin :mason_tags
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
state :component_sub do
|
|
98
|
+
rule %r/&>/, Comment::Preproc, :pop!
|
|
99
|
+
|
|
100
|
+
rule(/(.*?)(?=&>)/m) { delegate @perl }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
state :component_call do
|
|
104
|
+
rule %r/%>/, Comment::Preproc, :pop!
|
|
105
|
+
|
|
106
|
+
rule(/(.*?)(?=%>)/m) { delegate @perl }
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|