Skip to content

Commit

Permalink
fix: typo in unknown segments
Browse files Browse the repository at this point in the history
Rearrange regexps so "special" regexp catches everything not caught by other regexps.
Eliminates the "unknown" segment I added in #148.

In practice, the only time we would hit the "unknown" segment is for a few weird
characters that weren't already caught by the "special" segment, for example, the
? and unclosed ` in "a `?> b".  I figured that in those rare cases, we might as
well just call those characters "special".

Fixes #178, refs #148.
  • Loading branch information
wkeese committed Apr 14, 2024
1 parent 353542a commit 47884ee
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/index.js
Expand Up @@ -33,18 +33,15 @@ const highlighters = [

/(?<bracket>[()])/,

// Arithmetic, bitwise, comparison, and compound operators as listed in
// https://www.w3schools.com/sql/sql_operators.asp, https://www.tutorialspoint.com/sql/sql-operators.htm,
// https://data-flair.training/blogs/sql-operators/.
// Plus a few other symbols used in SQL statements: ,;:.
// Operators are arranged so that multi-character operators (ex: ">=") are parsed as one operator rather than two.
/(?<special>\^-=|\|\*=|\+=|-=|\*=|\/=|%=|&=|>=|<=|<>|!=|!<|!>|>>|<<|[+\-*/%&|^=><]|[,;:.])/,

/(?<identifier>\b\w+\b|`(?:[^`\\]|\\.)*`)/,

/(?<whitespace>\s+)/,

/(?<unknown>\.+?)/
// Multi-character arithmetic, bitwise, comparison, and compound operators as listed in
// https://www.w3schools.com/sql/sql_operators.asp, https://www.tutorialspoint.com/sql/sql-operators.htm,
// https://data-flair.training/blogs/sql-operators/, plus any single character (in particular ,:;.) not matched by
// the above regexps.
/(?<special>\^-=|\|\*=|\+=|-=|\*=|\/=|%=|&=|>=|<=|<>|!=|!<|!>|>>|<<|.)/
]

// Regex of the shape /(?<token1>...)|(?<token2>...)|.../g
Expand Down

0 comments on commit 47884ee

Please sign in to comment.