summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--pygments/lexers/_mapping.py5
-rw-r--r--pygments/lexers/other.py50
-rw-r--r--tests/examplefiles/example.msc43
-rw-r--r--tests/examplefiles/example2.msc79
5 files changed, 175 insertions, 3 deletions
diff --git a/AUTHORS b/AUTHORS
index 5a09a173..74f186af 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -45,6 +45,7 @@ Other contributors, listed alphabetically, are:
* Jordi GutiƩrrez Hermoso -- Octave lexer
* David Hess, Fish Software, Inc. -- Objective-J lexer
* Varun Hiremath -- Debian control lexer
+* Doug Hogan -- Mscgen lexer
* Ben Hollis -- Mason lexer
* Tim Howard -- BlitzMax lexer
* Ivan Inozemtsev -- Fantom lexer
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 8bcc1744..9cf31b20 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -131,9 +131,9 @@ LEXERS = {
'JavascriptPhpLexer': ('pygments.lexers.templates', 'JavaScript+PHP', ('js+php', 'javascript+php'), (), ('application/x-javascript+php', 'text/x-javascript+php', 'text/javascript+php')),
'JavascriptSmartyLexer': ('pygments.lexers.templates', 'JavaScript+Smarty', ('js+smarty', 'javascript+smarty'), (), ('application/x-javascript+smarty', 'text/x-javascript+smarty', 'text/javascript+smarty')),
'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)),
- 'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)),
- 'JuliaLexer': ('pygments.lexers.math', 'Julia', ('julia','jl'), ('*.jl',), ('text/x-julia','application/x-julia')),
'JuliaConsoleLexer': ('pygments.lexers.math', 'Julia console', ('jlcon',), (), ()),
+ 'JuliaLexer': ('pygments.lexers.math', 'Julia', ('julia', 'jl'), ('*.jl',), ('text/x-julia', 'application/x-julia')),
+ 'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)),
'LighttpdConfLexer': ('pygments.lexers.text', 'Lighttpd configuration file', ('lighty', 'lighttpd'), (), ('text/x-lighttpd-conf',)),
'LiterateHaskellLexer': ('pygments.lexers.functional', 'Literate Haskell', ('lhs', 'literate-haskell'), ('*.lhs',), ('text/x-literate-haskell',)),
'LlvmLexer': ('pygments.lexers.asm', 'LLVM', ('llvm',), ('*.ll',), ('text/x-llvm',)),
@@ -155,6 +155,7 @@ LEXERS = {
'Modula2Lexer': ('pygments.lexers.compiled', 'Modula-2', ('modula2', 'm2'), ('*.def', '*.mod'), ('text/x-modula2',)),
'MoinWikiLexer': ('pygments.lexers.text', 'MoinMoin/Trac Wiki markup', ('trac-wiki', 'moin'), (), ('text/x-trac-wiki',)),
'MoonScriptLexer': ('pygments.lexers.agile', 'MoonScript', ('moon', 'moonscript'), ('*.moon',), ('text/x-moonscript', 'application/x-moonscript')),
+ 'MscgenLexer': ('pygments.lexers.other', 'Mscgen', ('mscgen', 'msc'), ('*.msc',), ()),
'MuPADLexer': ('pygments.lexers.math', 'MuPAD', ('mupad',), ('*.mu',), ()),
'MxmlLexer': ('pygments.lexers.web', 'MXML', ('mxml',), ('*.mxml',), ()),
'MySqlLexer': ('pygments.lexers.sql', 'MySQL', ('mysql',), (), ('text/x-mysql',)),
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index 3497f867..689672e6 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -29,7 +29,8 @@ __all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer',
'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer', 'PostScriptLexer',
'AutohotkeyLexer', 'GoodDataCLLexer', 'MaqlLexer', 'ProtoBufLexer',
'HybrisLexer', 'AwkLexer', 'Cfengine3Lexer', 'SnobolLexer',
- 'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer']
+ 'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer',
+ 'MscgenLexer' ]
class ECLLexer(RegexLexer):
@@ -3337,3 +3338,50 @@ class BroLexer(RegexLexer):
(r'\\', String.Regex)
]
}
+
+class MscgenLexer(RegexLexer):
+ """
+ For `Mscgen <http://www.mcternan.me.uk/mscgen/>`_ files.
+ """
+ name = 'Mscgen'
+ aliases = ['mscgen', 'msc' ]
+ filenames = ['*.msc']
+
+ _var = r'([a-zA-Z0-9_]+|"(?:\\"|[^"])*")'
+
+ tokens = {
+ 'root': [
+ (r'msc\b', Keyword.Type),
+ # Options
+ (r'(hscale|HSCALE|width|WIDTH|wordwraparcs|WORDWRAPARCS'
+ r'|arcgradient|ARCGRADIENT)\b', Name.Property),
+ # Operators
+ (r'(abox|ABOX|rbox|RBOX|box|BOX|note|NOTE)\b', Operator.Word),
+ (r'(\.|-|\|){3}', Keyword),
+ (r'(?:-|=|\.|:){2}'
+ r'|<<=>>|<->|<=>|<<>>|<:>'
+ r'|->|=>>|>>|=>|:>|-x|-X'
+ r'|<-|<<=|<<|<=|<:|x-|X-|=', Operator),
+ # Names
+ (r'\*', Name.Builtin),
+ (_var, Name.Variable),
+ # Other
+ (r'\[', Punctuation, 'attrs'),
+ (r'\{|\}|,|;', Punctuation),
+ include('comments')
+ ],
+ 'attrs': [
+ (r'\]', Punctuation, '#pop'),
+ (_var + r'(\s*)(=)(\s*)' + _var,
+ bygroups(Name.Attribute, Text.Whitespace, Operator, Text.Whitespace,
+ String)),
+ (r',', Punctuation),
+ include('comments')
+ ],
+ 'comments': [
+ (r'(?://|#).*?\n', Comment.Single),
+ (r'/\*(?:.|\n)*?\*/', Comment.Multiline),
+ (r'[ \t\r\n]+', Text.Whitespace)
+ ]
+ }
+
diff --git a/tests/examplefiles/example.msc b/tests/examplefiles/example.msc
new file mode 100644
index 00000000..d51b32a6
--- /dev/null
+++ b/tests/examplefiles/example.msc
@@ -0,0 +1,43 @@
+msc {
+ hscale=5;
+
+ //test comment
+
+ a,b,c,d;
+
+/* another
+comment
+goes here */ /* too */ // now
+
+ ... [label="test1", id="1"];
+ --- [label="test2", id="2"];
+ ||| [label="test3", id="2"];
+ a ABOX b;
+ a--b [label="test4", id="2"];
+ a == b [label="test5", id="2"];
+ a .. b [label="test6", id="2"];
+ a::b [label="test7", id="2"];
+ a<<=>> b [label="test8", id="2"],
+ b <->c [label="test9", id="2"],
+ b RBOX c;
+ a BOX d;
+ a<=> b [label="test10", id="2"];
+ a <<>> b [label="test11", id="2"];
+ a<:>b [label="test12", id="2"];
+ a->b [label="test13", id="2"];
+ a =>> b [label="test14", id="2"],
+ b >> c [label="test15", id="2"],
+ a=> b [label="test16", id="2"];
+ a :>b [label="test17", id="2"];
+ a-x b [label="test18", id="2"];
+ a -Xb [label="test19", id="2"];
+ a<- b [label="test20", id="2"];
+ a <<=b [label="test21", id="2"];
+ a<< b [label="test22", id="2"];
+ a <= b [label="test23", id="2"];
+ a<: b [label="test24", id="2"];
+ a -xb [label="test25", id="2"];
+ a-X b [ label="test26",id="2" ];
+ a->* [label="test27" , id="2"];
+ *<-b [label="test28",id="28"];
+}
diff --git a/tests/examplefiles/example2.msc b/tests/examplefiles/example2.msc
new file mode 100644
index 00000000..61e2ef83
--- /dev/null
+++ b/tests/examplefiles/example2.msc
@@ -0,0 +1,79 @@
+#!/usr/bin/mscgen -Tpng
+#
+# testinput2.msc : Sample msc input file with URLs
+#
+# This file is PUBLIC DOMAIN and may be freely reproduced, distributed,
+# transmitted, used, modified, built upon, or otherwise exploited by
+# anyone for any purpose, commercial or non-commercial, and in any way,
+# including by methods that have not yet been invented or conceived.
+#
+# This file is provided "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+#
+
+# Note: This is from mscgen-0.20
+
+msc {
+
+A,B;
+
+--- [label="Start", ID="1"];
+
+A->B [label="signal"];
+A<-B [label="signal"];
+
+
+A=>B [label="method"];
+A<=B [label="method"];
+
+A>>B [label="return"];
+A<<B [label="return"];
+
+A=>>B [label="call-back"];
+A<<=B [label="call-back", URL="www.google.com"];
+
+A x- B [label="loss"];
+A -x B [label="loss"];
+
+--- [label="Left arcs", ID="2", IDURL="www.google.co.uk"];
+
+A->A [label="signal"];
+A<-A [label="signal"];
+
+
+A=>A [label="method"];
+A<=A [label="method"];
+
+A>>A [label="return"];
+A<<A [label="return"];
+
+A=>>A [label="call-back"];
+A<<=A [label="call-back", URL="www.google.com", ID="3"];
+
+A x- A [label="loss"];
+A -x A [label="loss"];
+
+--- [label="Right arcs"];
+
+B->B [label="signal"];
+B<-B [label="signal"];
+
+
+B=>B [label="method"];
+B<=B [label="method"];
+
+B>>B [label="return"];
+B<<B [label="return"];
+
+B=>>B [label="call-back", ID="4"];
+B<<=B [label="call-back", URL="www.google.com"];
+
+B x- B [label="loss"];
+B -x B [label="loss"];
+
+--- [label="End of arcs", URL="www.google.com"];
+
+
+... [label="Some time passes", URL="www.google.com"];
+}