aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormitchell <unknown>2020-03-26 11:20:26 -0400
committermitchell <unknown>2020-03-26 11:20:26 -0400
commitacb7c70264348bc80c151bfc76c7b107e8db99ab (patch)
tree9721deff587ed5fd7c0e331ff5cbb2db1084e19c
parent6c09e990d1906553d1e328502aca5662ef43eb12 (diff)
downloadscintilla-mirror-acb7c70264348bc80c151bfc76c7b107e8db99ab.tar.gz
Switch to 1-based indices in Lua.
The only external, 3rd party lexers that would be affected are those implementing their own fold functions.
-rw-r--r--doc/LPegLexer.html12
-rw-r--r--lexers/LexLPeg.cxx16
-rw-r--r--lexlua/lexer.lua22
-rw-r--r--test/test_lexlua.lua6
4 files changed, 28 insertions, 28 deletions
diff --git a/doc/LPegLexer.html b/doc/LPegLexer.html
index 0e1b81142..e31a091b1 100644
--- a/doc/LPegLexer.html
+++ b/doc/LPegLexer.html
@@ -1798,7 +1798,7 @@ operator 30
<h3><code>lexer.fold_level</code> (table, Read-only)</h3>
- <p>Table of fold level bit-masks for line numbers starting from zero.
+ <p>Table of fold level bit-masks for line numbers starting from 1.
Fold level masks are composed of an integer level combined with any of the
following bits:</p>
@@ -1829,7 +1829,7 @@ operator 30
<h3><code>lexer.indent_amount</code> (table, Read-only)</h3>
<p>Table of indentation amounts in character columns, for line numbers
- starting from zero.</p>
+ starting from 1.</p>
<p><a id="lexer.integer"></a></p>
@@ -1841,7 +1841,7 @@ operator 30
<h3><code>lexer.line_state</code> (table)</h3>
- <p>Table of integer line states for line numbers starting from zero.
+ <p>Table of integer line states for line numbers starting from 1.
Line states can be used by lexers for keeping track of persistent states.</p>
<p><a id="lexer.lower"></a></p>
@@ -2164,9 +2164,9 @@ operator 30
<ul>
<li><code>lexer</code>: The lexer to fold text with.</li>
<li><code>text</code>: The text in the buffer to fold.</li>
- <li><code>start_pos</code>: The position in the buffer <em>text</em> starts at, starting at
- zero.</li>
- <li><code>start_line</code>: The line number <em>text</em> starts on.</li>
+ <li><code>start_pos</code>: The position in the buffer <em>text</em> starts at, counting from
+ 1.</li>
+ <li><code>start_line</code>: The line number <em>text</em> starts on, counting from 1.</li>
<li><code>start_level</code>: The fold level <em>text</em> starts on.</li>
</ul>
diff --git a/lexers/LexLPeg.cxx b/lexers/LexLPeg.cxx
index f3295b448..a4e2f1735 100644
--- a/lexers/LexLPeg.cxx
+++ b/lexers/LexLPeg.cxx
@@ -85,10 +85,10 @@ static int lexer_property_index(lua_State *L) {
auto buffer = static_cast<IDocument *>(lua_touserdata(L, -1));
if (strcmp(property, "fold_level") == 0) {
luaL_argcheck(L, buffer, 1, "must be lexing or folding");
- lua_pushinteger(L, buffer->GetLevel(luaL_checkinteger(L, 2)));
+ lua_pushinteger(L, buffer->GetLevel(luaL_checkinteger(L, 2) - 1));
} else if (strcmp(property, "indent_amount") == 0) {
luaL_argcheck(L, buffer, 1, "must be lexing or folding");
- lua_pushinteger(L, buffer->GetLineIndentation(luaL_checkinteger(L, 2)));
+ lua_pushinteger(L, buffer->GetLineIndentation(luaL_checkinteger(L, 2) - 1));
} else if (strcmp(property, "property") == 0) {
lua_pushstring(L, props->Get(luaL_checkstring(L, 2)));
} else if (strcmp(property, "property_int") == 0) {
@@ -106,7 +106,7 @@ static int lexer_property_index(lua_State *L) {
lua_pop(L, 1); // style_num, leaving name on top
} else if (strcmp(property, "line_state") == 0) {
luaL_argcheck(L, buffer, 1, "must be lexing or folding");
- lua_pushinteger(L, buffer->GetLineState(luaL_checkinteger(L, 2)));
+ lua_pushinteger(L, buffer->GetLineState(luaL_checkinteger(L, 2) - 1));
}
return 1;
}
@@ -133,7 +133,7 @@ static int lexer_property_newindex(lua_State *L) {
luaL_argcheck(
L, lua_getfield(L, -1, "_BUFFER"), 1, "must be lexing or folding");
auto buffer = static_cast<IDocument *>(lua_touserdata(L, -1));
- buffer->SetLineState(luaL_checkinteger(L, 2), luaL_checkinteger(L, 3));
+ buffer->SetLineState(luaL_checkinteger(L, 2) - 1, luaL_checkinteger(L, 3));
}
return 0;
}
@@ -142,7 +142,7 @@ static int lexer_property_newindex(lua_State *L) {
static int line_from_position(lua_State *L) {
auto buffer = static_cast<IDocument *>(
lua_touserdata(L, lua_upvalueindex(1)));
- lua_pushinteger(L, buffer->LineFromPosition(luaL_checkinteger(L, 1) - 1));
+ lua_pushinteger(L, buffer->LineFromPosition(luaL_checkinteger(L, 1) - 1) + 1);
return 1;
}
@@ -738,8 +738,8 @@ public:
lua_pushvalue(L, -3);
Sci_Position currentLine = styler.GetLine(startPos);
lua_pushlstring(L, buffer->BufferPointer() + startPos, lengthDoc);
- lua_pushinteger(L, startPos);
- lua_pushinteger(L, currentLine);
+ lua_pushinteger(L, startPos + 1);
+ lua_pushinteger(L, currentLine + 1);
lua_pushinteger(L, styler.LevelAt(currentLine) & SC_FOLDLEVELNUMBERMASK);
if (lua_pcall(L, 5, 1, -7) != LUA_OK) return LogError(L);
if (!lua_istable(L, -1))
@@ -747,7 +747,7 @@ public:
// Fold the text from the fold table returned.
lua_pushnil(L);
while (lua_next(L, -2)) { // line = level
- styler.SetLevel(lua_tointeger(L, -2), lua_tointeger(L, -1));
+ styler.SetLevel(lua_tointeger(L, -2) - 1, lua_tointeger(L, -1));
lua_pop(L, 1); // level
}
lua_pop(L, 3); // fold table returned, lua_error_handler, lexer object
diff --git a/lexlua/lexer.lua b/lexlua/lexer.lua
index 658f7f004..8b29bb861 100644
--- a/lexlua/lexer.lua
+++ b/lexlua/lexer.lua
@@ -916,7 +916,7 @@ local M = {}
-- @field FOLD_HEADER (number)
-- Flag indicating the line is fold point.
-- @field fold_level (table, Read-only)
--- Table of fold level bit-masks for line numbers starting from zero.
+-- Table of fold level bit-masks for line numbers starting from 1.
-- Fold level masks are composed of an integer level combined with any of the
-- following bits:
--
@@ -928,9 +928,9 @@ local M = {}
-- The line is a header, or fold point.
-- @field indent_amount (table, Read-only)
-- Table of indentation amounts in character columns, for line numbers
--- starting from zero.
+-- starting from 1.
-- @field line_state (table)
--- Table of integer line states for line numbers starting from zero.
+-- Table of integer line states for line numbers starting from 1.
-- Line states can be used by lexers for keeping track of persistent states.
-- @field property (table)
-- Map of key-value string pairs.
@@ -1287,9 +1287,9 @@ end
-- beginning fold level of *start_level* in the buffer.
-- @param lexer The lexer to fold text with.
-- @param text The text in the buffer to fold.
--- @param start_pos The position in the buffer *text* starts at, starting at
--- zero.
--- @param start_line The line number *text* starts on.
+-- @param start_pos The position in the buffer *text* starts at, counting from
+-- 1.
+-- @param start_line The line number *text* starts on, counting from 1.
-- @param start_level The fold level *text* starts on.
-- @return table of fold levels associated with line numbers.
-- @name fold
@@ -1324,7 +1324,7 @@ function M.fold(lexer, text, start_pos, start_line, start_level)
--if not word or line:find('^%f[%w_]'..symbol..'%f[^%w_]', s) then
if not word or not ((s > 1 and line:find('^[%w_]', s - 1)) or
line:find('^[%w_]', e + 1)) then
- local symbols = fold_points[style_at[start_pos + pos + s - 1]]
+ local symbols = fold_points[style_at[start_pos + pos - 1 + s - 1]]
local level = symbols and symbols[symbol]
if type(level) == 'function' then
level = level(text, pos, line, s, symbol)
@@ -1350,7 +1350,7 @@ function M.fold(lexer, text, start_pos, start_line, start_level)
folds[line_num] = prev_level - 1 + FOLD_HEADER
else
-- Typing within a zero-sum line.
- local level = fold_level[line_num - 1] - 1
+ local level = fold_level[line_num] - 1
if level > FOLD_HEADER then level = level - FOLD_HEADER end
if level > FOLD_BLANK then level = level - FOLD_BLANK end
folds[line_num] = level + FOLD_HEADER
@@ -1377,7 +1377,7 @@ function M.fold(lexer, text, start_pos, start_line, start_level)
-- blank lines inbetween. If the current line is blank, match the level of
-- the previous non-blank line.
local current_level = start_level
- for i = start_line - 1, 0, -1 do
+ for i = start_line, 1, -1 do
local level = M.fold_level[i]
if level >= FOLD_HEADER then level = level - FOLD_HEADER end
if level < FOLD_BLANK then
@@ -1858,8 +1858,8 @@ M.property_expanded = setmetatable({}, {
--[[ The functions and fields below were defined in C.
---
--- Returns the line number of the line that contains position *pos*, which
--- starts from 1.
+-- Returns the line number (starting from 1) of the line that contains position
+-- *pos*, which starts from 1.
-- @param pos The position to get the line number of.
-- @return number
local function line_from_position(pos) end
diff --git a/test/test_lexlua.lua b/test/test_lexlua.lua
index f7bfd94c0..3436d9d19 100644
--- a/test/test_lexlua.lua
+++ b/test/test_lexlua.lua
@@ -159,7 +159,7 @@ function assert_fold_points(lex, code, expected_fold_points, initial_style)
})
end
lexer.property['fold'] = 1
- local levels = lex:fold(code, 0, 1, lexer.FOLD_BASE)
+ local levels = lex:fold(code, 1, 1, lexer.FOLD_BASE)
local j = 1
for i = 1, #levels do
if i == expected_fold_points[j] then
@@ -544,8 +544,8 @@ function test_fold_by_indentation()
else:
baz
]]
- lexer.fold_level = {[0] = lexer.FOLD_BASE} -- Scintilla normally creates this
- lexer.indent_amount = {[0] = 0} -- Scintilla normally creates this
+ lexer.fold_level = {lexer.FOLD_BASE} -- Scintilla normally creates this
+ lexer.indent_amount = {0} -- Scintilla normally creates this
local folds = {1, 3}
assert_fold_points(lex, code, folds)
end