This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Augeas. Co-authored-by: Michael Camilleri <mike@inqk.net>
- Loading branch information
Showing
4 changed files
with
160 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,16 @@ | ||
(* | ||
This is a comment | ||
*) | ||
module Foo = | ||
autoload xfm | ||
|
||
let a = b | c . d | ||
|
||
let lns = a* | ||
|
||
let filter = incl "/path/to/file" | ||
. incl "/path/to/other_file" | ||
. Util.stdexcl | ||
|
||
(* xmf is the transform *) | ||
let xmf = transform lns filter |
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,93 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
module Rouge | ||
module Lexers | ||
class Augeas < RegexLexer | ||
title "Augeas" | ||
desc "The Augeas programming language (augeas.net)" | ||
|
||
tag 'augeas' | ||
aliases 'aug' | ||
filenames '*.aug' | ||
mimetypes 'text/x-augeas' | ||
|
||
def self.reserved | ||
@reserved ||= Set.new %w( | ||
_ let del store value counter seq key label autoload incl excl | ||
transform test get put in after set clear insa insb print_string | ||
print_regexp print_endline print_tree lens_ctype lens_atype | ||
lens_ktype lens_vtype lens_format_atype regexp_match | ||
) | ||
end | ||
|
||
state :basic do | ||
rule %r/\s+/m, Text | ||
rule %r/\(\*/, Comment::Multiline, :comment | ||
end | ||
|
||
state :comment do | ||
rule %r/\*\)/, Comment::Multiline, :pop! | ||
rule %r/\(\*/, Comment::Multiline, :comment | ||
rule %r/[^*)]+/, Comment::Multiline | ||
rule %r/[*)]/, Comment::Multiline | ||
end | ||
|
||
state :root do | ||
mixin :basic | ||
|
||
rule %r/(:)(\w\w*)/ do | ||
groups Punctuation, Keyword::Type | ||
end | ||
|
||
rule %r/\w[\w']*/ do |m| | ||
name = m[0] | ||
if name == "module" | ||
token Keyword::Reserved | ||
push :module | ||
elsif self.class.reserved.include? name | ||
token Keyword::Reserved | ||
elsif name =~ /\A[A-Z]/ | ||
token Keyword::Namespace | ||
else | ||
token Name | ||
end | ||
end | ||
|
||
rule %r/"/, Str, :string | ||
rule %r/\//, Str, :regexp | ||
|
||
rule %r([-*+.=?\|]+), Operator | ||
rule %r/[\[\](){}:;]/, Punctuation | ||
end | ||
|
||
state :module do | ||
rule %r/\s+/, Text | ||
rule %r/[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop! | ||
end | ||
|
||
state :regexp do | ||
rule %r/\//, Str::Regex, :pop! | ||
rule %r/[^\\\/]+/, Str::Regex | ||
rule %r/\\[\\\/]/, Str::Regex | ||
rule %r/\\/, Str::Regex | ||
end | ||
|
||
state :string do | ||
rule %r/"/, Str, :pop! | ||
rule %r/\\/, Str::Escape, :escape | ||
rule %r/[^\\"]+/, Str | ||
end | ||
|
||
state :escape do | ||
rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop! | ||
rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop! | ||
rule %r/o[0-7]+/i, Str::Escape, :pop! | ||
rule %r/x[\da-f]+/i, Str::Escape, :pop! | ||
rule %r/\d+/, Str::Escape, :pop! | ||
rule %r/\s+/, Str::Escape, :pop! | ||
rule %r/./, Str, :pop! | ||
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,19 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
describe Rouge::Lexers::Augeas do | ||
let(:subject) { Rouge::Lexers::Augeas.new } | ||
|
||
describe 'guessing' do | ||
include Support::Guessing | ||
|
||
it 'guesses by filename' do | ||
assert_guess :filename => 'foo.aug' | ||
end | ||
|
||
it 'guess by mimetype' do | ||
assert_guess :mimetype => 'text/x-augeas' | ||
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,32 @@ | ||
(* | ||
Multiline | ||
Comment | ||
*) | ||
|
||
module Example = | ||
autoload xfm | ||
|
||
let eol = Util.eol | ||
let sep_spc = Sep.space | ||
let sep_cont = Sep.cl_or_space | ||
|
||
let sep_cont_opt_build (sep:string) = | ||
del (Rx.cl_or_opt_space . sep . Rx.cl_or_opt_space) (" " . sep . " ") | ||
|
||
let negate_or_value (key:lens) (value:lens) = | ||
[ del_negate . (negate_node . key | key . value) ] | ||
|
||
let del_negate = del /(!!)*/ "" | ||
|
||
let sto_to_com_cmnd = del_negate . negate_node? . ( | ||
let alias = Rx.word - /(NO)?(PASSWD|EXEC|SETENV)/ | ||
in let non_alias = /[\/a-z]([^,:#()\n\\]|\\\\[=:,\\])*[^,=:#() \t\n\\]|[^,=:#() \t\n\\]/ | ||
in store (alias | non_alias)) | ||
|
||
let filter = (incl "/etc/sudoers") | ||
. (incl "/usr/local/etc/sudoers") | ||
. (incl "/etc/sudoers.d/*") | ||
. (incl "/usr/local/etc/sudoers.d/*") | ||
. (incl "/opt/csw/etc/sudoers") | ||
. (incl "/etc/opt/csw/sudoers") | ||
. Util.stdexcl |