-
Notifications
You must be signed in to change notification settings - Fork 11
/
languages.nim
63 lines (55 loc) · 1.74 KB
/
languages.nim
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
import nimscript/common
const
sourceLanguageToStr*: array[SourceLanguage, string] = ["none",
"Nim", "C++", "C#", "C", "Java", "JavaScript", "XML", "HTML", "Console"]
additionalIndentChars*: array[SourceLanguage, set[char]] = [
langNone: {},
langNim: {'(', '[', '{', ':', '='},
langCpp: {'(', '[', '{'},
langCsharp: {'(', '[', '{'},
langC: {'(', '[', '{'},
langJava: {'(', '[', '{'},
langJs: {'(', '[', '{'},
langXml: {'>'},
langHtml: {'>'},
langConsole: {}]
from strutils import toLowerAscii, cmpIgnoreStyle
proc getSourceLanguage*(name: string): SourceLanguage =
for i in countup(succ(low(SourceLanguage)), high(SourceLanguage)):
if cmpIgnoreStyle(name, sourceLanguageToStr[i]) == 0:
return i
result = langNone
proc fileExtToLanguage*(ext: string): SourceLanguage =
case ext.toLowerAscii
of ".nim", ".nims": langNim
of ".cpp", ".hpp", ".cxx", ".h": langCpp
of ".c": langC
of ".js": langJs
of ".java": langJava
of ".cs": langCsharp
of ".xml": langXml
of ".html", ".htm": langHtml
else: langNone
type
InterestingControlflowEnum* = enum
isUninteresting, isIf, isCase, isDecl
proc interestingControlflow*(lang: SourceLanguage;
word: string): InterestingControlflowEnum =
case lang
of langNone, langConsole: isUninteresting
of langNim:
case word
of "case": isCase
of "if", "while", "for", "when": isIf
of "proc", "template", "method", "macro", "converter", "func", "iterator":
isDecl
else:
isUninteresting
of langCpp, langCsharp, langC, langJs, langJava:
case word
of "class", "struct": isDecl
of "if", "for", "while": isIf
of "switch": isCase
else:
isUninteresting
of langXml, langHtml: isIf