Lines Matching refs:stack
287 " Push a token onto the parser's stack.
289 " stack: [token]
291 function! s:Push(stack, token) argument
292 call s:Log(' Stack Push: "' . a:token . '" into ' . string(a:stack))
293 call insert(a:stack, a:token)
297 " Pop a token from the parser's stack.
299 " stack: [token]
303 function! s:Pop(stack) argument
304 let head = remove(a:stack, 0)
305 call s:Log(' Stack Pop: "' . head . '" from ' . string(a:stack))
466 " stack: [token]
469 function! s:IndentError(msg, token, stack) argument
472 \' stack = ' . string(a:stack))
485 " stack: [token]
488 function! s:UnexpectedToken(token, stack) argument
489 call s:Log(' Unexpected token ' . a:token . ', stack = ' .
490 \string(a:stack) . ' -> return')
592 " '[', '<<', etc.) is found. It asks the caller to return if the stack
594 " stack: [token]
604 function! s:BeginElementFoundIfEmpty(stack, token, curr_vcol, stored_vcol, sw) argument
605 if empty(a:stack)
622 " It asks the caller to return if the stack is already empty.
624 " stack: [token]
636 function! s:BeginElementFound(stack, token, curr_vcol, stored_vcol, end_token, sw) argument
638 " Return 'return' if the stack is empty
639 let [ret, res] = s:BeginElementFoundIfEmpty(a:stack, a:token, a:curr_vcol,
643 if a:stack[0] ==# a:end_token
645 call s:Pop(a:stack)
646 if !empty(a:stack) && a:stack[0] ==# 'align_to_begin_element'
647 call s:Pop(a:stack)
648 if empty(a:stack)
651 return [1, s:UnexpectedToken(a:token, a:stack)]
657 return [1, s:UnexpectedToken(a:token, a:stack)]
666 " If the stack contains an '->' or 'when', this means that we can return
669 " stack: [token]
679 function! s:BeginningOfClauseFound(stack, token, stored_vcol, lnum, i) argument
680 if !empty(a:stack) && a:stack[0] ==# 'when'
681 call s:Log(' BeginningOfClauseFound: "when" found in stack')
682 call s:Pop(a:stack)
683 if empty(a:stack)
687 return [1, s:UnexpectedToken(a:token, a:stack)]
689 elseif !empty(a:stack) && a:stack[0] ==# '->'
690 call s:Log(' BeginningOfClauseFound: "->" found in stack')
691 call s:Pop(a:stack)
692 if empty(a:stack)
695 elseif a:stack[0] ==# ';'
696 call s:Pop(a:stack)
698 if !empty(a:stack)
699 return [1, s:UnexpectedToken(a:token, a:stack)]
737 return [1, s:UnexpectedToken(a:token, a:stack)]
775 " stack: [token] -- initial stack
780 function! s:ErlangCalcIndent(lnum, stack) argument
781 let res = s:ErlangCalcIndent2(a:lnum, a:stack)
786 function! s:ErlangCalcIndent2(lnum, stack) argument
792 let stack = a:stack
803 let [ret, res] = s:BeginningOfClauseFound(stack, 'beginning_of_file',
818 if len(stack) > 256 " TODO: magic number
819 return s:IndentError('Stack too long', token, stack)
823 let [ret, res] = s:BeginningOfClauseFound(stack, token, stored_vcol,
835 elseif stack == ['prev_term_plus']
845 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
863 \ (empty(stack) || stack ==# ['when'] || stack ==# ['->'] ||
864 \ stack ==# ['->', ';'])
869 " % stack == []
873 " % stack == ['->', ';']
878 " % stack == ['->']
882 " % stack == ['when']
886 " stack = [] => LTI is a condition
887 " stack = ['->'] => LTI is a branch
888 " stack = ['->', ';'] => LTI is a condition
889 " stack = ['when'] => LTI is a guard
890 if empty(stack) || stack == ['->', ';']
894 elseif stack == ['->']
898 elseif stack == ['when']
903 return s:UnexpectedToken(token, stack)
908 " stack = [] => LTI is a condition
909 " stack = ['->'] => LTI is a branch
910 " stack = ['->', ';'] => LTI is a condition
911 " stack = ['when'] => LTI is in a guard
912 if empty(stack)
914 elseif (token ==# 'case' && stack[0] ==# 'of') ||
916 \ (token ==# 'try' && (stack[0] ==# 'of' ||
917 \ stack[0] ==# 'catch' ||
918 \ stack[0] ==# 'after')) ||
923 " when we reached these tokens, and the stack already had
928 " stack.
930 \ (token ==# 'receive' && stack[0] ==# 'after')
931 call s:Pop(stack)
934 if empty(stack)
938 elseif stack[0] ==# 'align_to_begin_element'
939 call s:Pop(stack)
941 elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
944 call s:Pop(stack)
945 call s:Pop(stack)
947 elseif stack[0] ==# '->'
950 call s:Pop(stack)
952 elseif stack[0] ==# 'when'
955 call s:Pop(stack)
961 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
982 " stack = [] => LTI is a condition
983 " stack = ['->'] => LTI is a branch
984 " stack = ['->', ';'] => LTI is a condition
985 " stack = ['when'] => LTI is in a guard
986 if empty(stack)
989 elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
991 call s:Pop(stack)
992 call s:Pop(stack)
993 elseif stack[0] ==# '->'
995 call s:Pop(stack)
997 elseif stack[0] ==# 'when'
999 call s:Pop(stack)
1003 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
1012 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
1018 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
1027 if empty(stack)
1030 elseif stack[0] ==# end_token
1032 call s:Pop(stack)
1034 if !empty(stack) && stack[0] ==# 'align_to_begin_element'
1040 " was already in the stack.
1044 return s:UnexpectedToken(token, stack)
1070 let stack = ['prev_term_plus']
1148 " just push the token onto the stack and keep parsing.
1152 call s:Push(stack, token)
1156 call s:Push(stack, token)
1163 \token, stack)
1180 call s:Push(stack, token)
1193 \token, stack)
1214 if empty(stack)
1215 call s:Push(stack, ';')
1217 \stack[0]) != -1
1220 " - If the stack top is another ';', then one ';' is
1222 " - If the stack top is an '->' or a 'when', then we
1227 " if the stack already has a catch/after/end, we don't
1230 " the stack.
1232 return s:UnexpectedToken(token, stack)
1237 if empty(stack) && !last_token_of_line
1240 elseif empty(stack) || stack[0] ==# ';' || stack[0] ==# 'end'
1241 " stack = [';'] -> LTI is either a branch or in a guard
1242 " stack = ['->'] -> LTI is a condition
1243 " stack = ['->', ';'] -> LTI is a branch
1244 call s:Push(stack, '->')
1245 elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
1248 " - If the stack top is another '->', then one '->' is
1250 " - If the stack top is a 'when', then we should keep
1254 " if the stack already has a catch/after/end, we don't
1257 " the stack.
1259 return s:UnexpectedToken(token, stack)
1264 " Pop all ';' from the top of the stack
1265 while !empty(stack) && stack[0] ==# ';'
1266 call s:Pop(stack)
1269 if empty(stack)
1277 let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
1284 call s:Push(stack, token)
1286 elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
1288 " - If the stack top is another 'when', then one 'when' is
1290 " - If the stack top is an '->' or a 'when', then we
1295 " if the stack already has a catch/after/end, we don't
1298 " the stack.
1300 return s:UnexpectedToken(token, stack)
1309 let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
1314 if empty(stack) || stack[0] ==# '->' || stack[0] ==# 'when'
1315 call s:Push(stack, token)
1316 elseif stack[0] ==# 'catch' || stack[0] ==# 'after' || stack[0] ==# 'end'
1319 " if the stack already has a catch/after/end, we don't
1322 " the stack.
1324 return s:UnexpectedToken(token, stack)
1327 elseif token ==# '||' && empty(stack) && !last_token_of_line
1333 call s:Log(' Misc token, stack unchanged = ' . string(stack))
1337 if empty(stack) || stack[0] ==# '->' || stack[0] ==# 'when'
1340 call s:Log(' Misc token when the stack is empty or has "->" ' .
1342 elseif stack[0] ==# ';'
1356 if empty(stack) && stored_vcol != -1 &&
1359 call s:Log(' Empty stack at the beginning of the line -> return')