From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: HaiJun Zhang Newsgroups: gmane.emacs.devel Subject: Re: Using incremental parsing in Emacs Date: Sat, 4 Jan 2020 12:57:24 +0800 Message-ID: References: <83blrkj1o1.fsf@gnu.org> <41b3e9a0-2866-4692-a35c-6d9541bc3aaa@Spark> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="5e101b39_2d9df57d_4379" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="110794"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org, Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 04 05:57:48 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1inbVT-000Sj3-Vi for ged-emacs-devel@m.gmane.org; Sat, 04 Jan 2020 05:57:48 +0100 Original-Received: from localhost ([::1]:59510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inbVR-0008VZ-R6 for ged-emacs-devel@m.gmane.org; Fri, 03 Jan 2020 23:57:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46637) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inbVL-0008VO-SW for emacs-devel@gnu.org; Fri, 03 Jan 2020 23:57:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1inbVK-0007aK-16 for emacs-devel@gnu.org; Fri, 03 Jan 2020 23:57:39 -0500 Original-Received: from mail-oln040092253076.outbound.protection.outlook.com ([40.92.253.76]:6007 helo=APC01-SG2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1inbVJ-0007LX-HE; Fri, 03 Jan 2020 23:57:37 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Di4fLrCDFikkafbfKFRM4vq4ehsJxe6TM4ulsNfaNX4B8gyfcJhiM8eIEUzIM5bKa67pqgBkmZh9cejTdEzixG8ZLlIrWvXxuuPxprEKmJUY8KsHxlDMraXdVW3+INNa9RjT3lTVzqXo2g159hs41LNCNqs1GLua6fR82ahDVuZcbCzUf4NFv4n5pVFbqf462Aix3n+7y19Gj4GLeOPYB6VExELfqPE79Zvb8rin8icpIElxM1YNRMmw+uXLCgyCUVy5FUk97w7pUObhGFazLugqjXhd1ju+AIevCNlsVnrQ1de3CKEKeQGAHXL5K+4WBSQHTI8Cr+Mvmu2inQvckw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z3wNHZzXKofl88YDQBp4a5v6DTgSyzDxxHeisH/zQ9M=; b=g+LiojFLVMTerxmNIhwQH+J7A/NUqMXmFYzIjm3U7FMYdOIPzFiP9GIGIjt1LuB+Ji6+ynMsuCanOi7KjDTzrPrm/2b9zjQ6PUl29O05nRKp05QhrEe0cUeEri1W8Qr1vmrQkBCdA9JKn4PGiTUHbZf5imLdA6xRHimuDiuVbKPJmp/XD9+iPgO1LEY4nW2xAjI5R8+opcd/1yyBNHISqF++dHFc3DE6NV3mxvefZ+06FBgVvOMpVbSPwBq1zA/D3TIQmhiVWZiIXVW0jwLcUJrfqWdCB1JrV7sSrO8gxJrhh/bdWFi5VK9aFVLfT8y6llZ17J2lyOxP6KzzBqhNeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=outlook.com; dmarc=pass action=none header.from=outlook.com; dkim=pass header.d=outlook.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z3wNHZzXKofl88YDQBp4a5v6DTgSyzDxxHeisH/zQ9M=; b=j9gd1FhOXcq6VSW/gSzzUUHfqaa9/dhLLeUb5WdWNrGkMZ1dGacEGDyEr+6T9sC1gRMZ7Vef1zCNO+JjPG2VL3fMKUycevijpR9k3ze8oJ79MUwD6hRNAtKIRsSiUHHuIyEoT5vXEwIJAY8k7xGef77gl+Nh+GwqbOyE2bZn9wPWi6M7kRtGuy+r8Odi7A3oAcznEBlH2X7LLEEudONb42mL3IxgzGWMTEwUHA4DCjofd9nIFlqLMVRaXb3rN8XN8VvY4j89K0DmprTmA0IMyFGG34BLYl84Y+RjBb//KvFLqOfhizmLFqkJyBqLgPamRyWP18hRr1CpMWuVY8kmMw== Original-Received: from SG2APC01FT132.eop-APC01.prod.protection.outlook.com (10.152.250.58) by SG2APC01HT213.eop-APC01.prod.protection.outlook.com (10.152.250.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Sat, 4 Jan 2020 04:57:33 +0000 Original-Received: from PS1PR03MB3606.apcprd03.prod.outlook.com (10.152.250.52) by SG2APC01FT132.mail.protection.outlook.com (10.152.250.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Sat, 4 Jan 2020 04:57:33 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:0F2FDBD4B667765E77911922702A00C0314429EF212F0C906838A6A44D595835; UpperCasedChecksum:6D67505818FF637E887378A4623E8511E10BD7046213FE8709B691C9525545B7; SizeAsReceived:8705; Count:47 Original-Received: from PS1PR03MB3606.apcprd03.prod.outlook.com ([fe80::b470:80bc:efed:9117]) by PS1PR03MB3606.apcprd03.prod.outlook.com ([fe80::b470:80bc:efed:9117%7]) with mapi id 15.20.2623.002; Sat, 4 Jan 2020 04:57:33 +0000 In-Reply-To: <41b3e9a0-2866-4692-a35c-6d9541bc3aaa@Spark> X-Readdle-Message-ID: 92481ca8-d8b0-40b3-9813-03cd7fbae899@Spark X-ClientProxiedBy: HK2PR06CA0012.apcprd06.prod.outlook.com (2603:1096:202:2e::24) To PS1PR03MB3606.apcprd03.prod.outlook.com (2603:1096:803:4e::17) X-Microsoft-Original-Message-ID: <92481ca8-d8b0-40b3-9813-03cd7fbae899@Spark> Original-Received: from [192.168.1.103] (1.199.245.197) by HK2PR06CA0012.apcprd06.prod.outlook.com (2603:1096:202:2e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.10 via Frontend Transport; Sat, 4 Jan 2020 04:57:32 +0000 X-Readdle-Message-ID: 92481ca8-d8b0-40b3-9813-03cd7fbae899@Spark X-Microsoft-Original-Message-ID: <92481ca8-d8b0-40b3-9813-03cd7fbae899@Spark> X-TMN: [59/zzHiTMD5gBcNV+mrnEeiNA3v6vGjI] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 4b81b521-4712-40c9-fef9-08d790d29c00 X-MS-TrafficTypeDiagnostic: SG2APC01HT213: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zBSqtztt6d3Tg8prwXVfnawx7PKIKMNqmYYx5CSXqnzODUW7QTIH8+jj2w8sHMS1w09nTCS/XdukbIjtUcqGI8sL0S+8fOw6zJkMQE6/KoQvBL/5LbT1o29azeQcIFzLaTnu2DR3Ka1kGoMLi1bZqdDREZ9jMMg9gvZA+5efa5CGnup2uZrMd0QiAgZm2Cag X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b81b521-4712-40c9-fef9-08d790d29c00 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2020 04:57:33.3485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT213 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.92.253.76 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:243907 Archived-At: --5e101b39_2d9df57d_4379 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline For font-lock, I think it may work with tree-sitter like this: 1. After openning a file, parse the whole buffer with tree-sitter. We get a syntax tree from tree-sitter. 2. Get the syntax nodes with ts_node_descendant_for_point_range and fontify the buffer text in the visible region or whole buffer. 3. After each modification of buffer text, make a copy of the syntax tree as the new one. Update the new one with the modification. 4. Get the changed range and changed nodes list by comparing the old and new syntax trees. Then free the old syntax tree. 5. Update the text properties in the changed range. 6. Goto 3 --5e101b39_2d9df57d_4379 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
For font-lock, I think it may work with tree-sitter like = this:
1. After openning a file, parse the whole buffer with tre= e-sitter. We get a syntax tree from tree-sitter.
2. Get the syntax nodes with ts_node_descendant_for_point= _range and fontify the buffer text in the visible region or whole buffer.
3. After each modification of buffer text, make a copy of= the syntax tree as the new one. Update the new one with the modification.<= /div>
4. Get the changed range and changed nodes list by compar= ing the old and new syntax trees. Then free the old syntax tree.
5. Update the text properties in the changed range.
6. Goto 3

--5e101b39_2d9df57d_4379--