diff options
author | Tim Hatch <tim@timhatch.com> | 2014-04-24 15:24:53 -0400 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2014-04-24 15:24:53 -0400 |
commit | 200ef95bc195f6fd30585f37ac0d218c8ed53881 (patch) | |
tree | 7255b204d4ff4dac0ebab1d46980ac10984767a0 | |
parent | 4330942e358d466ec6516e4114865ec6ca641c48 (diff) | |
parent | 284333c37108ad14eaa61f0634574ffd2183273c (diff) | |
download | pygments-200ef95bc195f6fd30585f37ac0d218c8ed53881.tar.gz |
Merged in vuhonglinh/pygments-main (pull request #212)
Conflicts:
pygments/lexers/_mapping.py
pygments/lexers/other.py
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 3 | ||||
-rw-r--r-- | pygments/lexers/other.py | 49 | ||||
-rw-r--r-- | tests/examplefiles/test.rsl | 111 |
4 files changed, 162 insertions, 2 deletions
@@ -157,6 +157,7 @@ Other contributors, listed alphabetically, are: * Pepijn de Vos -- HTML formatter CTags support * Whitney Young -- ObjectiveC lexer * Matthias Vallentin -- Bro lexer +* Linh Vu Hong -- RSL lexer * Nathan Weizenbaum -- Haml and Sass lexers * Dietmar Winkler -- Modelica lexer * Nils Winter -- Smalltalk lexer diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 3e0696f4..20d3ce75 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -267,7 +267,7 @@ LEXERS = { 'PythonConsoleLexer': ('pygments.lexers.agile', 'Python console session', ('pycon',), (), ('text/x-python-doctest',)), 'PythonLexer': ('pygments.lexers.agile', 'Python', ('python', 'py', 'sage'), ('*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'), ('text/x-python', 'application/x-python')), 'PythonTracebackLexer': ('pygments.lexers.agile', 'Python Traceback', ('pytb',), ('*.pytb',), ('text/x-python-traceback',)), - 'QBasicLexer': ('pygments.lexers.qbasic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('application/basic',)), + 'QBasicLexer': ('pygments.lexers.qbasic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('text/basic',)), 'QmlLexer': ('pygments.lexers.web', 'QML', ('qml',), ('*.qml',), ('application/x-qml',)), 'RConsoleLexer': ('pygments.lexers.math', 'RConsole', ('rconsole', 'rout'), ('*.Rout',), ()), 'RPMSpecLexer': ('pygments.lexers.other', 'RPMSpec', ('spec',), ('*.spec',), ('text/x-rpm-spec',)), @@ -289,6 +289,7 @@ LEXERS = { 'RhtmlLexer': ('pygments.lexers.templates', 'RHTML', ('rhtml', 'html+erb', 'html+ruby'), ('*.rhtml',), ('text/html+ruby',)), 'RobotFrameworkLexer': ('pygments.lexers.other', 'RobotFramework', ('robotframework',), ('*.txt', '*.robot'), ('text/x-robotframework',)), 'RqlLexer': ('pygments.lexers.sql', 'RQL', ('rql',), ('*.rql',), ('text/x-rql',)), + 'RslLexer': ('pygments.lexers.other', 'RSL', ('rsl',), ('*.rsl',), ('text/rsl',)), 'RstLexer': ('pygments.lexers.text', 'reStructuredText', ('rst', 'rest', 'restructuredtext'), ('*.rst', '*.rest'), ('text/x-rst', 'text/prs.fallenstein.rst')), 'RubyConsoleLexer': ('pygments.lexers.agile', 'Ruby irb session', ('rbcon', 'irb'), (), ('text/x-ruby-shellsession',)), 'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby', 'duby'), ('*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'), ('text/x-ruby', 'application/x-ruby')), diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index 261fa304..36772289 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -37,7 +37,8 @@ __all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer', 'MscgenLexer', 'KconfigLexer', 'VGLLexer', 'SourcePawnLexer', 'RobotFrameworkLexer', 'PuppetLexer', 'NSISLexer', 'RPMSpecLexer', 'CbmBasicV2Lexer', 'AutoItLexer', 'RexxLexer', 'APLLexer', - 'LSLLexer', 'AmbientTalkLexer', 'PawnLexer', 'VCTreeStatusLexer'] + 'LSLLexer', 'AmbientTalkLexer', 'PawnLexer', 'VCTreeStatusLexer', + 'RslLexer'] class LSLLexer(RegexLexer): @@ -4118,3 +4119,49 @@ class VCTreeStatusLexer(RegexLexer): (r'.*\n', Text) ] } + + +class RslLexer(RegexLexer): + """ + `RSL <http://en.wikipedia.org/wiki/RAISE>`_ is the formal specification + language used in RAISE (Rigorous Approach to Industrial Software Engineering) + method. + + *New in Pygments 1.7.* + """ + name = 'RSL' + aliases = ['rsl'] + filenames = ['*.rsl'] + mimetypes = ['text/rsl'] + flags = re.MULTILINE | re.DOTALL + + tokens = { + 'root':[ + (r'\b(Bool|Char|Int|Nat|Real|Text|Unit|abs|all|always|any|as|axiom|card|case|channel|chaos|class|devt_relation|dom|elems|else|elif|end|exists|extend|false|for|hd|hide|if|in|is|inds|initialise|int|inter|isin|len|let|local|ltl_assertion|object|of|out|post|pre|read|real|rng|scheme|skip|stop|swap|then|thoery|test_case|tl|transition_system|true|type|union|until|use|value|variable|while|with|write|~isin|-inflist|-infset|-list|-set)\b', Keyword), + (r'(variable|value)', Keyword.Declaration), + (r'--.*?\n', Comment), + (r'<:.*?:>', Comment), + (r'\{!.*?!\}', Comment), + (r'/\*.*?\*/', Comment), + (r'^[ \t]*([\w]+)[ \t]*:[^:]', Name.Function), + (r'(^[ \t]*)([\w]+)([ \t]*\([\w\s, ]*\)[ \t]*)(is|as)', bygroups(Text,Name.Function, Text, Keyword)), + (r'\b[A-Z]\w*\b',Keyword.Type), + (r'(true|false)\b', Keyword.Constant), + (r'".*"',String), + (r'\'.\'',String.Char), + (r'(><|->|-m->|/\\|<=|<<=|<\.|\|\||\|\^\||-~->|-~m->|\\/|>=|>>|\.>|\+\+|-\\|<->|=>|:-|~=|\*\*|<<|>>=|\+>|!!|\|=\||#)', Operator), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-f]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'.', Text), + ], + } + + def analyse_text(text): + """ + Check for the most common text in the beginning of a RSL file. + """ + if re.search(r'scheme\s*.*?=\s*class\s*type', text, re.I) is not None: + return 1.0 + else: + return 0.01 diff --git a/tests/examplefiles/test.rsl b/tests/examplefiles/test.rsl new file mode 100644 index 00000000..d6c9fc9a --- /dev/null +++ b/tests/examplefiles/test.rsl @@ -0,0 +1,111 @@ +scheme COMPILER = +class + type + Prog == mk_Prog(stmt : Stmt), + + Stmt == + mk_Asgn(ide : Identifier, expr : Expr) | + mk_If(cond : Expr, s1 : Stmt, s2 : Stmt) | + mk_Seq(head : Stmt, last : Stmt), + + Expr == + mk_Const(const : Int) | + mk_Plus(fst : Expr, snd : Expr) | + mk_Id(ide : Identifier), + Identifier = Text + +type /* storage for program variables */ + `Sigma = Identifier -m-> Int + +value + m : Prog -> `Sigma -> `Sigma + m(p)(`sigma) is m(stmt(p))(`sigma), + + m : Stmt -> `Sigma -> `Sigma + m(s)(`sigma) is + case s of + mk_Asgn(i, e) -> `sigma !! [i +> m(e)(`sigma)], + mk_Seq(s1, s2) -> m(s2)(m(s1)(`sigma)), + mk_If(c, s1, s2) -> + if m(c)(`sigma) ~= 0 then m(s1)(`sigma) else m(s2)(`sigma) end + end, + + m : Expr -> `Sigma -> Int + m(e)(`sigma) is + case e of + mk_Const(n) -> n, + mk_Plus(e1, e2) -> m(e1)(`sigma) + m(e2)(`sigma), + mk_Id(id) -> if id isin dom `sigma then `sigma(id) else 0 end + end + +type + MProg = Inst-list, + Inst == + mk_Push(ide1 : Identifier) | + mk_Pop(Unit) | + mk_Add(Unit) | + mk_Cnst(val : Int) | + mk_Store(ide2 : Identifier) | + mk_Jumpfalse(off1 : Int) | + mk_Jump(off2 : Int) + + +/* An interpreter for SMALL instructions */ + +type Stack = Int-list +value + I : MProg >< Int >< Stack -> (`Sigma ->`Sigma) + I(mp, pc, s)(`sigma) is + if pc <= 0 \/ pc > len mp then `sigma else + case mp(pc) of + mk_Push(x) -> if x isin dom `sigma + then I(mp, pc + 1, <.`sigma(x).> ^ s)(`sigma) + else I(mp, pc + 1, <.0.> ^ s)(`sigma) end, + mk_Pop(()) -> if len s = 0 then `sigma + else I(mp, pc + 1, tl s)(`sigma) end, + mk_Cnst(n) -> I(mp, pc + 1, <.n.> ^ s)(`sigma), + mk_Add(()) -> if len s < 2 then `sigma + else I(mp, pc + 1,<.s(1) + s(2).> ^ tl tl s)(`sigma) end, + mk_Store(x) -> if len s = 0 then `sigma + else I(mp, pc + 1, s)(`sigma !! [x +> s(1)]) end, + mk_Jumpfalse(n) -> if len s = 0 then `sigma + elsif hd s ~= 0 then I(mp, pc + 1, s)(`sigma) + else I(mp, pc + n, s)(`sigma) end, + mk_Jump(n) -> I(mp, pc + n, s)(`sigma) + end + end + +value + comp_Prog : Prog -> MProg + comp_Prog(p) is comp_Stmt(stmt(p)), + + comp_Stmt : Stmt -> MProg + comp_Stmt(s) is + case s of + mk_Asgn(id, e) -> comp_Expr(e) ^ <. mk_Store(id), mk_Pop() .>, + mk_Seq(s1, s2) -> comp_Stmt(s1) ^ comp_Stmt(s2), + mk_If(e, s1, s2) -> + let + ce = comp_Expr(e), + cs1 = comp_Stmt(s1), cs2 = comp_Stmt(s2) + in + ce ^ + <. mk_Jumpfalse(len cs1 + 3) .> ^ + <. mk_Pop() .> ^ + cs1 ^ + <. mk_Jump(len cs2 + 2) .> ^ + <. mk_Pop() .> ^ + cs2 + end + end, + + comp_Expr : Expr -> MProg + comp_Expr(e) is + case e of + mk_Const(n) -> <. mk_Cnst(n) .>, + mk_Plus(e1, e2) -> + comp_Expr(e1) ^ comp_Expr(e2) ^ <. mk_Add() .>, + mk_Id(id) -> <. mk_Push(id) .> + end + +end |