-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.yaml
183 lines (160 loc) · 4.5 KB
/
source.yaml
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
scope:
regex: <tab>#(<var>)#(<lines>)$
tokens: [tab,name,statement]
statement:
eachline: <tab> <line>
doc: Implentation of scope(like in javascript)(Syntax:#name#<statement_in_new_line>)
notdefined:
regex: (<var>)\s*\|\|\s*(.+)(?:$|\))
tokens: [var,value]
doc: if variable is defined return variable otherwise a value(var||value)
chk_defined:
regex: "!(<var>)"
tokens: [var]
doc: Return False if variable is not defined (!variable)
pipe:
regex: <tab>(<var>)\s*<-\s*(.+)$
tokens: [tab,f1,f2]
f2:
call: [pipe]
doc: Pass output from one function to another function as input(fun1<-fun2())
print:
regex: <tab>p(".*")$
tokens: [tab,str]
doc: Print string (p"")
arrow_multline:
regex: <args>\s*=>\s*{<i1>3<i2>}
tokens: [args,statement]
doc: Multiline arrow function(like in javascript)
statement:
call: [arrow_multline]
replace:
- [^(\t)*]
- [^\n(\t)*]
- [\n\t,\n]
- [\\n\\t,\\n]
- [\n$]
- [\n\t$]
- [\t,\\t]
- [\n,\\n]
- ["'''",\\\''']
- ['"""',"'''"]
fun_operation:
regex: \((<var>(?:<op><var>)+)\)<args>
tokens: [funs,val]
funs:
replace:
- [(<var>),\1(<val>)]
doc: To add functions((fun1+fun2)(arg))
arrow2list:
regex: (<var>)\s*=>\s*(.+)$
tokens: [fun,list]
doc: Function to list
arrow_fun:
regex: <tab>(<var>)<bracket>\s*=\s*(.+)$
tokens: [tab,name,args,statement]
doc: Map function to list (fun=>list)
arrow:
regex: \(([^\(]+)\)\s*=>\s*(.+)$
tokens: [arg,statement]
doc: To create lambda function ((args)=>statement)
fun:
regex: fun\s([A-Za-z_]+)
tokens: [name]
doc: def into fun
single_try:
regex: <tab>try (.+) (.+) (.+)$
tokens: [tab,try_state,err,except_state]
doc: Singleline error handling(try statement exception_class statement)
itself:
regex: <tab>=(<var>)\.(.+)$
tokens: [tab,var,rest]
doc: Assign return value to same variable after operation(=variable.function())
ternary:
regex: (=\s*|\()(.+)\?(.+):(.+)($|\))
tokens: [start,bol,tru,fals,end]
doc: Ternary operation(expression?true_statement:false_statement)
bol,tru,fals:
replace:
- [<lstrip>]
- [<rstrip>]
condition:
regex: <tab>(<var>)<bracket> if (.+)$
tokens: [tab,name,args,bol]
doc: Call function if expression is true(function() if expression)
#Some Haskell Syntax
jrange:
regex: (\d+),(\d+)\.\.(\d+)
tokens: [jump,start,end]
doc: Range of numbers with jump (jump,start..end)
range:
regex: (,*)(\d+)\.\.(\d+)
tokens: [comma,start,end]
doc: Range of numbers (start..end)
comma:
replace:
- ["^,",",*"]
#-----------------------
listrange:
regex: "!\\[(.+)\\]"
tokens: [inside]
doc: To change into list (![variable/generator/function])
inside:
call: [jrange,range]
multiline_flow:
regex: \n\t*\|>(.+)$
tokens: [statements]
doc: Multiline piping
statements:
call: [flow]
flow:
regex: <tab><narrow>\s*->\s*<narrow>\s*->
tokens: [tab,arg,fun]
doc: To write flow pipe(fun1->fun2->fun3)
endflow:
regex: <tab><narrow>\s*->\s*(.+)$
tokens: [tab,arg,fun]
doc: To write flow pipe(fun1->fun2)
make_dict:
regex: <tab>make dict (<var>):<tablock>
tokens: [tab,name,tab2,block]
block:
replace:
- [\n\n$,\n]
- [\bpass\b,return locals()]
make:
regex: <tab>make (<var>) (<var>)<bracket>:<tablock>
tokens: [tab,callable,name,tuple,tab2,block]
doc: PEP 359 - make statement
block:
replace:
- [\n\n$,\n]
- [\bpass\b,return locals()]
tuple:
replace:
- [(\w)$,'\1,']
__make:
regex: <tab>make (<var>) (<var>)():<tablock>
block:
replace:
- [\n\n$,\n]
- [\bpass\b,return locals()]
settings:
variables:
tab: ^((?:(?:\t|\s)+)*) # For tab
lstip: "^\\s{1,}" # Remove space in left
rstrip: "\\s{1,}$" # Remove space in right
var: \w+ # Variable/Function Names
bracket: \((.*)\) # Get content inside bracket
spvar: \s*\w+\s* # Variable Name with space around
args: \((<spvar>(?:,<spvar>)*)\) # To get arguments
i1: (\n(?:(?:(?:\t|\s)+)+?).*(?:(?:\n\\ # For multiline
i2: .*)*\n*)*) # End multline
op: (?:\+|-|\*|\\) #Arthematic Operators
narrow: ((?:(?!\s*->).)+) #Not arrow
line: (?:\n.+) # For single line
lines: <line>+ # For multiple lines
# To get indentation level and block of statements
tablock: .*(\n(?:(?:\t|\s)+)+)(.+<line>*)
author: Name
lang: Python