-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a lexer for SSH configuration files. Co-authored-by: Michael Camilleri <mike@inqk.net>
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Host example | ||
Hostname example.com | ||
User user | ||
Port 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
module Rouge | ||
module Lexers | ||
class SSH < RegexLexer | ||
tag 'ssh' | ||
|
||
title "SSH Config File" | ||
desc 'A lexer for SSH configuration files' | ||
filenames 'ssh_config' | ||
|
||
state :root do | ||
rule %r/[a-z0-9]+/i, Keyword, :statement | ||
mixin :base | ||
end | ||
|
||
state :statement do | ||
rule %r/\n/, Text, :pop! | ||
rule %r/(?:yes|no|confirm|ask|always|auto|none|force)\b/, Name::Constant | ||
|
||
rule %r/\d+/, Num | ||
rule %r/[^#\s;{}$\\]+/, Text | ||
mixin :base | ||
end | ||
|
||
state :base do | ||
rule %r/\s+/, Text | ||
rule %r/#.*/, Comment::Single | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
describe Rouge::Lexers::SSH do | ||
let(:subject) { Rouge::Lexers::SSH.new } | ||
|
||
describe 'lexing' do | ||
include Support::Lexing | ||
|
||
it 'lexes a specification' do | ||
example = 'Host example | ||
Hostname www.example.com | ||
Port 1234 | ||
Tunnel no' | ||
|
||
assert_tokens_equal example, ["Keyword", "Host"], | ||
["Text", " example\n "], | ||
["Keyword", "Hostname"], | ||
["Text", " www.example.com\n "], | ||
["Keyword", "Port"], | ||
["Text", " "], | ||
["Literal.Number", "1234"], | ||
["Text", "\n "], | ||
["Keyword", "Tunnel"], | ||
["Text", " "], | ||
["Name.Constant", "no"] | ||
end | ||
end | ||
|
||
describe 'guessing' do | ||
include Support::Guessing | ||
|
||
it 'guesses by filename' do | ||
assert_guess :filename => '/etc/ssh_config' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This is the ssh client system-wide configuration file. See | ||
# ssh_config(5) for more information. This file provides defaults for | ||
# users, and the values can be changed in per-user configuration files | ||
# or on the command line. | ||
|
||
Host * | ||
Port 22 # default port | ||
Tunnel no | ||
GSSAPIAuthentication yes | ||
GSSAPIDelegateCredentials no | ||
|
||
Host example | ||
Hostname www.example.com | ||
User user | ||
Port 1234 |