Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions lib/rouge/lexers/biml.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'xml'
require_relative 'csharp'

module Rouge
module Lexers
Expand All @@ -14,22 +15,48 @@ def self.detect?(text)
return true if text =~ /<\s*Biml\b/
end

start do
@csharp = CSharp.new(options)
end

state :biml_interp do
rule %r(<#[=]?)m do
token Name::Tag
push :directive_as_csharp
end
end

prepend :root do
rule %r(<#\@\s*)m, Name::Tag, :directive_tag

rule %r(<#[=]?\s*)m, Name::Tag, :directive_as_csharp
mixin :biml_interp
end

prepend :attr do
#TODO: how to deal with embedded <# tags inside a attribute string
#rule %r("<#[=]?\s*)m, Name::Tag, :directive_as_csharp
rule(%r/"/) { token Str::Double; goto :biml_dq }
rule(%r/'/) { token Str::Double; goto :biml_sq }

mixin :biml_interp
end

state :biml_dq do
rule %r/[^<"]+/, Str::Double
mixin :biml_interp
rule %r/"/, Str::Double, :pop!
rule %r/</, Str::Double
end

state :biml_sq do
rule %r/[^<']+/, Str::Single
mixin :biml_interp
rule %r/'/, Str::Single, :pop!
rule %r/</, Str::Single
end

state :directive_as_csharp do
rule %r/\s*#>\s*/m, Name::Tag, :pop!
rule %r(.*?(?=\s*#>\s*))m do
delegate CSharp
end
rule(/[^#]+/) { delegate @csharp }
rule /#>/, Name::Tag, :pop!
rule(/[#>]/) { delegate @csharp }
end

state :directive_tag do
Expand Down