pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Is there a way make the lex program match multiple line?
3+ messages / 2 participants
[nested] [flat]

* Is there a way make the lex program match multiple line?
@ 2023-06-18 01:17  Wen Yi <896634148@qq.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Wen Yi @ 2023-06-18 01:17 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi community,
I am making a config program, use the lex program to analyse input.


/*
&nbsp;&nbsp; &nbsp;config.l
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; The lex rule file for toysql
&nbsp;&nbsp; &nbsp;Wen Yi
*/
%option noyywrap
%{
#include <string.h&gt;
#include <stdlib.h&gt;&nbsp;&nbsp;&nbsp; 
%}
%%
-[0-9]+.[0-9]+|[0-9]+.[0-9]+|-[0-9]+|[0-9]+ { printf("Number = %lf\n", atof(yytext)); }
[a-zA-Z_0-9]+&nbsp; { printf("Token = %s\n", yytext); }
['].+['] { 
&nbsp;&nbsp; &nbsp;yytext[yyleng - 1] = '\0';
&nbsp;&nbsp; &nbsp;memmove(yytext, yytext + 1, yyleng - 1);
&nbsp;&nbsp; &nbsp;printf("String = %s\n", yytext);
}

; {}
. { printf("Anything: '%s'\n", yytext);&nbsp; }
%%
int main()
{
&nbsp;&nbsp; &nbsp;yylex();
&nbsp;&nbsp; &nbsp;return 0;
}


But when I try to run it:



[beginnerc@bogon config]$ ./a.out
'This is a single line string'
String = This is a single line string

'This is a multiple line string
Anything: '''
Token = This
Anything: ' '
Token = is
Anything: ' '
Token = a
Anything: ' '
Token = multiple
Anything: ' '
Token = line
Anything: ' '
Token = string

Can someone give me some advice to make the ['].+['] match multiple string?
Thanks in advance!


Yours,
Wen Yi

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Is there a way make the lex program match multiple line?
@ 2023-06-18 01:50  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wen Yi <896634148@qq.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2023-06-18 01:50 UTC (permalink / raw)
  To: Wen Yi <896634148@qq.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

"=?ISO-8859-1?B?V2VuIFlp?=" <896634148@qq.com> writes:
> Can someone give me some advice to make the ['].+['] match multiple string?

You should check the flex manual, but it's likely that "." doesn't
match newline.  Another problem with this pattern is that "."
*does* match "'", so it's ambiguous what will happen with quotes.
You probably need something closer to [']([^']|\n)[']

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Is there a way make the lex program match multiple line?
@ 2023-06-18 02:53  Wen Yi <896634148@qq.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Wen Yi @ 2023-06-18 02:53 UTC (permalink / raw)
  To: Tom&nbsp;Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

I rewrite, and I think the [']([^']|\n)['] should be [']([^']|\n)+[']
Thanks very much!



Yours,
Wen Yi.







 




------------------ Original ------------------
From:                                                                                                                        "Tom Lane"                                                                                    <tgl@sss.pgh.pa.us>;
Date: Sun, Jun 18, 2023 09:50 AM
To: "Wen Yi"<896634148@qq.com>;
Cc: "pgsql-general"<pgsql-general@lists.postgresql.org>;
Subject: Re: Is there a way make the lex program match multiple line?



"=?ISO-8859-1?B?V2VuIFlp?=" <896634148@qq.com> writes:
> Can someone give me some advice to make the ['].+['] match multiple string?

You should check the flex manual, but it's likely that "." doesn't
match newline.  Another problem with this pattern is that "."
*does* match "'", so it's ambiguous what will happen with quotes.
You probably need something closer to [']([^']|\n)[']

 regards, tom lane

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-06-18 02:53 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 01:17 Is there a way make the lex program match multiple line? Wen Yi <896634148@qq.com>
2023-06-18 01:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-06-18 02:53   ` Wen Yi <896634148@qq.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox