Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lexer for GDT #2060

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions lib/rouge/demos/gdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
01380006301
0178315EKG_TYP1
0178316PRX_SYS1
014921802.00
01330000815
0123101Doe
0133102Jane
017310301011990
01031102
0123622158
0123623061
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/.*$\r?\n?/, Literal, :root
end

state :comment do
rule %r/.*$\r?\n?/, Comment, :root
end

state :type do
rule %r/.*$\r?\n?/, 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
19 changes: 19 additions & 0 deletions spec/visual/samples/gdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
01380006310
0178315PRX_SYS1
0178316KKX_SYS1
014921802.10
014300004711
0123101Doe
0133102John
017310331121999
01031101
0123622180
0123623085
017620031122023
0166227Comment
0286228Blood pressure test
0286228-------------------
0236228Ps[mmHg] 143
0236228Pd[mmHg] 92
0236228HF[P/min] 71
0096228