Armin Ronacher avatar Armin Ronacher committed 95025f4 Merge

Merged

Comments (0)

Files changed (8)

 * Nick Efford -- Python 3 lexer
 * Artem Egorkine -- terminal256 formatter
 * James H. Fisher -- PostScript lexer
-* Naveen Garg - Autohotkey lexer
+* Naveen Garg -- Autohotkey lexer
 * Laurent Gautier -- R/S lexer
+* Alex Gaynor -- PyPy log lexer
 * Bertrand Goetzmann -- Groovy lexer
 * Krzysiek Goj -- Scala lexer
 * Matt Good -- Genshi, Cheetah lexers
   * Groovy (#501)
   * PostgreSQL (#660)
   * DTD
+  * Gosu
 
 - In the LaTeX formatter, escape special &, < and > chars (#648).
 

pygments/lexers/_mapping.py

     'GnuplotLexer': ('pygments.lexers.other', 'Gnuplot', ('gnuplot',), ('*.plot', '*.plt'), ('text/x-gnuplot',)),
     'GoLexer': ('pygments.lexers.compiled', 'Go', ('go',), ('*.go',), ('text/x-gosrc',)),
     'GoodDataCLLexer': ('pygments.lexers.other', 'GoodData-CL', ('gooddata-cl',), ('*.gdc',), ('text/x-gooddata-cl',)),
+    'GosuLexer': ('pygments.lexers.compiled', 'Gosu', ('gosu',), ('*.gs', '*.gsx', '*.gsp', '*.vark'), ('text/x-gosu',)),
+    'GosuTemplateLexer': ('pygments.lexers.compiled', 'Gosu Template', ('gst',), ('*.gst',), ('text/x-gosu-template',)),
     'GroffLexer': ('pygments.lexers.text', 'Groff', ('groff', 'nroff', 'man'), ('*.[1234567]', '*.man'), ('application/x-troff', 'text/troff')),
     'GroovyLexer': ('pygments.lexers.agile', 'Groovy', ('groovy',), ('*.groovy',), ('text/x-groovy',)),
     'HamlLexer': ('pygments.lexers.web', 'Haml', ('haml', 'HAML'), ('*.haml',), ('text/x-haml',)),

pygments/lexers/compiled.py

            'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer',
            'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer',
            'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer',
-           'Modula2Lexer', 'BlitzMaxLexer', 'NimrodLexer']
+           'Modula2Lexer', 'BlitzMaxLexer', 'NimrodLexer', 'GosuLexer',
+           'GosuTemplateLexer']
 
 
 class CLexer(RegexLexer):
           (r'', Text, '#pop')
         ],
     }
+
+
+class GosuLexer(RegexLexer):
+    """
+    For Gosu source code.
+
+    *New in Pygments 1.5.*
+    """
+
+    name = 'Gosu'
+    aliases = ['gosu']
+    filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark']
+    mimetypes = ['text/x-gosu']
+
+    flags = re.MULTILINE | re.DOTALL
+
+    #: optional Comment or Whitespace
+    _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
+
+    tokens = {
+        'root': [
+            # method names
+            (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # modifiers etc.
+             r'([a-zA-Z_][a-zA-Z0-9_]*)'                    # method name
+             r'(\s*)(\()',                                  # signature start
+             bygroups(using(this), Name.Function, Text, Operator)),
+            (r'[^\S\n]+', Text),
+            (r'//.*?\n', Comment.Single),
+            (r'/\*.*?\*/', Comment.Multiline),
+            (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
+            (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|'
+             r'for|index|while|do|continue|break|return|try|catch|finally|this|throw|'
+             r'new|switch|case|default|eval|super|outer|classpath|using)\b',
+             Keyword),
+            (r'(var|delegate|construct|function|private|internal|protected|public|'
+             r'abstract|override|final|static|extends|transient|implements|represents|'
+             r'readonly)\b', Keyword.Declaration),
+            (r'(property\s+)(get|set|)', Keyword.Declaration),
+            (r'(boolean|byte|char|double|float|int|long|short|void|block)\b',
+             Keyword.Type),
+            (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
+            (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant),
+            (r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Keyword.Declaration, Text, Name.Class)),
+            (r'(uses)(\s+)([a-zA-Z0-9_.]+\*?)', bygroups(Keyword.Namespace, Text, Name.Namespace)),
+            (r'"', String, 'string'),
+            (r'(\??[\.#])([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+            (r'(:)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+            (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+            (r'and|or|not|[\\~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
+            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
+            (r'[0-9]+', Number.Integer),
+            (r'\n', Text)
+        ],
+        'templateText': [
+          (r'(\\<)|(\\\$)', String),
+          (r'(<%@\s+)(extends|params)', bygroups(Operator, Name.Decorator), 'stringTemplate'),
+          (r'<%!--.*?--%>', Comment.Multiline),
+          (r'(<%)|(<%=)', Operator, 'stringTemplate'),
+          (r'\$\{', Operator, 'stringTemplateShorthand'),
+          (r'.', String)
+        ],
+        'string': [
+          (r'"', String, '#pop'),
+          include('templateText')
+        ],
+        'stringTemplate': [
+          (r'"', String, 'string'),
+          (r'%>', Operator, '#pop'),
+          include('root')
+        ],
+        'stringTemplateShorthand': [
+          (r'"', String, 'string'),
+          (r'\{', Operator, 'stringTemplateShorthand'),
+          (r'\}', Operator, '#pop'),
+          include('root')
+        ],
+    }
+
+
+class GosuTemplateLexer(Lexer):
+    """
+    For Gosu templates.
+
+    *New in Pygments 1.5.*
+    """
+
+    name = 'Gosu Template'
+    aliases = ['gst']
+    filenames = ['*.gst']
+    mimetypes = ['text/x-gosu-template']
+    lexer = GosuLexer()
+
+    def get_tokens_unprocessed(self, text):
+        stack = ['templateText']
+        for item in self.lexer.get_tokens_unprocessed(text, stack):
+            yield item
+

pygments/lexers/pypylog.py

              r"float_add|float_sub|float_mul|float_truediv|"
              r"float_eq|float_ne|float_ge|float_gt|float_le|float_lt|"
              r"ptr_eq|"
-             r"force_token|"
-             r"call_may_force|call_assembler|call|"
+             r"force_token|quasiimmut_field|same_as|virtual_ref_finish|virtual_ref|"
+             r"call_may_force|call_assembler|call_loopinvariant|call_pure|call|"
              r"new_with_vtable|new_array|newstr|newunicode|new|"
              r"arraylen_gc|"
              r"getarrayitem_gc_pure|getarrayitem_gc|setarrayitem_gc|"

pygments/lexers/web.py

             include('whitespace'),
             (r'\(:', Comment, 'comment'),
             (r'\$', Punctuation, 'varname'),
-            (r'void\s*\(\s*\)',
+            (r'(void)(\s*)(\()(\s*)(\))',
              bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'),
             (r'(element|attribute|schema-element|schema-attribute|comment|text|'
              r'node|binary|document-node|empty-sequence)(\s*)(\()',
             (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
 
             (r'(element|attribute|schema-element|schema-attribute|comment|'
-             r'text|node|document-node)(\s+)(\()',
+             r'text|node|document-node|empty-sequence)(\s+)(\()',
              pushstate_operator_kindtest_callback),
 
             (r'(processing-instruction)(\s+)(\()',

tests/examplefiles/example.gs

+package example
+
+uses java.util.*
+
+uses java.io.File
+
+class Person extends Contact implements IEmailable {
+
+  var _name : String
+  var _age : Integer as Age 
+  var _relationship : Relationship as readonly RelationshipOfPerson
+
+  delegate _emailHelper represents IEmailable
+
+  enum Relationship {
+    FRIEND,
+    FAMILY,
+    BUSINESS_CONTACT
+  }
+
+  // Map of names to people
+  static var ALL_PEOPLE = new HashMap<String, Person>()
+
+  /* Constructs a new Person */
+  construct( name : String, age : Integer, relationship : Relationship ) {
+    _name = name
+    _age = age
+    _relationship = relationship
+    _emailHelper = new EmailHelper( this )
+  }
+
+  property get Name():String{
+    return _name
+  }
+
+  property set Name(name : String){
+    _name = name
+  }
+
+  /* Implement IEmailable#getEmailName() */
+  override function getEmailName():String{
+    return Name
+  }
+
+  function incrementAge() {
+    _age++
+  }
+
+  @Deprecated
+  function printPersonInfo() {
+    print( "Person { Name : ${Name}, Age : ${Age}, Relationship : ${RelationshipOfPerson} }" )
+  }
+
+  static function addPerson(p : Person){
+    if(ALL_PEOPLE.containsKey(p?.Name)) {
+      throw new IllegalArgumentException( "There is already someone named '${p.Name}'." )
+    }
+    ALL_PEOPLE[p.Name] = p
+  }
+
+  static function addAllPeople( contacts : List<Contact> ) {
+    for( contact in contacts ) {
+      if( contact typeis Person and not ALL_PEOPLE.containsKey( contact.Name )) {
+        addPerson( contact )
+      }
+    }
+  }
+
+  static function getAllPeopleOlderThanNOrderedByName( age : int ) {
+    var allPeople = ALL_PEOPLE.Values
+
+    return allPeople.where( \ p -> p.Age > age ).orderBy( \ p -> p.Name )
+  }
+
+  static function loadPersonFromDB( id : Integer ) {
+    using( var conn = DBConnectionManager.getConnection(),
+      var stmt = conn.prepareStatement( "SELECT name, age, relationship FROM PEOPLE WHERE ID=?") ){
+
+      stmt.setInt( 0, 0 )
+      var result = stmt.executeQuery()
+      if( result.next() ) {
+         addPerson( new Person( result.getString( "name" ),
+                    result.getInt( "age" ),
+                    Relationship.valueOf( result.getString( "relationship" ) ) ) )
+
+      }
+    }
+  }
+
+  /* Loads in people from a CSV */
+  static function loadFromFile( file : File ) {
+    file.eachLine( \ line -> {
+      if( line.HasContent ) {
+        addPerson( line.toPerson() )
+      }
+    })
+  }
+
+  /* Save people to a CSV */
+  static function saveToFile( file : File ) {
+    using( var writer = new FileWriter( file ) ) {
+      print( PersonCSVTemplate.renderToString( ALL_PEOPLE.Values ) )
+      PersonCSVTemplate.render( writer, ALL_PEOPLE.Values )
+    }
+  }
+}

tests/examplefiles/example.gst

+<%!-- defined in example/PersonCSVTemplate.gst --%>
+
+<%@ params( users : Collection <User> ) %>
+
+<%  for( user in users ) { %>
+
+${user.LastName}, ${user.FirstName}, ${user.Department}  <%  } %>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.