# -*- coding: utf-8 -*- #
# frozen_string_literal: true
moduleRougemoduleLexersclassMason<TemplateLexertitle'Mason'desc'The HTML::Mason framework (https://metacpan.org/pod/HTML::Mason)'tag'mason'filenames'*.mi','*.mc','*.mas','*.m','*.mhtml','*.mcomp','autohandler','dhandler'mimetypes'text/x-mason','application/x-mason'definitialize(*)super@perl=Perl.newenddefself.detect?(text)returnfalseiftext.doctype?(/((?:ht|x)ml)/)returntrueiftext.doctype?end# Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
TEXT_BLOCKS=%w(text doc)PERL_BLOCKS=%w(args flags attr init once shared perl cleanup filter)COMPONENTS=%w(def method)state:rootdomixin:mason_tagsendstate:mason_tagsdorule%r/\s+/,Text::Whitespacerule%r/<%(#{TEXT_BLOCKS.join('|')})>/oi,Comment::Preproc,:text_blockrule%r/<%(#{PERL_BLOCKS.join('|')})>/oi,Comment::Preproc,:perl_blockrule%r/(<%(#{COMPONENTS.join('|')}))([^>]*)(>)/oido|m|tokenComment::Preproc,m[1]tokenName,m[3]tokenComment::Preproc,m[4]push:component_blockend# perl line
rule%r/^(%)(.*)$/do|m|tokenComment::Preproc,m[1]delegate@perl,m[2]end# start of component call
rule%r/<%/,Comment::Preproc,:component_call# start of component with content
rule%r/<&\|/dotokenComment::Preprocpush:component_with_contentpush:component_subend# start of component substitution
rule%r/<&/,Comment::Preproc,:component_sub# fallback to HTML until a mason tag is encountered
rule(/(.+?)(?=(<\/?&|<\/?%|^%|^#))/m){delegateparent}# if we get here, there's no more mason tags, so we parse the rest of the doc as HTML
rule(/.+/m){delegateparent}endstate:perl_blockdorule%r/<\/%(#{PERL_BLOCKS.join('|')})>/oi,Comment::Preproc,:pop!rule%r/\s+/,Text::Whitespacerule%r/^(#.*)$/,Commentrule(/(.*?[^"])(?=<\/%)/m){delegate@perl}endstate:text_blockdorule%r/<\/%(#{TEXT_BLOCKS.join('|')})>/oi,Comment::Preproc,:pop!rule%r/\s+/,Text::Whitespacerule%r/^(#.*)$/,Commentrule%r/(.*?[^"])(?=<\/%)/m,Commentendstate:component_blockdorule%r/<\/%(#{COMPONENTS.join('|')})>/oi,Comment::Preproc,:pop!rule%r/\s+/,Text::Whitespacerule%r/^(#.*)$/,Commentmixin:mason_tagsendstate:component_with_contentdorule%r/<\/&>/dotokenComment::Preprocpop!endmixin:mason_tagsendstate:component_subdorule%r/&>/,Comment::Preproc,:pop!rule(/(.*?)(?=&>)/m){delegate@perl}endstate:component_calldorule%r/%>/,Comment::Preproc,:pop!rule(/(.*?)(?=%>)/m){delegate@perl}endendendend