summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2015-10-13 09:27:54 -0700
committerTim Hatch <tim@timhatch.com>2015-10-13 09:27:54 -0700
commit5770287cbb9d663d407d059e4b0137fb2b5be3ed (patch)
treed037358e164da691e40f4171066e78ef7e127465
parentc55107b1c900caa20cdc0c5386f51ec4731114bb (diff)
parentcbc52d156bbd8fb85c6eb185013c60b1e5b353cb (diff)
downloadpygments-5770287cbb9d663d407d059e4b0137fb2b5be3ed.tar.gz
Merged in justinjhendrick/pygments-main (pull request #381)
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/parasail.py81
-rw-r--r--tests/examplefiles/test.psl182
3 files changed, 264 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 3dc36204..2d14432d 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -268,6 +268,7 @@ LEXERS = {
'OpaLexer': ('pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)),
'OpenEdgeLexer': ('pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')),
'PanLexer': ('pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()),
+ 'ParaSailLexer': ('pygments.lexers.parasail', 'ParaSail', ('parasail',), ('*.psi', '*.psl'), ('text/x-parasail',)),
'PawnLexer': ('pygments.lexers.pawn', 'Pawn', ('pawn',), ('*.p', '*.pwn', '*.inc'), ('text/x-pawn',)),
'Perl6Lexer': ('pygments.lexers.perl', 'Perl6', ('perl6', 'pl6'), ('*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6', '*.6pm', '*.p6m', '*.pm6', '*.t'), ('text/x-perl6', 'application/x-perl6')),
'PerlLexer': ('pygments.lexers.perl', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm', '*.t'), ('text/x-perl', 'application/x-perl')),
diff --git a/pygments/lexers/parasail.py b/pygments/lexers/parasail.py
new file mode 100644
index 00000000..3cfffbee
--- /dev/null
+++ b/pygments/lexers/parasail.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.parasail
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Lexer for ParaSail.
+
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import re
+
+from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
+ this, combined, inherit, do_insertions, default
+from pygments.util import get_bool_opt, get_list_opt
+from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
+ Number, Punctuation, Literal
+
+__all__ = ['ParaSailLexer']
+
+
+class ParaSailLexer(RegexLexer):
+ """
+ For `ParaSail <http://www.parasail-lang.org>`_ source code.
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'ParaSail'
+ aliases = ['parasail']
+ filenames = ['*.psi', '*.psl']
+ mimetypes = ['text/x-parasail']
+
+ flags = re.MULTILINE
+
+ tokens = {
+ 'root': [
+ (r'[^\S\n]+', Text),
+ (r'//.*?\n', Comment.Single),
+ (r'\b(and|or|xor)=', Operator.Word),
+ (r'\b(and(\s+then)?|or(\s+else)?|xor|rem|mod|'
+ r'(is|not)\s+null)\b',
+ Operator.Word),
+ # Keywords
+ (r'\b(abs|abstract|all|block|class|concurrent|const|continue|'
+ r'each|end|exit|extends|exports|forward|func|global|implements|'
+ r'import|in|interface|is|lambda|locked|new|not|null|of|op|'
+ r'optional|private|queued|ref|return|reverse|separate|some|'
+ r'type|until|var|with|'
+ # Control flow
+ r'if|then|else|elsif|case|for|while|loop)\b',
+ Keyword.Reserved),
+ (r'(abstract\s+)?(interface|class|op|func|type)',
+ Keyword.Declaration),
+ # Literals
+ (r'"[^"]*"', String),
+ (r'\\[\'ntrf"0]', String.Escape),
+ (r'#[a-zA-Z]\w*', Literal), #Enumeration
+ include('numbers'),
+ (r"'[^']'", String.Char),
+ (r'[a-zA-Z]\w*', Name),
+ # Operators and Punctuation
+ (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|'
+ r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\||\|=|/=|\+|-|\*|/|'
+ r'\.\.|<\.\.|\.\.<|<\.\.<)',
+ Operator),
+ (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)',
+ Punctuation),
+ (r'\n+', Text),
+ ],
+ 'numbers' : [
+ (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex), # any base
+ (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex), # C-like hex
+ (r'0[bB][01][01_]*', Number.Bin), # C-like bin
+ (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*', # float exp
+ Number.Float),
+ (r'\d[0-9_]*\.\d[0-9_]*', Number.Float), # float
+ (r'\d[0-9_]*', Number.Integer), # integer
+ ],
+ }
diff --git a/tests/examplefiles/test.psl b/tests/examplefiles/test.psl
new file mode 100644
index 00000000..3ac99498
--- /dev/null
+++ b/tests/examplefiles/test.psl
@@ -0,0 +1,182 @@
+// This is a comment
+
+// 1. Basics
+
+// Functions
+func Add(X : Univ_Integer; Y : Univ_Integer) -> Univ_Integer is
+ return X + Y;
+end func Add;
+// End of line semi-colons are optional
+// +, +=, -, -=, *, *=, /, /=
+// all do what you'd expect (/ is integer division)
+
+// If you find Univ_Integer to be too verbose you can import Short_Names
+// which defines aliases like Int for Univ_Integer and String for Univ_String
+import PSL::Short_Names::*, *
+
+func Greetings() is
+ const S : String := "Hello, World!"
+ Println(S)
+end func Greetings
+// All declarations are 'const', 'var', or 'ref'
+// Assignment is :=, equality checks are ==, and != is not equals
+
+func Boolean_Examples(B : Bool) is
+ const And := B and #true // Parallel execution of operands
+ const And_Then := B and then #true // Short-Circuit
+ const Or := B or #false // Parallel execution of operands
+ const Or_Else := B or else #false // Short-Cirtuit
+ const Xor := B xor #true
+ var Result : Bool := #true;
+ Result and= #false;
+ Result or= #true;
+ Result xor= #false;
+end func Boolean_Examples
+// Booleans are a special type of enumeration
+// All enumerations are preceded by a sharp '#'
+
+func Fib(N : Int) {N >= 0} -> Int is
+ if N <= 1 then
+ return N
+ else
+ // Left and right side of '+' are computed in Parallel here
+ return Fib(N - 1) + Fib(N - 2)
+ end if
+end func Fib
+// '{N >= 0}' is a precondition to this function
+// Preconditions are built in to the language and checked by the compiler
+
+// ParaSail does not have mutable global variables
+// Instead, use 'var' parameters
+func Increment_All(var Nums : Vector<Int>) is
+ for each Elem of Nums concurrent loop
+ Elem += 1
+ end loop
+end func Increment_All
+// The 'concurrent' keyword in the loop header tells the compiler that
+// iterations of the loop can happen in any order.
+// It will choose the most optimal number of threads to use.
+// Other options are 'forward' and 'reverse'.
+
+func Sum_Of_Squares(N : Int) -> Int is
+ // The type of Sum is inferred
+ var Sum := 0
+ for I in 1 .. N forward loop
+ Sum += I ** 2 // ** is exponentiation
+ end loop
+end func Sum_Of_Squares
+
+func Sum_Of(N : Int; Map : func (Int) -> Int) -> Int is
+ return (for I in 1 .. N => <0> + Map(I))
+end func Sum_Of
+// It has functional aspects as well
+// Here, we're taking an (Int) -> Int function as a parameter
+// and using the inherently parallel map-reduce.
+// Initial value is enclosed with angle brackets
+
+func main(Args : Basic_Array<String>) is
+ Greetings() // Hello World
+ Println(Fib(5)) // 5
+ // Container Comprehension
+ var Vec : Vector<Int> := [for I in 0 .. 10 {I mod 2 == 0} => I ** 2]
+ // Vec = [0, 4, 16, 36, 64, 100]
+ Increment_All(Vec)
+ // Vec = [1, 5, 17, 37, 65, 101]
+ // '|' is an overloaded operator.
+ // It's usually used for concatenation or adding to a container
+ Println("First: " | Vec[1] | ", Last: " | Vec[Length(Vec)]);
+ // Vectors are 1 indexed, 0 indexed ZVectors are also available
+
+ Println(Sum_Of_Squares(3))
+
+ // Sum of fibs!
+ Println(Sum_Of(10, Fib))
+end func main
+
+// Preceding a type with 'optional' allows it to take the value 'null'
+func Divide(A, B, C : Real) -> optional Real is
+ // Real is the floating point type
+ const Epsilon := 1.0e-6;
+ if B in -Epsilon .. Epsilon then
+ return null
+ elsif C in -Epsilon .. Epsilon then
+ return null
+ else
+ return A / B + A / C
+ end if
+end func Divide
+
+// 2. Modules
+// Modules are composed of an interface and a class
+// ParaSail has object orientation features
+
+// modules can be defined as 'concurrent'
+// which allows 'locked' and 'queued' parameters
+concurrent interface Locked_Box<Content_Type is Assignable<>> is
+ // Create a box with the given content
+ func Create(C : optional Content_Type) -> Locked_Box;
+
+ // Put something into the box
+ func Put(locked var B : Locked_Box; C : Content_Type);
+
+ // Get a copy of current content
+ func Content(locked B : Locked_Box) -> optional Content_Type;
+
+ // Remove current content, leaving it null
+ func Remove(locked var B : Locked_Box) -> optional Content_Type;
+
+ // Wait until content is non-null, then return it, leaving it null.
+ func Get(queued var B : Locked_Box) -> Content_Type;
+end interface Locked_Box;
+
+concurrent class Locked_Box is
+ var Content : optional Content_Type;
+exports
+ func Create(C : optional Content_Type) -> Locked_Box is
+ return (Content => C);
+ end func Create;
+
+ func Put(locked var B : Locked_Box; C : Content_Type) is
+ B.Content := C;
+ end func Put;
+
+ func Content(locked B : Locked_Box) -> optional Content_Type is
+ return B.Content;
+ end func Content;
+
+ func Remove(locked var B : Locked_Box) -> Result : optional Content_Type is
+ // '<==' is the move operator
+ // It moves the right operand into the left operand,
+ // leaving the right null.
+ Result <== B.Content;
+ end func Remove;
+
+ func Get(queued var B : Locked_Box) -> Result : Content_Type is
+ queued until B.Content not null then
+ Result <== B.Content;
+ end func Get;
+end class Locked_Box;
+
+func Use_Box(Seed : Univ_Integer) is
+ var U_Box : Locked_Box<Univ_Integer> := Create(null);
+ // The type of 'Ran' can be left out because
+ // it is inferred from the return type of Random::Start
+ var Ran := Random::Start(Seed);
+
+ Println("Starting 100 pico-threads trying to put something in the box");
+ Println(" or take something out.");
+ for I in 1..100 concurrent loop
+ if I < 30 then
+ Println("Getting out " | Get(U_Box));
+ else
+ Println("Putting in " | I);
+ U_Box.Put(I);
+
+ // The first parameter can be moved to the front with a dot
+ // X.Foo(Y) is equivalent to Foo(X, Y)
+ end if;
+ end loop;
+
+ Println("And the winner is: " | Remove(U_Box));
+ Println("And the box is now " | Content(U_Box));
+end func Use_Box;