summaryrefslogtreecommitdiff
path: root/pycco/languages.py
blob: 29bf16d4dd6b0eaac2c18e0f5b42060fd778210c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
A list of the languages that Pycco supports, mapping the file extension to
the name of the Pygments lexer and the symbol that indicates a comment. To
add another language to Pycco's repertoire, add it here.
"""

__all__ = ("supported_languages",)

HASH = "#"
SLASH_STAR = "/*"
STAR_SLASH = "*/"
SLASH_SLASH = "//"
DASH_DASH = "--"
TRIPLE_QUOTE = '"""'

def lang(name, comment_symbol, multistart=None, multiend=None):
    """
    Generate a language entry dictionary, given a name and comment symbol and
    optional start/end strings for multiline comments.
    """
    result = {
        "name": name,
        "comment_symbol": comment_symbol
    }
    if multistart is not None and multiend is not None:
        result.update(multistart=multistart, multiend=multiend)
    return result


c_lang = lang("c", SLASH_SLASH, SLASH_STAR, STAR_SLASH)

supported_languages = {
    ".coffee": lang("coffee-script", HASH, "###", "###"),

    ".pl": lang("perl", HASH),

    ".sql": lang("sql", DASH_DASH, SLASH_STAR, STAR_SLASH),

    ".sh": lang("bash", HASH),

    ".c": c_lang,

    ".h": c_lang,

    ".cl": c_lang,

    ".cpp": lang("cpp", SLASH_SLASH),

    ".js": lang("javascript", SLASH_SLASH, SLASH_STAR, STAR_SLASH),

    ".rb": lang("ruby", HASH, "=begin", "=end"),

    ".py": lang("python", HASH, TRIPLE_QUOTE, TRIPLE_QUOTE),

    ".pyx": lang("cython", HASH, TRIPLE_QUOTE, TRIPLE_QUOTE),

    ".scm": lang("scheme", ";;", "#|", "|#"),

    ".lua": lang("lua", DASH_DASH, "--[[", "--]]"),

    ".erl": lang("erlang", "%%"),

    ".tcl": lang("tcl", HASH),

    ".hs": lang("haskell", DASH_DASH, "{-", "-}"),
}