Use rx macro instead of hand written regexps

ご主人様
not manx 4 years ago
parent 4f502b5893
commit 4585d85149
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -1,26 +1,13 @@
# testing thing
www-servers/nginx nginx_modueles: #some commnet: here
nginx rtmp threads pcre-jit
nginx NGINX_MODULES_HTTP: headers_more gunzip fancyindex gzip_static mp4 metrics push_stream random_index realip slice sticky stub_status upload_progress upstream_check addition
app-misc/some-big-word
some-modules a b c d
app-misc/nginx
*/*
>=nginx
<=nginx
=nginx
>=app-misc/nginx t
<=thing t a mweee: mwee: uguu
thing dsadsaading:
thing Wadsadang:
app-misc/mwee
app-misc/*
thing-thonxb
>=x11-libs/
app-misc/some-big-word:10 mwee: a_flag #comment
app-misc/s
=>app-misc/-_-
app-misc/thing
www-servers/nginx
some big huge line: something after something something:
>=www-servers/nginx
=www-servers/nginx
>=www-servers/nginx-1.19.1
dev-lang/python:3.7

@ -37,67 +37,49 @@
table)
"Syntax table for `package.use-mode'.")
(setq package.use--repos
'("acct-group/" "acct-user/" "app-accessibility/" "app-admin/" "app-antivirus/"
"app-arch/" "app-backup/" "app-benchmarks/" "app-cdr/" "app-crypt/"
"app-dicts/" "app-doc/" "app-editors/" "app-emacs/" "app-emulation/"
"app-eselect/" "app-forensics/" "app-i18n/" "app-laptop/" "app-leechcraft/"
"app-metrics/" "app-misc/" "app-mobilephone/" "app-office/" "app-officeext/"
"app-pda/" "app-portage/" "app-shells/" "app-text/" "app-vim/" "app-xemacs/"
"dev-ada/" "dev-cpp/" "dev-db/" "dev-dotnet/" "dev-embedded/" "dev-erlang/"
"dev-games/" "dev-go/" "dev-haskell/" "dev-java/" "dev-lang/" "dev-libs/"
"dev-lisp/" "dev-lua/" "dev-ml/" "dev-perl/" "dev-php/" "dev-python/"
"dev-qt/" "dev-ros/" "dev-ruby/" "dev-scheme/" "dev-tcltk/" "dev-tex/"
"dev-texlive/" "dev-util/" "dev-vcs/" "eclass/" "games-action/"
"games-arcade/" "games-board/" "games-emulation/" "games-engines/"
"games-fps/" "games-kids/" "games-misc/" "games-mud/" "games-puzzle/"
"games-roguelike/" "games-rpg/" "games-server/" "games-simulation/"
"games-sports/" "games-strategy/" "games-util/" "gnome-base/" "gnome-extra/"
"gnustep-apps/" "gnustep-base/" "gnustep-libs/" "gui-apps/" "gui-libs/"
"gui-wm/" "java-virtuals/" "kde-apps/" "kde-frameworks/" "kde-misc/"
"kde-plasma/" "licenses/" "lxde-base/" "lxqt-base/" "mail-client/"
"mail-filter/" "mail-mta/" "mate-base/" "mate-extra/" "media-fonts/"
"media-gfx/" "media-libs/" "media-plugins/" "media-radio/" "media-sound/"
"media-tv/" "media-video/" "metadata/" "net-analyzer/" "net-dialup/"
"net-dns/" "net-firewall/" "net-fs/" "net-ftp/" "net-im/" "net-irc/"
"net-libs/" "net-mail/" "net-misc/" "net-nds/" "net-news/" "net-nntp/"
"net-p2p/" "net-print/" "net-proxy/" "net-voip/" "net-vpn/" "net-wireless/"
"perl-core/" "profiles/" "ros-meta/" "sci-astronomy/" "sci-biology/"
"sci-calculators/" "sci-chemistry/" "sci-electronics/" "sci-geosciences/"
"sci-libs/" "sci-mathematics/" "sci-misc/" "sci-physics/" "sci-visualization/"
"scripts/" "sec-policy/" "sys-apps/" "sys-auth/" "sys-block/" "sys-boot/"
"sys-cluster/" "sys-devel/" "sys-fabric/" "sys-firmware/" "sys-fs/"
"sys-kernel/" "sys-libs/" "sys-power/" "sys-process/" "virtual/" "www-apache/"
"www-apps/" "www-client/" "www-misc/" "www-plugins/" "www-servers/"
"x11-apps/" "x11-base/" "x11-drivers/" "x11-libs/" "x11-misc/" "x11-plugins/"
"x11-terms/" "x11-themes/" "x11-wm/" "xfce-base/" "xfce-extra/" "*/"))
(defvar package.use--version-bit
(rx line-start (? (or "=" ">" "<" ">=" "<="))))
(setq package.use--repos-joined (concat "\\(" (string-join package.use--repos "\\|") "\\)"))
(defvar package.use--version-bit "^\\([=<>]*\\)?")
(setq package.use--name-bit "\\([A-Za-z0-9_\\*-]+\\)")
(defvar package.use--catagory-bit
(rx (1+ (any alnum "_" "." "+" "*" "-")) "/"))
(setq package.use-font-lock-keywords
(list `(,(concat package.use--version-bit package.use--repos-joined package.use--name-bit)
(0 font-lock-function-name-face)
(3 font-lock-variable-name-face t))
`(,(concat package.use--version-bit package.use--name-bit) . font-lock-keyword-face)
'(":[0-9]+" 0 font-lock-builtin-face t)
'("[ \\t]+[A-Za-z09_-]+:" 0 font-lock-constant-face t)))
(defvar package.use--name-bit
(rx (group (1+ (any alnum "_" "." "+" "*" "-")))))
(defvar package.use-font-lock-keywords
(list
;; >=www-servers/
;; www-servers/
`(,(concat package.use--version-bit package.use--catagory-bit)
. font-lock-function-name-face)
;; >=nginx-1.19.1
;; nginx
`(,(concat package.use--version-bit package.use--name-bit)
. font-lock-keyword-face)
;; >=www-servers/nginx-1.19.1
;; www-servers/nginx
`(,(concat package.use--version-bit package.use--catagory-bit package.use--name-bit)
(1 font-lock-variable-name-face t))
;; dev-langs/python:3.7
`(,(rx ":" (1+ (any digit ".")))
0 font-lock-type-face t)
;; www-servers/nginx NGINX_MODULES_HTTP:
`(,(rx (1+ whitespace) (1+ (any alnum "_" "-")) ":")
0 font-lock-constant-face t)))
(define-derived-mode package.use-mode prog-mode "package.use"
:syntax-table nginx-mode-syntax-table
:keymap nil
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-start-skip) "#+ *")
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(set (make-local-variable 'require-final-newline) t)
(set (make-local-variable 'font-lock-defaults)
'(package.use-font-lock-keywords nil)))
;;;###autoload
(add-to-list 'auto-mode-alist '("package\\.use'" . package.use-mode))
(add-to-list 'auto-mode-alist '("package\\.use$" . package.use-mode))
;;;###autoload
(add-to-list 'auto-mode-alist '("/package\\.use/" . package.use-mode))

Loading…
Cancel
Save