From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_SBL,URIBL_SBL_A shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 6CACA1FB06 for ; Fri, 8 Oct 2021 19:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240920AbhJHTMB (ORCPT ); Fri, 8 Oct 2021 15:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240479AbhJHTL4 (ORCPT ); Fri, 8 Oct 2021 15:11:56 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D176BC061570 for ; Fri, 8 Oct 2021 12:10:00 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id t2so32643678wrb.8 for ; Fri, 08 Oct 2021 12:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ngZ0ar27WWg0VwBar7AyiNjC3RMv1OoTrNDR7TYg3MA=; b=KxUsVvgtJdhU4xXqHRD70pjjYUiH7SbFPBPhyVrV5wsZ64ie9qmO5tkbuQMbpEMU/I I6gEi1roIbOn5H/q532Q3zsBL2PJG/uvMY2DIYhhTk+EtpdVWzmKTMjWeOhQSriMigQz rFcKkiGAEN4LMrXT1N2YEjCxnDFNrpXbbqXpZClrVNIDXOzM1YAdKxJtnm/g2iHA9WSF HmEQ+h/M/KjJ6i74skhar+dsjhwJ0YiNb1+oYWJxhObCFfgYCIwlvu/Y7lFuawPRTUib Tj+kGY5+6mjvPgdaQ3t5YGnuRwmtwRZikOqFj8e8/1OEsPN21oiOdHbAHGy4bW75amNA eX4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ngZ0ar27WWg0VwBar7AyiNjC3RMv1OoTrNDR7TYg3MA=; b=ivUIVRvO6hLOp3cU8B8bctPnerAw5saRTrVZRQ0M8se+TM4hppBrZk0OGK00daP8X+ uJq9AQLc8MHfaL0H7zRobRxMFvGetSPV6djKCH2rOf8ZvcUtzp8GU9CxalueJ54E62l3 v+x1Izf/2eMdt13eHuAmRSHgssvT5zH03JpRg1Ouz8785TqoLgBgObiienbYc7zAR69d lQkFe2n8UglelrRx1ZJRCaAsRzsZZAJy8iwnO33b0dkfjpASh0R90V/BO/HtxKtnNIZg nkxAyeSPb8rY8Qsrg4MII7qDyICGmghDcdau8nRE6CIKXITNqShdrxse/jYSKzuF406b SIeA== X-Gm-Message-State: AOAM532vaC3W1n5uZxRJ3J19ASmbASpX2/UBet00g1csm1uqUrLz7O3f DRkzEvxdOQAEWYMBLUehgegZjPxkQ0Y= X-Google-Smtp-Source: ABdhPJy/s209MtRInX4nEyxJNafgjotzi34myCAc93z8nfFziZck+pB2BuZEtSSvLnLS9MovyLTpPA== X-Received: by 2002:a5d:6b03:: with SMTP id v3mr6257124wrw.226.1633720199492; Fri, 08 Oct 2021 12:09:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x17sm174306wrc.51.2021.10.08.12.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 12:09:59 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Johannes Sixt via GitGitGadget" Date: Fri, 08 Oct 2021 19:09:55 +0000 Subject: [PATCH v2 3/5] userdiff-cpp: tighten word regex Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?UTF-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0?= Bjarmason , Johannes Sixt , Johannes Sixt Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Sixt Generally, word regex can be written such that they match tokens liberally and need not model the actual syntax because it can be assumed that the regex will only be applied to syntactically correct text. The regex for cpp (C/C++) is too liberal, though. It regards these sequences as single tokens: 1+2 1.5-e+2+f and the following amalgams as one token: .l as in str.length .f as in str.find .e as in str.erase Tighten the regex in the following way: - Accept + and - only in one position in the exponent. + and - are no longer regarded as the sign of a number and are treated by the catcher-all that is not visible in the driver's regex. - Accept a leading decimal point only when it is followed by a digit. For readability, factor hex- and binary numbers into an own term. As a drive-by, this fixes that floating point numbers such as 12E5 (with upper-case E) were split into two tokens. Signed-off-by: Johannes Sixt --- t/t4034/cpp/expect | 16 ++++++++-------- userdiff.c | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/t/t4034/cpp/expect b/t/t4034/cpp/expect index 63e53a61e62..46c9460a968 100644 --- a/t/t4034/cpp/expect +++ b/t/t4034/cpp/expect @@ -3,24 +3,24 @@ --- a/pre +++ b/post @@ -1,30 +1,30 @@ -Foo() : x(0&&1&42) { foo0bar(x.f.Find); } +Foo() : x(0&&1&42) { foo0bar(x.findFind); } cout<<"Hello World!?\n"<(1 -1e10+1e10 0xabcdef) 'xy' +(1 -+1e10 0xabcdef) 'xy' // long double 3.141592653e-10l3.141592654e+10l // float -120E5fE6f +120E5f120E6f // hex -0xdeadbeaf+80xdeadBeaf+7ULL +0xdeadbeaf0xdeadBeaf+8ULL7ULL // octal 0123456701234560 // binary 0b10000b1100+e1 // expression -1.5-e+2+f1.5-e+3+f +1.5-e+23+f // another one -str.e+65.e+75 -[a] b->->*v d.e.*e +str.e+6575 +[a] b->->*v d..*e ~!a !~b c+++ d--- e**f g&&&h a**=b c//=d e%%=f a+++b c---d @@ -30,6 +30,6 @@ a==!=b c!==d a^^=b c||=d e&&&=f a|||b a?:b -a===b c+=+d e-=fe-f g*=*h i/=/j k%=%l m<<=<<n o>>=>>p q&=&r s^=^t u|=|v +a===b c+=+d e-=-f g*=*h i/=/j k%=%l m<<=<<n o>>=>>p q&=&r s^=^t u|=|v a,b a:::b diff --git a/userdiff.c b/userdiff.c index d9b2ba752f0..ce2a9230703 100644 --- a/userdiff.c +++ b/userdiff.c @@ -54,8 +54,14 @@ PATTERNS("cpp", /* functions/methods, variables, and compounds at top level */ "^((::[[:space:]]*)?[A-Za-z_].*)$", /* -- */ + /* identifiers and keywords */ "[a-zA-Z_][a-zA-Z0-9_]*" - "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lLuU]*" + /* decimal and octal integers as well as floatingpoint numbers */ + "|[0-9][0-9.]*([Ee][-+]?[0-9]+)?[fFlLuU]*" + /* hexadecimal and binary integers */ + "|0[xXbB][0-9a-fA-F]+[lLuU]*" + /* floatingpoint numbers that begin with a decimal point */ + "|\\.[0-9]+([Ee][-+]?[0-9]+)?[fFlL]?" "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*"), PATTERNS("csharp", /* Keywords */ -- gitgitgadget