robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
21.7 KiB704 linesraw
1local api = vim.api
2local nvim_on = require('vim._core.util').nvim_on
3
4local Range = require('vim.treesitter._range')
5
6local M = {}
7
8---@class (private) vim.treesitter.dev.TSTreeView
9---@field ns integer API namespace
10---@field opts vim.treesitter.dev.TSTreeViewOpts
11---@field nodes vim.treesitter.dev.Node[]
12---@field named vim.treesitter.dev.Node[]
13local TSTreeView = {}
14
15---@class (private) vim.treesitter.dev.TSTreeViewOpts
16---@field anon boolean If true, display anonymous nodes.
17---@field lang boolean If true, display the language alongside each node.
18---@field indent integer Number of spaces to indent nested lines.
19
20---@class (private) vim.treesitter.dev.Node
21---@field node TSNode Treesitter node
22---@field field string? Node field
23---@field depth integer Depth of this node in the tree
24---@field text string? Text displayed in the inspector for this node. Not computed until the
25---                    inspector is drawn.
26---@field lang string Source language of this node
27
28---@class (private) vim.treesitter.dev.Injection
29---@field lang string Source language of this injection
30---@field root TSNode Root node of the injection
31
32--- Traverse all child nodes starting at {node}.
33---
34--- This is a recursive function. The {depth} parameter indicates the current recursion level.
35--- {lang} is a string indicating the language of the tree currently being traversed. Each traversed
36--- node is added to {tree}. When recursion completes, {tree} is an array of all nodes in the order
37--- they were visited.
38---
39--- {injections} is a table mapping node ids from the primary tree to language tree injections. Each
40--- injected language has a series of trees nested within the primary language's tree, and the root
41--- node of each of these trees is contained within a node in the primary tree. The {injections}
42--- table maps nodes in the primary tree to root nodes of injected trees.
43---
44---@param node TSNode Starting node to begin traversal |tsnode|
45---@param depth integer Current recursion depth
46---@param field string|nil The field of the current node
47---@param lang string Language of the tree currently being traversed
48---@param injections table<string, vim.treesitter.dev.Injection[]> Mapping of node ids to root nodes
49---                  of injected language trees (see explanation above)
50---@param tree vim.treesitter.dev.Node[] Output table containing a list of tables each representing a node in the tree
51local function traverse(node, depth, field, lang, injections, tree)
52  table.insert(tree, {
53    node = node,
54    depth = depth,
55    lang = lang,
56    field = field,
57  })
58
59  for _, injection in ipairs(injections[node:id()] or {}) do
60    traverse(injection.root, depth + 1, nil, injection.lang, injections, tree)
61  end
62
63  for child, child_field in node:iter_children() do
64    traverse(child, depth + 1, child_field, lang, injections, tree)
65  end
66
67  return tree
68end
69
70--- Create a new treesitter view.
71---
72---@param buf integer Source buffer number
73---@param lang string|nil Language of source buffer
74---
75---@return vim.treesitter.dev.TSTreeView|nil
76---@return string|nil Error message, if any
77---
78---@package
79function TSTreeView:new(buf, lang)
80  buf = buf or 0
81  lang = lang or vim.treesitter.language.get_lang(vim.bo[buf].filetype)
82  local parser = vim.treesitter.get_parser(buf, lang)
83  if not parser then
84    return nil,
85      string.format('Failed to create TSTreeView for buffer %s: no parser for lang "%s"', buf, lang)
86  end
87
88  -- For each child tree (injected language), find the root of the tree and locate the node within
89  -- the primary tree that contains that root. Add a mapping from the node in the primary tree to
90  -- the root in the child tree to the {injections} table.
91  local root = parser:parse(true)[1]:root()
92  local injections = {} ---@type table<string, table<string, TSNode>>
93
94  parser:for_each_tree(function(parent_tree, parent_ltree)
95    local parent = parent_tree:root()
96    local parent_range = { parent:range() }
97    for _, child in pairs(parent_ltree:children()) do
98      for _, tree in pairs(child:trees()) do
99        local r = tree:root()
100        local r_range = { r:range() }
101        if Range.contains(parent_range, r_range) then
102          local node = assert(parent:named_descendant_for_range(r:range()))
103          local id = node:id()
104          local ilang = child:lang()
105          injections[id] = injections[id] or {}
106          local injection = injections[id][ilang]
107          if not injection or r:byte_length() > injection:byte_length() then
108            injections[id][ilang] = r
109          end
110        end
111      end
112    end
113  end)
114
115  local sorted_injections = {} ---@type table<string, vim.treesitter.dev.Injection[]>
116  for id, lang_injections in pairs(injections) do
117    local langs = vim.tbl_keys(lang_injections)
118    ---@param a string
119    ---@param b string
120    table.sort(langs, function(a, b)
121      return lang_injections[a]:byte_length() > lang_injections[b]:byte_length()
122    end)
123    ---@param ilang string
124    sorted_injections[id] = vim.tbl_map(function(ilang)
125      return { lang = ilang, root = lang_injections[ilang] }
126    end, langs)
127  end
128
129  local nodes = traverse(root, 0, nil, parser:lang(), sorted_injections, {})
130
131  local named = {} ---@type vim.treesitter.dev.Node[]
132  for _, v in ipairs(nodes) do
133    if v.node:named() then
134      named[#named + 1] = v
135    end
136  end
137
138  local t = {
139    ns = api.nvim_create_namespace('nvim.treesitter.dev_inspect'),
140    nodes = nodes,
141    named = named,
142    ---@type vim.treesitter.dev.TSTreeViewOpts
143    opts = {
144      anon = false,
145      lang = false,
146      indent = 2,
147    },
148  }
149
150  self.__index = self
151  return setmetatable(t, self)
152end
153
154local decor_ns = api.nvim_create_namespace('nvim.treesitter.dev')
155
156---@param w integer
157---@return boolean closed Whether the window was closed.
158local function close_win(w)
159  if api.nvim_win_is_valid(w) then
160    api.nvim_win_close(w, true)
161    return true
162  end
163
164  return false
165end
166
167---@param w integer
168---@param b integer
169---@param opts nil|{ indent?: integer }
170local function set_dev_options(w, b, opts)
171  vim.wo[w][0].scrolloff = 5
172  vim.wo[w][0].wrap = false
173  vim.wo[w][0].foldmethod = 'expr'
174  vim.wo[w][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- explicitly set foldexpr
175  vim.wo[w][0].foldenable = false -- Don't fold on first open InspectTree
176  vim.wo[w][0].foldlevel = 99
177  vim.bo[b].buflisted = false
178  vim.bo[b].buftype = 'nofile'
179  vim.bo[b].bufhidden = 'wipe'
180  vim.bo[b].filetype = 'query'
181  vim.bo[b].swapfile = false
182
183  opts = opts or {}
184  if opts.indent then
185    vim.bo[b].shiftwidth = opts.indent
186  end
187end
188
189--- Updates the cursor position in the inspector to match the node under the cursor.
190---
191--- @param treeview vim.treesitter.dev.TSTreeView
192--- @param lang string?
193--- @param source_buf integer
194--- @param inspect_buf integer
195--- @param inspect_win integer
196--- @param pos? [integer, integer]
197local function set_inspector_cursor(treeview, lang, source_buf, inspect_buf, inspect_win, pos)
198  api.nvim_buf_clear_namespace(inspect_buf, treeview.ns, 0, -1)
199
200  local cursor_node = vim.treesitter.get_node({
201    bufnr = source_buf,
202    lang = lang,
203    pos = pos,
204    ignore_injections = false,
205    include_anonymous = treeview.opts.anon,
206  })
207  if not cursor_node then
208    return
209  end
210
211  local cursor_node_id = cursor_node:id()
212  for i, v in treeview:iter() do
213    if v.node:id() == cursor_node_id then
214      local start = v.depth * treeview.opts.indent ---@type integer
215      local end_col = start + #v.text
216      api.nvim_buf_set_extmark(inspect_buf, treeview.ns, i - 1, start, {
217        end_col = end_col,
218        hl_group = 'Visual',
219      })
220      api.nvim_win_set_cursor(inspect_win, { i, 0 })
221      break
222    end
223  end
224end
225
226--- Write the contents of this View into {bufnr}.
227---
228--- Calling this function computes the text that is displayed for each node.
229---
230---@param buf integer Buffer number to write into.
231---@package
232function TSTreeView:draw(buf)
233  vim.bo[buf].modifiable = true
234  local lines = {} ---@type string[]
235  local lang_hl_marks = {} ---@type table[]
236
237  for i, item in self:iter() do
238    local range_str = ('[%d, %d] - [%d, %d]'):format(item.node:range())
239    local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
240
241    local text ---@type string
242    if item.node:named() then
243      text = string.format('(%s%s', item.node:missing() and 'MISSING ' or '', item.node:type())
244    else
245      text = string.format('%q', item.node:type()):gsub('\n', 'n')
246      if item.node:missing() then
247        text = string.format('(MISSING %s)', text)
248      end
249    end
250    if item.field then
251      text = string.format('%s: %s', item.field, text)
252    end
253
254    local next = self:get(i + 1)
255    if not next or next.depth <= item.depth then
256      local parens = item.depth - (next and next.depth or 0) + (item.node:named() and 1 or 0)
257      if parens > 0 then
258        text = string.format('%s%s', text, string.rep(')', parens))
259      end
260    end
261
262    item.text = text
263
264    local line = string.format(
265      '%s%s ; %s%s',
266      string.rep(' ', item.depth * self.opts.indent),
267      text,
268      range_str,
269      lang_str
270    )
271
272    if self.opts.lang then
273      lang_hl_marks[#lang_hl_marks + 1] = {
274        col = #line - #lang_str,
275        end_col = #line,
276      }
277    end
278
279    lines[i] = line
280  end
281
282  api.nvim_buf_set_lines(buf, 0, -1, false, lines)
283
284  api.nvim_buf_clear_namespace(buf, decor_ns, 0, -1)
285
286  for i, m in ipairs(lang_hl_marks) do
287    api.nvim_buf_set_extmark(buf, decor_ns, i - 1, m.col, {
288      hl_group = 'Title',
289      end_col = m.end_col,
290    })
291  end
292
293  vim.bo[buf].modifiable = false
294end
295
296--- Get node {i} from this View.
297---
298--- The node number is dependent on whether or not anonymous nodes are displayed.
299---
300---@param i integer Node number to get
301---@return vim.treesitter.dev.Node?
302---@package
303function TSTreeView:get(i)
304  local t = self.opts.anon and self.nodes or self.named
305  return t[i]
306end
307
308--- Iterate over all of the nodes in this View.
309---
310---@return (fun(): integer, vim.treesitter.dev.Node) Iterator over all nodes in this View
311---@return table
312---@return integer
313---@package
314function TSTreeView:iter()
315  -- TODO(lewis6991): EmmyLua 0.25.1's ipairs annotation omits the table and initial index.
316  --- @diagnostic disable-next-line: missing-return-value
317  return ipairs(self.opts.anon and self.nodes or self.named)
318end
319
320--- @class vim.treesitter.dev.inspect_tree.Opts
321--- @inlinedoc
322---
323--- The language of the source buffer. If omitted, the filetype of the source
324--- buffer is used.
325--- @field lang string?
326---
327--- Buffer to draw the tree into. If omitted, a new buffer is created.
328--- @field bufnr integer?
329---
330--- Window id to display the tree buffer in. If omitted, a new window is
331--- created with {command}.
332--- @field winid integer?
333---
334--- Vimscript command to create the window. Default value is "60vnew".
335--- Only used when {winid} is nil.
336--- @field command string?
337---
338--- Title of the window. If a function, it accepts the buffer number of the
339--- source buffer as its only argument and should return a string.
340--- @field title? string|fun(bufnr:integer):string
341
342--- @nodoc
343--- @param opts vim.treesitter.dev.inspect_tree.Opts?
344function M.inspect_tree(opts)
345  vim.validate('opts', opts, 'table', true)
346
347  opts = opts or {}
348
349  -- source buffer
350  local buf = api.nvim_get_current_buf()
351
352  -- window id for source buffer
353  local win = api.nvim_get_current_win()
354  local treeview, err = TSTreeView:new(buf, opts.lang)
355  if err and err:match('no parser for lang') then
356    api.nvim_echo({ { err, 'WarningMsg' } }, true)
357    return
358  elseif not treeview then
359    error(err)
360  end
361
362  -- Close any existing inspector window
363  if vim.b[buf].dev_inspect then
364    close_win(vim.b[buf].dev_inspect)
365  end
366
367  -- window id for tree buffer
368  local w = opts.winid
369  if not w then
370    vim.cmd(opts.command or '60vnew')
371    w = api.nvim_get_current_win()
372  end
373
374  -- tree buffer
375  local b = opts.bufnr
376  if b then
377    api.nvim_win_set_buf(w, b)
378  else
379    b = api.nvim_win_get_buf(w)
380  end
381
382  vim.b[buf].dev_inspect = w
383  vim.b[b].dev_base = win -- base window handle
384  vim.b[b].disable_query_linter = true
385  set_dev_options(w, b, { indent = treeview.opts.indent })
386
387  local title --- @type string?
388  local opts_title = opts.title
389  if not opts_title then
390    local bufname = api.nvim_buf_get_name(buf)
391    title = ('Syntax tree for %s'):format(vim.fs.relpath('.', bufname) or bufname)
392  elseif type(opts_title) == 'function' then
393    title = opts_title(buf)
394  else
395    title = opts_title
396  end
397
398  assert(type(title) == 'string', 'Window title must be a string')
399  api.nvim_buf_set_name(b, title)
400
401  treeview:draw(b)
402
403  local cursor = api.nvim_win_get_cursor(win)
404  set_inspector_cursor(treeview, opts.lang, buf, b, w, { cursor[1] - 1, cursor[2] })
405
406  api.nvim_buf_clear_namespace(buf, treeview.ns, 0, -1)
407  api.nvim_buf_set_keymap(b, 'n', '<CR>', '', {
408    desc = 'Jump to the node under the cursor in the source buffer',
409    nowait = true,
410    callback = function()
411      local row = api.nvim_win_get_cursor(w)[1]
412      local lnum, col = assert(treeview:get(row)).node:start()
413
414      -- update source window if original was closed
415      if not api.nvim_win_is_valid(win) then
416        win = assert(vim.fn.win_findbuf(buf)[1])
417      end
418
419      api.nvim_set_current_win(win)
420      api.nvim_win_set_cursor(win, { lnum + 1, col })
421    end,
422  })
423  api.nvim_buf_set_keymap(b, 'n', 'a', '', {
424    desc = 'Toggle anonymous nodes',
425    nowait = true,
426    callback = function()
427      local row, col = unpack(api.nvim_win_get_cursor(w)) ---@type integer, integer
428      local curnode = treeview:get(row)
429      while curnode and not curnode.node:named() do
430        row = row - 1
431        curnode = treeview:get(row)
432      end
433
434      treeview.opts.anon = not treeview.opts.anon
435      treeview:draw(b)
436
437      if not curnode then
438        return
439      end
440
441      local id = curnode.node:id()
442      for i, node in treeview:iter() do
443        if node.node:id() == id then
444          api.nvim_win_set_cursor(w, { i, col })
445          break
446        end
447      end
448    end,
449  })
450  api.nvim_buf_set_keymap(b, 'n', 'I', '', {
451    desc = 'Toggle language display',
452    nowait = true,
453    callback = function()
454      treeview.opts.lang = not treeview.opts.lang
455      treeview:draw(b)
456    end,
457  })
458  api.nvim_buf_set_keymap(b, 'n', 'o', '', {
459    desc = 'Toggle query editor',
460    nowait = true,
461    callback = function()
462      local edit_w = vim.b[buf].dev_edit
463      if not edit_w or not close_win(edit_w) then
464        M.edit_query()
465      end
466    end,
467  })
468  api.nvim_buf_set_keymap(b, 'n', 'q', '<Cmd>wincmd c<CR>', {
469    desc = 'Close language tree window',
470    nowait = true,
471  })
472
473  local group = api.nvim_create_augroup('nvim.treesitter.dev')
474
475  nvim_on('CursorMoved', group, { buf = b }, function()
476    if not api.nvim_buf_is_loaded(buf) then
477      return true
478    end
479
480    w = api.nvim_get_current_win()
481    api.nvim_buf_clear_namespace(buf, treeview.ns, 0, -1)
482    local row = api.nvim_win_get_cursor(w)[1]
483    local lnum, col, end_lnum, end_col = assert(treeview:get(row)).node:range()
484    api.nvim_buf_set_extmark(buf, treeview.ns, lnum, col, {
485      end_row = end_lnum,
486      end_col = math.max(0, end_col),
487      hl_group = 'Visual',
488    })
489
490    -- update source window if original was closed
491    if not api.nvim_win_is_valid(win) then
492      win = assert(vim.fn.win_findbuf(buf)[1])
493    end
494
495    local topline, botline = vim.fn.line('w0', win), vim.fn.line('w$', win)
496
497    -- Move the cursor if highlighted range is completely out of view
498    if lnum < topline and end_lnum < topline then
499      api.nvim_win_set_cursor(win, { end_lnum + 1, 0 })
500    elseif lnum > botline and end_lnum > botline then
501      api.nvim_win_set_cursor(win, { lnum + 1, 0 })
502    end
503  end)
504
505  nvim_on('CursorMoved', group, { buf = buf }, function()
506    if not api.nvim_buf_is_loaded(b) then
507      return true
508    end
509
510    set_inspector_cursor(treeview, opts.lang, buf, b, w)
511  end)
512
513  nvim_on({ 'TextChanged', 'InsertLeave' }, group, { buf = buf }, function()
514    if not api.nvim_buf_is_loaded(b) then
515      return true
516    end
517
518    local treeview_opts = treeview.opts
519    treeview = assert(TSTreeView:new(buf, opts.lang))
520    treeview.opts = treeview_opts
521    treeview:draw(b)
522  end)
523
524  nvim_on('BufLeave', group, { buf = b }, function()
525    if not api.nvim_buf_is_loaded(buf) then
526      return true
527    end
528    api.nvim_buf_clear_namespace(buf, treeview.ns, 0, -1)
529  end)
530
531  nvim_on('BufLeave', group, { buf = buf }, function()
532    if not api.nvim_buf_is_loaded(b) then
533      return true
534    end
535    api.nvim_buf_clear_namespace(b, treeview.ns, 0, -1)
536  end)
537
538  nvim_on({ 'BufHidden', 'BufUnload', 'QuitPre' }, group, { buf = buf }, function()
539    -- don't close inpector window if source buffer
540    -- has more than one open window
541    if #vim.fn.win_findbuf(buf) > 1 then
542      return
543    end
544
545    -- close all tree windows
546    for _, window in pairs(vim.fn.win_findbuf(b)) do
547      close_win(window)
548    end
549
550    return true
551  end)
552end
553
554local edit_ns = api.nvim_create_namespace('nvim.treesitter.dev_edit')
555
556---@param query_win integer
557---@param base_win integer
558---@param lang string
559local function update_editor_highlights(query_win, base_win, lang)
560  local base_buf = api.nvim_win_get_buf(base_win)
561  local query_buf = api.nvim_win_get_buf(query_win)
562  local root_lang = vim.treesitter.language.get_lang(vim.bo[base_buf].filetype)
563  local parser = assert(vim.treesitter.get_parser(base_buf, root_lang))
564  api.nvim_buf_clear_namespace(base_buf, edit_ns, 0, -1)
565  local query_content = table.concat(api.nvim_buf_get_lines(query_buf, 0, -1, false), '\n')
566
567  local ok_query, query = pcall(vim.treesitter.query.parse, lang, query_content)
568  if not ok_query then
569    return
570  end
571
572  local cursor_word = vim.fn.expand('<cword>') --[[@as string]]
573  -- Only highlight captures if the cursor is on a capture name
574  if cursor_word:find('^@') == nil then
575    return
576  end
577  -- Remove the '@' from the cursor word
578  cursor_word = cursor_word:sub(2)
579  -- Parse buffer including injected languages.
580  parser:parse(true)
581  -- Query on the trees of the language requested to highlight captures.
582  parser:for_each_tree(function(tree, ltree)
583    if ltree:lang() ~= lang then
584      return
585    end
586    local root = tree:root()
587    local topline, botline = vim.fn.line('w0', base_win), vim.fn.line('w$', base_win)
588    for id, node, metadata in query:iter_captures(root, base_buf, topline - 1, botline) do
589      local capture_name = query.captures[id]
590      if capture_name == cursor_word then
591        local lnum, col, end_lnum, end_col =
592          Range.unpack4(vim.treesitter.get_range(node, base_buf, metadata[id]))
593
594        api.nvim_buf_set_extmark(base_buf, edit_ns, lnum, col, {
595          end_row = end_lnum,
596          end_col = end_col,
597          hl_group = 'Visual',
598          virt_text = {
599            { capture_name, 'DiagnosticVirtualTextHint' },
600          },
601        })
602      end
603    end
604  end)
605end
606
607--- @nodoc
608--- @param lang? string language to open the query editor for.
609--- @return boolean? `true` on success, `nil` on failure
610--- @return string? error message, if applicable
611function M.edit_query(lang)
612  local buf = api.nvim_get_current_buf()
613  local win = api.nvim_get_current_win()
614
615  -- Close any existing editor window
616  if vim.b[buf].dev_edit then
617    close_win(vim.b[buf].dev_edit)
618  end
619
620  local cmd = '60vnew'
621  -- If the inspector is open, place the editor above it.
622  local base_win = vim.b[buf].dev_base ---@type integer?
623  local base_buf = base_win and api.nvim_win_get_buf(base_win)
624  local inspect_win = base_buf and vim.b[base_buf].dev_inspect
625  if base_win and base_buf and api.nvim_win_is_valid(inspect_win) then
626    api.nvim_set_current_win(inspect_win)
627    buf = base_buf
628    win = base_win
629    cmd = 'new'
630  end
631  vim.cmd(cmd)
632
633  local parser = vim.treesitter.get_parser(buf, lang)
634  if not parser then
635    return nil,
636      string.format('Failed to show query editor for buffer %s: no parser for lang "%s"', buf, lang)
637  end
638  lang = parser:lang()
639
640  local query_win = api.nvim_get_current_win()
641  local query_buf = api.nvim_win_get_buf(query_win)
642
643  vim.b[buf].dev_edit = query_win
644  vim.bo[query_buf].omnifunc = vim.treesitter.query.omnifunc
645  set_dev_options(query_win, query_buf)
646
647  -- Note that omnifunc guesses the language based on the containing folder,
648  -- so we add the parser's language to the buffer's name so that omnifunc
649  -- can infer the language later.
650  api.nvim_buf_set_name(query_buf, string.format('%s/query_editor.scm', lang))
651
652  local group = api.nvim_create_augroup('nvim.treesitter.dev_edit')
653  nvim_on({ 'TextChanged', 'InsertLeave' }, group, {
654    buf = query_buf,
655    desc = 'Update query editor diagnostics when the query changes',
656  }, function()
657    vim.treesitter.query.lint(query_buf, { langs = lang, clear = false })
658  end)
659  nvim_on({ 'TextChanged', 'InsertLeave', 'CursorMoved', 'BufEnter' }, group, {
660    buf = query_buf,
661    desc = 'Update query editor highlights when the cursor moves',
662  }, function()
663    if api.nvim_win_is_valid(win) then
664      update_editor_highlights(query_win, win, lang)
665    end
666  end)
667  nvim_on('BufLeave', group, {
668    buf = query_buf,
669    desc = 'Clear highlights when leaving the query editor',
670  }, function()
671    api.nvim_buf_clear_namespace(buf, edit_ns, 0, -1)
672  end)
673  nvim_on('BufLeave', group, {
674    buf = buf,
675    desc = 'Clear the query editor highlights when leaving the source buffer',
676  }, function()
677    if not api.nvim_buf_is_loaded(query_buf) then
678      return true
679    end
680
681    api.nvim_buf_clear_namespace(query_buf, edit_ns, 0, -1)
682  end)
683  nvim_on({ 'BufHidden', 'BufUnload' }, group, {
684    buf = buf,
685    desc = 'Close the editor window when the source buffer is hidden or unloaded',
686    once = true,
687  }, function()
688    close_win(query_win)
689  end)
690
691  api.nvim_buf_set_lines(query_buf, 0, -1, false, {
692    ';; Write queries here (see $VIMRUNTIME/queries/ for examples).',
693    ';; Move cursor to a capture ("@foo") to highlight matches in the source buffer.',
694    ';; Completion for grammar nodes is available (:help compl-omni)',
695    '',
696    '',
697  })
698  vim.cmd('normal! G')
699  vim.cmd.startinsert()
700
701  return true
702end
703
704return M