diff --git a/.vim/indent/kyn.vim b/.vim/indent/kyn.vim new file mode 100644 index 0000000..83df688 --- /dev/null +++ b/.vim/indent/kyn.vim @@ -0,0 +1,52 @@ +" Vim indent file +" Language: Kyn +" Maintainer: Gemini + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetKynIndent() +setlocal indentkeys+=={,},0) + +let b:undo_indent = "setlocal indentexpr< indentkeys<" + +" Only define the function once +if exists("*GetKynIndent") + finish +endif + +function GetKynIndent() + " Get the line number of the current line + let lnum = v:lnum + + " Get the current line + let cline = getline(lnum) + + " If the current line has a '}', decrease indent + if cline =~ '^\s*}' + let lnum = prevnonblank(lnum - 1) + return indent(lnum) + endif + + " Find the previous non-blank line + let lnum = prevnonblank(lnum - 1) + + " At the start of the file, no indent + if lnum == 0 + return 0 + endif + + " Get the indent of the previous line + let prev_indent = indent(lnum) + let prev_line = getline(lnum) + + " If the previous line ends with '{', increase indent + if prev_line =~ '{\s*$' + return prev_indent + &shiftwidth + endif + + " Otherwise, keep the same indent + return prev_indent +endfunction diff --git a/src/datatypes/lists/lists.cpp b/src/datatypes/lists/lists.cpp index 8030ed5..d903606 100644 --- a/src/datatypes/lists/lists.cpp +++ b/src/datatypes/lists/lists.cpp @@ -39,7 +39,7 @@ Value handleListGet(const Value& subject, const std::vector& args) { return Value(); } Value accessor = args[0]; - if (accessor.valtype == ValueType::String && accessor.string_val == "size") { + if (accessor.valtype == ValueType::Identifier && accessor.string_val == "size") { return Value((long long)subject.list.size()); } if (accessor.valtype != ValueType::Int) { diff --git a/src/datatypes/strings/strings.cpp b/src/datatypes/strings/strings.cpp index 6d1db8c..d28145d 100644 --- a/src/datatypes/strings/strings.cpp +++ b/src/datatypes/strings/strings.cpp @@ -39,7 +39,7 @@ Value handleStringGet(const Value& subject, const std::vector& args) { } Value accessor = args[0]; if (accessor.valtype != ValueType::Int) { - if (accessor.valtype == ValueType::String && accessor.string_val == "size") { + if (accessor.valtype == ValueType::Identifier && accessor.string_val == "size") { return Value((long long)subject.string_val.length()); } error("String accessor must be an integer or \"size\"");