Skip to content

Commit

Permalink
Add gdt lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lixfeld committed Aug 19, 2024
1 parent 150ec4a commit 2ef6b7a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/rouge/lexers/gdt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class GDT < RegexLexer
title 'GDT'
desc "Geräte-Daten-Träger (Device Data Carrier)"
tag 'gdt'
filenames '*.gdt'
mimetypes 'text/x-gdt'

state :root do
rule %r/[0-9]{3}/, Text, :length
end

state :length do
rule %r/(6227|6228)/, Keyword, :comment
rule %r/8000/, Keyword, :type
rule %r/[0-9]{4}/, Keyword, :content
rule %r/\s+/, Text::Whitespace
end

state :content do
rule %r(.*?$), Literal, :root
end

state :comment do
rule %r(.*?$), Comment, :root
end

state :type do
rule %r(.*?$), Name::Class, :root
end

state :whitespace do
rule %r/\s+/, Text::Whitespace
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lexers/gdt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::GDT do
let(:subject) { Rouge::Lexers::GDT.new }

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.gdt'
end

it 'guesses by mimetype' do
assert_guess :mimetype => 'text/x-gdt'
end
end
end

0 comments on commit 2ef6b7a

Please sign in to comment.