summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-06-07 23:49:52 -0700
committerTim Hatch <tim@timhatch.com>2014-06-07 23:49:52 -0700
commit2f1c724903db081f1d6941d366ca95070049e94b (patch)
tree3f43531b55424c456c977fb809f773aec36dace0
parent712d327c39efd6109d6919657e21ae5cd1a15414 (diff)
parent68c8011b8980c91a74f4625a96fa0fa946fb7b67 (diff)
downloadpygments-2f1c724903db081f1d6941d366ca95070049e94b.tar.gz
Merged in megajoule/pygments-main (pull request #372)
Update ElixirLexer and ElixirConsoleLexer
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/compiled.py43
-rw-r--r--pygments/lexers/functional.py12
-rw-r--r--pygments/lexers/templates.py213
-rw-r--r--tests/examplefiles/example.liquid42
-rw-r--r--tests/examplefiles/r6rs-comments.scm23
-rw-r--r--tests/examplefiles/test.swift65
7 files changed, 395 insertions, 5 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 70159bdb..f8454357 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -191,6 +191,7 @@ LEXERS = {
'LassoXmlLexer': ('pygments.lexers.templates', 'XML+Lasso', ('xml+lasso',), (), ('application/xml+lasso',)),
'LighttpdConfLexer': ('pygments.lexers.text', 'Lighttpd configuration file', ('lighty', 'lighttpd'), (), ('text/x-lighttpd-conf',)),
'LimboLexer': ('pygments.lexers.inferno', 'Limbo', ('limbo',), ('*.b',), ('text/limbo',)),
+ 'LiquidLexer': ('pygments.lexers.templates', 'liquid', ('liquid',), ('*.liquid',), ()),
'LiterateAgdaLexer': ('pygments.lexers.functional', 'Literate Agda', ('lagda', 'literate-agda'), ('*.lagda',), ('text/x-literate-agda',)),
'LiterateCryptolLexer': ('pygments.lexers.functional', 'Literate Cryptol', ('lcry', 'literate-cryptol', 'lcryptol'), ('*.lcry',), ('text/x-literate-cryptol',)),
'LiterateHaskellLexer': ('pygments.lexers.functional', 'Literate Haskell', ('lhs', 'literate-haskell', 'lhaskell'), ('*.lhs',), ('text/x-literate-haskell',)),
@@ -322,6 +323,7 @@ LEXERS = {
'SquidConfLexer': ('pygments.lexers.text', 'SquidConf', ('squidconf', 'squid.conf', 'squid'), ('squid.conf',), ('text/x-squidconf',)),
'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)),
'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()),
+ 'SwiftLexer': ('pygments.lexers.compiled', 'Swift', ('swift',), ('*.swift',), ('text/x-swift',)),
'SwigLexer': ('pygments.lexers.compiled', 'SWIG', ('swig',), ('*.swg', '*.i'), ('text/swig',)),
'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')),
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 46990510..25c7a4d8 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -32,7 +32,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer',
'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
'CobolFreeformatLexer', 'LogosLexer', 'ClayLexer', 'PikeLexer',
'ChapelLexer', 'EiffelLexer', 'Inform6Lexer', 'Inform7Lexer',
- 'Inform6TemplateLexer', 'MqlLexer']
+ 'Inform6TemplateLexer', 'MqlLexer', 'SwiftLexer']
class CFamilyLexer(RegexLexer):
@@ -5149,3 +5149,44 @@ class MqlLexer(CppLexer):
inherit,
],
}
+
+class SwiftLexer(ObjectiveCLexer):
+ """
+ For `Swift <https://developer.apple.com/swift/>`_ source.
+ """
+ name = 'Swift'
+ filenames = ['*.swift']
+ aliases = ['swift']
+ mimetypes = ['text/x-swift']
+
+ keywords_decl = ['class', 'deinit', 'enum', 'extension', 'func', 'import',
+ 'init', 'let', 'protocol', 'static', 'struct', 'subscript',
+ 'typealias', 'var']
+ keywords_stmt = ['break', 'case', 'continue', 'default', 'do', 'else',
+ 'fallthrough', 'if', 'in', 'for', 'return', 'switch',
+ 'where', 'while']
+ keywords_type = ['as', 'dynamicType', 'is', 'new', 'super', 'self', 'Self',
+ 'Type', '__COLUMN__', '__FILE__', '__FUNCTION__',
+ '__LINE__']
+ keywords_resrv = ['associativity', 'didSet', 'get', 'infix', 'inout', 'left',
+ 'mutating', 'none', 'nonmutating', 'operator', 'override',
+ 'postfix', 'precedence', 'prefix', 'right', 'set',
+ 'unowned', 'unowned(safe)', 'unowned(unsafe)', 'weak',
+ 'willSet']
+ operators = ['->']
+
+ def get_tokens_unprocessed(self, text):
+ for index, token, value in \
+ ObjectiveCLexer.get_tokens_unprocessed(self, text):
+ if token is Name:
+ if value in self.keywords_decl:
+ token = Keyword
+ elif value in self.keywords_stmt:
+ token = Keyword
+ elif value in self.keywords_type:
+ token = Keyword.Type
+ elif value in self.keywords_resrv:
+ token = Keyword.Reserved
+ elif value in self.operators:
+ token = Operator
+ yield index, token, value
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index f4342d3c..a22c4f55 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -999,11 +999,16 @@ class SchemeLexer(RegexLexer):
tokens = {
'root' : [
- # the comments - always starting with semicolon
+ # the comments
# and going to the end of the line
(r';.*$', Comment.Single),
# multi-line comment
(r'#\|', Comment.Multiline, 'multiline-comment'),
+ # commented form (entire sexpr folliwng)
+ (r'#;\s*\(', Comment, 'commented-form'),
+ # signifies that the program text that follows is written with the
+ # lexical and datum syntax described in r6rs
+ (r'#!r6rs', Comment),
# whitespaces - usually not relevant
(r'\s+', Text),
@@ -1058,6 +1063,11 @@ class SchemeLexer(RegexLexer):
(r'[^|#]+', Comment.Multiline),
(r'[|#]', Comment.Multiline),
],
+ 'commented-form' : [
+ (r'\(', Comment, '#push'),
+ (r'\)', Comment, '#pop'),
+ (r'[^()]+', Comment),
+ ],
}
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py
index 50579c61..8d91d9d0 100644
--- a/pygments/lexers/templates.py
+++ b/pygments/lexers/templates.py
@@ -18,9 +18,10 @@ from pygments.lexers.compiled import JavaLexer
from pygments.lexers.jvm import TeaLangLexer
from pygments.lexers.text import YamlLexer
from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \
- include, using, this, default
+ include, using, this, default, combined
from pygments.token import Error, Punctuation, \
- Text, Comment, Operator, Keyword, Name, String, Number, Other, Token
+ Text, Comment, Operator, Keyword, Name, String, Number, Other, Token, \
+ Whitespace
from pygments.util import html_doctype_matches, looks_like_xml
__all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer',
@@ -41,7 +42,7 @@ __all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer',
'VelocityHtmlLexer', 'VelocityXmlLexer', 'SspLexer',
'TeaTemplateLexer', 'LassoHtmlLexer', 'LassoXmlLexer',
'LassoCssLexer', 'LassoJavascriptLexer', 'HandlebarsLexer',
- 'HandlebarsHtmlLexer', 'YamlJinjaLexer']
+ 'HandlebarsHtmlLexer', 'YamlJinjaLexer', 'LiquidLexer']
class ErbLexer(Lexer):
@@ -1851,3 +1852,209 @@ class YamlJinjaLexer(DelegatingLexer):
def __init__(self, **options):
super(YamlJinjaLexer, self).__init__(YamlLexer, DjangoLexer, **options)
+
+
+class LiquidLexer(RegexLexer):
+ """
+ Lexer for `Liquid templates
+ <http://www.rubydoc.info/github/Shopify/liquid>`_.
+
+ .. versionadded:: 2.0
+ """
+ name = 'liquid'
+ aliases = ['liquid']
+ filenames = ['*.liquid']
+
+ tokens = {
+ 'root': [
+ (r'[^{]+', Text),
+ # tags and block tags
+ (r'(\{%)(\s*)', bygroups(Punctuation, Whitespace), 'tag-or-block'),
+ # output tags
+ (r'({{)(\s*)([^\s}]+)',
+ bygroups(Punctuation, Whitespace, using(this, state = 'generic')),
+ 'output'),
+ (r'{', Text)
+ ],
+
+ 'tag-or-block': [
+ # builtin logic blocks
+ (r'(if|unless|elsif|case)(?=\s+)', Keyword.Reserved, 'condition'),
+ (r'(when)(\s+)', bygroups(Keyword.Reserved, Whitespace),
+ combined('end-of-block', 'whitespace', 'generic')),
+ (r'(else)(\s*)(%\})',
+ bygroups(Keyword.Reserved, Whitespace, Punctuation), '#pop'),
+
+ # other builtin blocks
+ (r'(capture)(\s+)([^\s%]+)(\s*)(%\})',
+ bygroups(Name.Tag, Whitespace, using(this, state = 'variable'),
+ Whitespace, Punctuation), '#pop'),
+ (r'(comment)(\s*)(%\})',
+ bygroups(Name.Tag, Whitespace, Punctuation), 'comment'),
+ (r'(raw)(\s*)(%\})',
+ bygroups(Name.Tag, Whitespace, Punctuation), 'raw'),
+
+ # end of block
+ (r'(end(case|unless|if))(\s*)(%\})',
+ bygroups(Keyword.Reserved, None, Whitespace, Punctuation), '#pop'),
+ (r'(end([^\s%]+))(\s*)(%\})',
+ bygroups(Name.Tag, None, Whitespace, Punctuation), '#pop'),
+
+ # builtin tags (assign and include are handled together with usual tags)
+ (r'(cycle)(\s+)(?:([^\s:]*)(:))?(\s*)',
+ bygroups(Name.Tag, Whitespace,
+ using(this, state='generic'), Punctuation, Whitespace),
+ 'variable-tag-markup'),
+
+ # other tags or blocks
+ (r'([^\s%]+)(\s*)', bygroups(Name.Tag, Whitespace), 'tag-markup')
+ ],
+
+ 'output': [
+ include('whitespace'),
+ ('\}\}', Punctuation, '#pop'), # end of output
+
+ (r'\|', Punctuation, 'filters')
+ ],
+
+ 'filters': [
+ include('whitespace'),
+ (r'\}\}', Punctuation, ('#pop', '#pop')), # end of filters and output
+
+ (r'([^\s\|:]+)(:?)(\s*)',
+ bygroups(Name.Function, Punctuation, Whitespace), 'filter-markup')
+ ],
+
+ 'filter-markup': [
+ (r'\|', Punctuation, '#pop'),
+ include('end-of-tag'),
+ include('default-param-markup')
+ ],
+
+ 'condition': [
+ include('end-of-block'),
+ include('whitespace'),
+
+ (r'([^\s=!><]+)(\s*)([=!><]=?)(\s*)(\S+)(\s*)(%\})',
+ bygroups(using(this, state = 'generic'), Whitespace, Operator,
+ Whitespace, using(this, state = 'generic'), Whitespace,
+ Punctuation)),
+ (r'\b!', Operator),
+ (r'\bnot\b', Operator.Word),
+ (r'([\w\.\'"]+)(\s+)(contains)(\s+)([\w\.\'"]+)',
+ bygroups(using(this, state = 'generic'), Whitespace, Operator.Word,
+ Whitespace, using(this, state = 'generic'))),
+
+ include('generic'),
+ include('whitespace')
+ ],
+
+ 'generic-value': [
+ include('generic'),
+ include('end-at-whitespace')
+ ],
+
+ 'operator': [
+ (r'(\s*)((=|!|>|<)=?)(\s*)',
+ bygroups(Whitespace, Operator, None, Whitespace), '#pop'),
+ (r'(\s*)(\bcontains\b)(\s*)',
+ bygroups(Whitespace, Operator.Word, Whitespace), '#pop'),
+ ],
+
+ 'end-of-tag': [
+ (r'\}\}', Punctuation, '#pop')
+ ],
+
+ 'end-of-block': [
+ (r'%\}', Punctuation, ('#pop', '#pop'))
+ ],
+
+ 'end-at-whitespace': [
+ (r'\s+', Whitespace, '#pop')
+ ],
+
+ # states for unknown markup
+ 'param-markup': [
+ include('whitespace'),
+ # params with colons or equals
+ (r'([^\s=:]+)(\s*)(=|:)',
+ bygroups(Name.Attribute, Whitespace, Operator)),
+ # explicit variables
+ (r'(\{\{)(\s*)([^\s\}])(\s*)(\}\})',
+ bygroups(Punctuation, Whitespace, using(this, state = 'variable'),
+ Whitespace, Punctuation)),
+
+ include('string'),
+ include('number'),
+ include('keyword'),
+ (r',', Punctuation)
+ ],
+
+ 'default-param-markup': [
+ include('param-markup'),
+ (r'.', Text) # fallback for switches / variables / un-quoted strings / ...
+ ],
+
+ 'variable-param-markup': [
+ include('param-markup'),
+ include('variable'),
+ (r'.', Text) # fallback
+ ],
+
+ 'tag-markup': [
+ (r'%\}', Punctuation, ('#pop', '#pop')), # end of tag
+ include('default-param-markup')
+ ],
+
+ 'variable-tag-markup': [
+ (r'%\}', Punctuation, ('#pop', '#pop')), # end of tag
+ include('variable-param-markup')
+ ],
+
+ # states for different values types
+ 'keyword': [
+ (r'\b(false|true)\b', Keyword.Constant)
+ ],
+
+ 'variable': [
+ (r'[a-zA-Z_]\w*', Name.Variable),
+ (r'(?<=\w)\.(?=\w)', Punctuation)
+ ],
+
+ 'string': [
+ (r"'[^']*'", String.Single),
+ (r'"[^"]*"', String.Double)
+ ],
+
+ 'number': [
+ (r'\d+\.\d+', Number.Float),
+ (r'\d+', Number.Integer)
+ ],
+
+ 'generic': [ # decides for variable, string, keyword or number
+ include('keyword'),
+ include('string'),
+ include('number'),
+ include('variable')
+ ],
+
+ 'whitespace': [
+ (r'[ \t]+', Whitespace)
+ ],
+
+ # states for builtin blocks
+ 'comment': [
+ (r'(\{%)(\s*)(endcomment)(\s*)(%\})',
+ bygroups(Punctuation, Whitespace, Name.Tag, Whitespace,
+ Punctuation), ('#pop', '#pop')),
+ (r'.', Comment)
+ ],
+
+ 'raw': [
+ (r'[^\{]+', Text),
+ (r'(\{%)(\s*)(endraw)(\s*)(%\})',
+ bygroups(Punctuation, Whitespace, Name.Tag, Whitespace,
+ Punctuation), '#pop'),
+ (r'\{', Text)
+ ]
+ }
diff --git a/tests/examplefiles/example.liquid b/tests/examplefiles/example.liquid
new file mode 100644
index 00000000..8f3ea9e9
--- /dev/null
+++ b/tests/examplefiles/example.liquid
@@ -0,0 +1,42 @@
+# This is an example file. Process it with `./pygmentize -O full -f html -o /liquid-example.html example.liquid`.
+
+{% raw %}
+some {{raw}} liquid syntax
+
+{% raw %}
+{% endraw %}
+
+Just regular text - what happens?
+
+{% comment %}My lovely {{comment}} {% comment %}{% endcomment %}
+
+{% custom_tag params: true %}
+{% custom_block my="abc" c = false %}
+ Just usual {{liquid}}.
+{% endcustom_block %}
+
+{% another_tag "my string param" %}
+
+{{ variable | upcase }}
+{{ var.field | textilize | markdownify }}
+{{ var.field.property | textilize | markdownify }}
+{{ 'string' | truncate: 100 param='df"g' }}
+
+{% cycle '1', 2, var %}
+{% cycle 'group1': '1', var, 2 %}
+{% cycle group2: '1', var, 2 %}
+
+{% if a == 'B' %}
+{% elsif a == 'C%}' %}
+{% else %}
+{% endif %}
+
+{% unless not a %}
+{% else %}
+{% endunless %}
+
+{% case a %}
+{% when 'B' %}
+{% when 'C' %}
+{% else %}
+{% endcase %} \ No newline at end of file
diff --git a/tests/examplefiles/r6rs-comments.scm b/tests/examplefiles/r6rs-comments.scm
new file mode 100644
index 00000000..cd5c3636
--- /dev/null
+++ b/tests/examplefiles/r6rs-comments.scm
@@ -0,0 +1,23 @@
+#!r6rs
+
+#|
+
+ The FACT procedure computes the factorial
+
+ of a non-negative integer.
+
+|#
+
+(define fact
+
+ (lambda (n)
+
+ ;; base case
+
+ (if (= n 0)
+
+ #;(= n 1)
+
+ 1 ; identity of *
+
+ (* n (fact (- n 1))))))
diff --git a/tests/examplefiles/test.swift b/tests/examplefiles/test.swift
new file mode 100644
index 00000000..8ef19763
--- /dev/null
+++ b/tests/examplefiles/test.swift
@@ -0,0 +1,65 @@
+//
+// test.swift
+// from https://github.com/fullstackio/FlappySwift
+//
+// Created by Nate Murray on 6/2/14.
+// Copyright (c) 2014 Fullstack.io. All rights reserved.
+//
+
+import UIKit
+import SpriteKit
+
+extension SKNode {
+ class func unarchiveFromFile(file : NSString) -> SKNode? {
+
+ let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks")
+
+ var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil)
+ var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
+
+ archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
+ let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as GameScene
+ archiver.finishDecoding()
+ return scene
+ }
+}
+
+class GameViewController: UIViewController {
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
+ // Configure the view.
+ let skView = self.view as SKView
+ skView.showsFPS = true
+ skView.showsNodeCount = true
+
+ /* Sprite Kit applies additional optimizations to improve rendering performance */
+ skView.ignoresSiblingOrder = true
+
+ /* Set the scale mode to scale to fit the window */
+ scene.scaleMode = .AspectFill
+
+ skView.presentScene(scene)
+ }
+ }
+
+ override func shouldAutorotate() -> Bool {
+ return true
+ }
+
+ override func supportedInterfaceOrientations() -> Int {
+ if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
+ return Int(UIInterfaceOrientationMask.AllButUpsideDown.toRaw())
+ } else {
+ return Int(UIInterfaceOrientationMask.All.toRaw())
+ }
+ }
+
+ override func didReceiveMemoryWarning() {
+ super.didReceiveMemoryWarning()
+ // Release any cached data, images, etc that aren't in use.
+ }
+
+}