Skip to content

replace some regex patterns with more tpre friendlier ones #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions PLUGINS/FRONTEND/C/c-smart-tokenize.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ let std-c-tokenize-string(file-path: String, text: String): List<Token> = (
"\t".. rest => text = rest;
"\n".. rest => text = rest;

(comment=r/^\/\/[^\n]*/).. rest => (
(comment=r/^\/\/.*?(?:\r\n|\n|$)/).. rest => (
text = rest;
);

# TODO, allow * character in block comments
# posix extended regular expressions don't do well here
# this isn't very important though because cpp should remove comments
(comment=r/\/[*]([^*])*[*]\//).. rest => (
(comment=r/^\/\*(?:.|\s)*?\*\//).. rest => (
text = rest;
);

Expand Down Expand Up @@ -72,23 +69,23 @@ let std-c-tokenize-string(file-path: String, text: String): List<Token> = (
".".. rest => (tokens = cons(text[:".".length], tokens); text = rest;);
"-".. rest => (tokens = cons(text[:"-".length], tokens); text = rest;);

(cl=r/^[0][x][0-9a-fA-F]+([.][0-9a-fA-F]+)?([eE][0-9a-fA-F]+)?([pP][0-9]+)(fF)?/).. rest => (
(cl=r/^[0][x][0-9a-fA-F]+(\.[0-9a-fA-F]+)?([eE][0-9a-fA-F]+)?([pP][0-9]+)(fF)?/).. rest => (
tokens = cons(text[:cl.length], tokens); text = rest;
);
(cl=r/^[0][x][0-9a-fA-F]+([uU]|[lL]|wb|WB)*/).. rest => (
(cl=r/^[0][x][0-9a-fA-F]+?([uU]|[lL]|wb|WB)*/).. rest => (
tokens = cons(text[:cl.length], tokens); text = rest;
);
(cl=r/^[0][bB][01]+([uU]|[lL]|wb|WB)*/).. rest => (
(cl=r/^[0][bB][01]+?([uU]|[lL]|wb|WB)*/).. rest => (
tokens = cons(text[:cl.length], tokens); text = rest;
);
(cl=r/^[0-9]+([uU]|[lL]|wb|WB)*([.][0-9]+)?([eE][0-9]+)?[fF]?/).. rest => (
(cl=r/^[0-9]+?([uU]|[lL]|wb|WB)*?(\.[0-9]+?)?([eE][0-9]+?)?[fF]?/).. rest => (
tokens = cons(text[:cl.length], tokens); text = rest;
);
(cl=r/^(u8|u|U|L)?[']([^']|([\\][']))+[']/).. rest => (
(cl=r/^(u8|u|U|L)?[']([^']|([\\][']))+?[']/).. rest => (
tokens = cons(text[:cl.length], tokens); text = rest;
);

(lit=r/^[RLuU8]*["]([^"\\]|([\\].))*["]/).. rest => (
(lit=r/^[RLuU8]*?["]([^"\\]|([\\].))*?["]/).. rest => (
tokens = cons(text[:lit.length], tokens); text = rest;
);

Expand Down
8 changes: 4 additions & 4 deletions PLUGINS/FRONTEND/LSTS/lsts-smart-tokenize.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ let lsts-tokenize-string(file-path: String, text: String): List<Token> = (
push-newline = 1;
);

(lit=r/^[cl]?["]([^"\\]|([\\].))*["]/).. rest => (
(lit=r/^[cl]?["]([^"\\]|([\\].))*?["]/).. rest => (
tokens = cons(text[:lit.length], tokens); text = rest;
);

(rgx=r/^r[\/]([^\/]|([\\].))*[\/]/).. rest => (
(rgx=r/^r[\/]([^\/]|([\\].))*?[\/]/).. rest => (
tokens = cons(text[:rgx.length], tokens); text = rest;
);

(id=r/^[$]["]([^"\\]|([\\].))*["]/).. rest => (
(id=r/^[$]["]([^"\\]|([\\].))*?["]/).. rest => (
tokens = cons(text[:id.length], tokens); text = rest;
);

(id=r/^[a-zA-Z0-9_-]+/).. rest => (
tokens = cons(text[:id.length], tokens); text = rest;
);

(comment=r/^#[^\n]*[\n]/).. rest => (
(comment=r/^#[^\n]*?[\n]/).. rest => (
text = rest;
);

Expand Down
Loading