aboutsummaryrefslogtreecommitdiffstats
path: root/osurl
diff options
context:
space:
mode:
authorAndrew <RhodiumToad@lua.freenode>2018-12-05 13:25:52 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-03-28 16:48:37 +0100
commit7fb961453ff32d2671308798df6bc4bd54586df4 (patch)
treee80fb73bf062a5f79157fe5ce6b7b641d2df98bb /osurl
parent7b180f7a82d7bfcd954bdf71589153c8d5046411 (diff)
downloadvim-suse-changes-7fb961453ff32d2671308798df6bc4bd54586df4.tar.gz
fix(osurl): alternative version using lpeg.
Diffstat (limited to 'osurl')
-rwxr-xr-xosurl41
1 files changed, 16 insertions, 25 deletions
diff --git a/osurl b/osurl
index 34454db..2deb753 100755
--- a/osurl
+++ b/osurl
@@ -1,28 +1,19 @@
#!/usr/bin/luajit
-local re = require 're'
-local pat = re.compile([[
- str <- {~ (bug / .)* ~} !.
- num <- { %d+ }
- bug <- (("bgo#" num) -> BGO)
- / (("bko#" num) -> BKO)
- / (("bmo#" num) -> BMO)
- / (("boo#" num) -> BOO)
- / (("bsc#" num) -> BSC)
- / (("gh#" { (!"#" .)+ } "#" { %w+ }) -> GH)
- / (("lp#" num) -> LP)
- / (("rh#" num) -> RH)
-]],{
- BGO = "http://bugzilla.gnome.org/show_bug.cgi?id=%1",
- BKO = "http://bugzilla.kernel.org/show_bug.cgi?id=%1",
- BMO = "http://bugzilla.mozilla.org/show_bug.cgi?id=%1",
- BOO = "http://bugzilla.opensuse.org/show_bug.cgi?id=%1",
- BSC = "http://bugzilla.suse.com/show_bug.cgi?id=%1",
- GH = "https://github.com/%1/issues/%2",
- LP = "https://launchpad.net/bugs/%1",
- RH = "http://bugzilla.redhat.com/show_bug.cgi?id=%1"
-});
+local lpeg = require 'lpeg'
+local P,C,Cs,R = lpeg.P, lpeg.C, lpeg.Cs, lpeg.R
-print(pat:match("gh#python/cpython#123"))
-print(pat:match("lp#123456"))
-print(pat:match("bramboříček"))
+local cnum = C(R("09")^1)
+local cword = C(R("AZ","az","09","__")^1)
+local bugpat =
+ (P"bgo#" * cnum) / "http://bugzilla.gnome.org/show_bug.cgi?id=%1"
+ + (P"bko#" * cnum) / "http://bugzilla.kernel.org/show_bug.cgi?id=%1"
+ + (P"bmo#" * cnum) / "http://bugzilla.mozilla.org/show_bug.cgi?id=%1"
+ + (P"boo#" * cnum) / "http://bugzilla.opensuse.org/show_bug.cgi?id=%1"
+ + (P"bsc#" * cnum) / "http://bugzilla.suse.com/show_bug.cgi?id=%1"
+ + (P"gh#" * C((1 - P"#")^1) * P"#" * cword) / "https://github.com/%1/issues/%2"
+ + (P"lp#" * cnum) / "https://launchpad.net/bugs/%1"
+ + (P"rh#" * cnum) / "http://bugzilla.redhat.com/show_bug.cgi?id=%1"
+local pat = Cs((bugpat + P(1))^0)
+
+os.execute("xdg-open " .. pat:match(arg[1]))