From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Fu Yuan Newsgroups: gmane.emacs.devel Subject: Re: How to add pseudo vector types Date: Tue, 3 Aug 2021 08:50:45 -0400 Message-ID: <8D678FFA-51BB-4835-B14B-8A22C575666A@gmail.com> References: <83czqun2fu.fsf@gnu.org> Mime-Version: 1.0 (1.0) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10986"; mail-complaints-to="usenet@ciao.gmane.io" Cc: cpitclaudel@gmail.com, stephen_leake@stephe-leake.org, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Aug 03 14:52:08 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAttw-0002fs-Km for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Aug 2021 14:52:08 +0200 Original-Received: from localhost ([::1]:44766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAttu-0006h1-G4 for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Aug 2021 08:52:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAtsi-0005CT-SX for emacs-devel@gnu.org; Tue, 03 Aug 2021 08:50:52 -0400 Original-Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]:39919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAtsg-0001tO-3G; Tue, 03 Aug 2021 08:50:52 -0400 Original-Received: by mail-qv1-xf2d.google.com with SMTP id d3so10478790qvq.6; Tue, 03 Aug 2021 05:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=GoZNFSUIZaUfgjNS/8qGkMSaWM6d72Iq+kYn5xiFR78=; b=utEQqwyIJGgnpJKujGzi/0Yi+kwowrg6WdvLFgqMwvoACJqMVeCpLi6X8m4yZ+cw1F jdav1GzWywV1ZW2lm9Yn6cf35eW0W2m5pLOdBC3zavbR/rHvXUmo+DyhySPhIda1PLOF wSDql9rHS42V2r9FmyObS4rsCuu6SwEk2ZvXXQp/O49FlSn9rkwKbIcTyJf+XuyG8KCK O2rCVrujlQNk/HIlZig4ERrA+hPww9G90pKJ5QOlf0l0q7jI+gUsWPaTD/xfYzfWJCbx sIuPbOw4vYc8QAVqtvdbcE/JEHHFNcfRR/uIVPPAxmJ6jYuWrgOVVweLXl4OKRwf7YbP s53w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=GoZNFSUIZaUfgjNS/8qGkMSaWM6d72Iq+kYn5xiFR78=; b=Pf7eegMgBXvtwweBw2GxnpACf+AHhuAh5KDape+3c+OQsxBECq8Un0HogWFOZF7u3a A6pZSY7qwcn0xuJHKpfpMqvj11cNF2hch8lobAiuI/okjqtl18d9QYm825VYzOXYxyai GG8Ey3N6bbAnPL3zmGwObsLZCPhhoKn+0ezPkauNNEM5hagHkkOFPuGWyr5FtzKcxAWb 6tUBXfnQzP9dbLQvNeB/E/h6XdHdURznMGccfb38Xk1ntUNiLo0Q+SoXZjWJ1WaZ2vPE oDKg1LKCpRCRRJBP7BGgZvJXssN2tIx7yMPG9XOm7/ACden6hHmT042Is9HlnvqJdsoy 9MpA== X-Gm-Message-State: AOAM531/F2QOpxOrdiuzo7rpBE0kVJNVScxpolm/fH9pGNof1eTXheVf jKapf5DihQqcWf1poCbFr0g= X-Google-Smtp-Source: ABdhPJwH74R2BfX7aDAsc92lvJ0MvChkPnRTe3QZOjdTjMJhG32KADZ2FSl8U8I8BoAMKKvlMJZ8lA== X-Received: by 2002:a05:6214:21ee:: with SMTP id p14mr21127774qvj.8.1627995048766; Tue, 03 Aug 2021 05:50:48 -0700 (PDT) Original-Received: from ?IPv6:2607:fb90:a902:79bf:ece0:4f2a:436e:c17b? ([2607:fb90:a902:79bf:ece0:4f2a:436e:c17b]) by smtp.gmail.com with ESMTPSA id q4sm6096951qtr.20.2021.08.03.05.50.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Aug 2021 05:50:47 -0700 (PDT) In-Reply-To: <83czqun2fu.fsf@gnu.org> X-Mailer: iPhone Mail (17H35) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2d; envelope-from=casouri@gmail.com; helo=mail-qv1-xf2d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271968 Archived-At: > =E5=9C=A8 2021=E5=B9=B48=E6=9C=883=E6=97=A5=EF=BC=8C=E4=B8=8A=E5=8D=888:22= =EF=BC=8CEli Zaretskii =E5=86=99=E9=81=93=EF=BC=9A >=20 > =EF=BB=BF >>=20 >> From: Fu Yuan >> Date: Tue, 3 Aug 2021 07:53:54 -0400 >> Cc: stephen_leake@stephe-leake.org, cpitclaudel@gmail.com, >> monnier@iro.umontreal.ca, emacs-devel@gnu.org >>=20 >> Oh no, I don=E2=80=99t mean that. I meant that, for example, functions li= ke node_start_byte, which returns the byte position of the beginning of the n= ode, will now be node_start_pos, which returns a point position. >=20 > That's called "character position". Let's use the accepted > terminology, to minimize misunderstandings. Ah, got it. > So in what sense are character positions easier to use than byte > positions? Here are what you can do with positions: - find the smallest node that encloses a range (BEG . END) - get the beginning and end of a node Since all other functions use character position (eg, put-text-property, poi= nt), using character positions saves lisp code some =E2=80=98position-to-byt= es=E2=80=99.=20 >> And if I want the byte position of the beginning of the node, I can use (= position-to-byte (tree-sitter-node-start-pos node)) >=20 > Caveat: position-to-byte can be expensive. So in time-critical code, > such as the display engine, we keep both character position and byte > position, and update them in sync. Then you can use whichever is > easier in each case. Internally, tree_sitter.c will continue to use byte positions, of course. Yuan=