This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-14
lines changed Expand file tree Collapse file tree 4 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 11module SqlSquared.Parser.Tokenizer
22 ( tokenize
3+ , keywords
34 , Token (..)
45 , Literal (..)
56 , PositionedToken
Original file line number Diff line number Diff line change 11module SqlSquared.Signature.Ident where
22
3- import SqlSquared.Utils (escapeIdent )
3+ import Prelude
4+
5+ import Data.Set as Set
6+ import Data.String as S
7+ import Data.String.Regex (test , replace ) as Regex
8+ import Data.String.Regex.Flags (ignoreCase , global ) as Regex
9+ import Data.String.Regex.Unsafe (unsafeRegex ) as Regex
10+ import SqlSquared.Parser.Tokenizer (keywords )
411
512printIdent ∷ String → String
6- printIdent = escapeIdent " `"
13+ printIdent ident =
14+ if Regex .test identifier ident && not (Set .member (S .toLower ident) keywords)
15+ then ident
16+ else " `" <> Regex .replace tick (" \\ `" ) ident <> " `"
17+ where
18+ identifier = Regex .unsafeRegex " ^[a-z][_a-z0-9]*$" Regex .ignoreCase
19+ tick = Regex .unsafeRegex " `" Regex .global
Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ module SqlSquared.Utils where
22
33import Prelude
44import Data.Functor.Coproduct (Coproduct , coproduct )
5- import Data.String.Regex (test , replace ) as Regex
6- import Data.String.Regex.Flags (ignoreCase , global ) as Regex
7- import Data.String.Regex.Unsafe (unsafeRegex ) as Regex
85import Data.Tuple (Tuple (..))
96
107infixr 4 type Tuple as ×
@@ -17,12 +14,3 @@ composeFlipped ∷ ∀ a b c d. Semigroupoid a ⇒ a b c → a c d → a b d
1714composeFlipped f g = compose g f
1815
1916infixr 9 composeFlipped as ⋙
20-
21- escapeIdent ∷ String → String → String
22- escapeIdent delim ident =
23- if Regex .test identifier ident
24- then ident
25- else delim <> Regex .replace tick (" \\ " <> delim) ident <> delim
26- where
27- identifier = Regex .unsafeRegex " ^[a-z][_a-z0-9]*$" Regex .ignoreCase
28- tick = Regex .unsafeRegex delim Regex .global
Original file line number Diff line number Diff line change @@ -176,6 +176,14 @@ testSuite1 = do
176176 industry
177177 """
178178
179+ parseFail """
180+ select foo as between from bar
181+ """
182+
183+ parseSucc """
184+ select foo as `between` from bar
185+ """
186+
179187testSuite2 ∷ ∀ e . TestSuite (testOutput ∷ Console.TESTOUTPUT | e )
180188testSuite2 = do
181189 parseSucc """
You can’t perform that action at this time.
0 commit comments