Skip to content

Commit

Permalink
Add suport for quotes and double quotes for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
davesavic committed Oct 18, 2023
1 parent 1240481 commit a06d461
Show file tree
Hide file tree
Showing 14 changed files with 577 additions and 411 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@ csvshift --source large-file.csv --destination transformed-file.csv --path scrip

#### Script.csvshift
```
Input Columns first_name, last_name, email, phone_number
Input Columns id, first_name, last_name, address, dob
Column email
-> ToLower
Column last_name
-> Trim
-> Replace "S" with "K"
Columns first_name, last_name
-> Trim
-> Replace "K" with "L"
-> Join with " " as full_name
Column email
-> Split on "@" as handle, domain
Column address
-> Split on "," as street, city, state
Columns street, city, state
-> Trim
Column state
-> Split on " " as state, postcode, country
Column dob
-> RegexReplace "(\d{4})-(\d{2})-(\d{2})" with "$3/$2/$1"
Column domain
-> Replace "@" with ""
Column dob
-> RegexExtract "(\d{2})\/(\d{2})\/(\d{4})" as day, month, year
Output Columns full_name, handle, domain, phone_number
Output Columns id, full_name, street, city, state, postcode, country, dob, day, month, year
```

#### Source.csv
Expand Down
2 changes: 1 addition & 1 deletion application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
parser "csvshift/gen"
"csvshift/listeners"
"encoding/csv"
"github.com/antlr4-go/antlr"
"github.com/antlr4-go/antlr/v4"
"io"
"log"
"os"
Expand Down
4 changes: 1 addition & 3 deletions gen/CsvShiftGrammar.interp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ null
'with'
'as'
','
'"'
'->'
null
null
Expand All @@ -38,7 +37,6 @@ REGEXEXTRACT
WITH
AS
COMMA
QUOTE
ARROW
IDENTIFIER
STRING
Expand All @@ -57,4 +55,4 @@ columns


atn:
[4, 1, 20, 99, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4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 0, 31, 32, 5, 2, 0, 0, 32, 33, 3, 16, 8, 0, 33, 5, 1, 0, 0, 0, 34, 37, 3, 8, 4, 0, 35, 37, 3, 10, 5, 0, 36, 34, 1, 0, 0, 0, 36, 35, 1, 0, 0, 0, 37, 7, 1, 0, 0, 0, 38, 39, 5, 3, 0, 0, 39, 41, 5, 18, 0, 0, 40, 42, 3, 12, 6, 0, 41, 40, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 41, 1, 0, 0, 0, 43, 44, 1, 0, 0, 0, 44, 9, 1, 0, 0, 0, 45, 46, 5, 4, 0, 0, 46, 48, 3, 16, 8, 0, 47, 49, 3, 14, 7, 0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 11, 1, 0, 0, 0, 52, 72, 5, 5, 0, 0, 53, 54, 5, 6, 0, 0, 54, 55, 5, 19, 0, 0, 55, 56, 5, 13, 0, 0, 56, 72, 5, 19, 0, 0, 57, 72, 5, 8, 0, 0, 58, 72, 5, 9, 0, 0, 59, 60, 5, 10, 0, 0, 60, 61, 5, 19, 0, 0, 61, 62, 5, 14, 0, 0, 62, 72, 3, 16, 8, 0, 63, 64, 5, 11, 0, 0, 64, 65, 5, 19, 0, 0, 65, 66, 5, 13, 0, 0, 66, 72, 5, 19, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 5, 19, 0, 0, 69, 70, 5, 14, 0, 0, 70, 72, 3, 16, 8, 0, 71, 52, 1, 0, 0, 0, 71, 53, 1, 0, 0, 0, 71, 57, 1, 0, 0, 0, 71, 58, 1, 0, 0, 0, 71, 59, 1, 0, 0, 0, 71, 63, 1, 0, 0, 0, 71, 67, 1, 0, 0, 0, 72, 13, 1, 0, 0, 0, 73, 89, 5, 5, 0, 0, 74, 75, 5, 6, 0, 0, 75, 76, 5, 19, 0, 0, 76, 77, 5, 13, 0, 0, 77, 89, 5, 19, 0, 0, 78, 79, 5, 7, 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7, 1, 7, 1, 7, 1, 7, 3, 7, 89, 8, 7, 1, 8, 1, 8, 1, 8, 5, 8, 94, 8, 8, 10, 8, 12, 8, 97, 9, 8, 1, 8, 0, 0, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 0, 105, 0, 18, 1, 0, 0, 0, 2, 28, 1, 0, 0, 0, 4, 31, 1, 0, 0, 0, 6, 36, 1, 0, 0, 0, 8, 38, 1, 0, 0, 0, 10, 45, 1, 0, 0, 0, 12, 71, 1, 0, 0, 0, 14, 88, 1, 0, 0, 0, 16, 90, 1, 0, 0, 0, 18, 22, 3, 2, 1, 0, 19, 21, 3, 6, 3, 0, 20, 19, 1, 0, 0, 0, 21, 24, 1, 0, 0, 0, 22, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 25, 1, 0, 0, 0, 24, 22, 1, 0, 0, 0, 25, 26, 3, 4, 2, 0, 26, 27, 5, 0, 0, 1, 27, 1, 1, 0, 0, 0, 28, 29, 5, 1, 0, 0, 29, 30, 3, 16, 8, 0, 30, 3, 1, 0, 0, 0, 31, 32, 5, 2, 0, 0, 32, 33, 3, 16, 8, 0, 33, 5, 1, 0, 0, 0, 34, 37, 3, 8, 4, 0, 35, 37, 3, 10, 5, 0, 36, 34, 1, 0, 0, 0, 36, 35, 1, 0, 0, 0, 37, 7, 1, 0, 0, 0, 38, 39, 5, 3, 0, 0, 39, 41, 5, 17, 0, 0, 40, 42, 3, 12, 6, 0, 41, 40, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 41, 1, 0, 0, 0, 43, 44, 1, 0, 0, 0, 44, 9, 1, 0, 0, 0, 45, 46, 5, 4, 0, 0, 46, 48, 3, 16, 8, 0, 47, 49, 3, 14, 7, 0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 11, 1, 0, 0, 0, 52, 72, 5, 5, 0, 0, 53, 54, 5, 6, 0, 0, 54, 55, 5, 18, 0, 0, 55, 56, 5, 13, 0, 0, 56, 72, 5, 18, 0, 0, 57, 72, 5, 8, 0, 0, 58, 72, 5, 9, 0, 0, 59, 60, 5, 10, 0, 0, 60, 61, 5, 18, 0, 0, 61, 62, 5, 14, 0, 0, 62, 72, 3, 16, 8, 0, 63, 64, 5, 11, 0, 0, 64, 65, 5, 18, 0, 0, 65, 66, 5, 13, 0, 0, 66, 72, 5, 18, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 5, 18, 0, 0, 69, 70, 5, 14, 0, 0, 70, 72, 3, 16, 8, 0, 71, 52, 1, 0, 0, 0, 71, 53, 1, 0, 0, 0, 71, 57, 1, 0, 0, 0, 71, 58, 1, 0, 0, 0, 71, 59, 1, 0, 0, 0, 71, 63, 1, 0, 0, 0, 71, 67, 1, 0, 0, 0, 72, 13, 1, 0, 0, 0, 73, 89, 5, 5, 0, 0, 74, 75, 5, 6, 0, 0, 75, 76, 5, 18, 0, 0, 76, 77, 5, 13, 0, 0, 77, 89, 5, 18, 0, 0, 78, 79, 5, 7, 0, 0, 79, 80, 5, 18, 0, 0, 80, 81, 5, 14, 0, 0, 81, 89, 5, 17, 0, 0, 82, 89, 5, 8, 0, 0, 83, 89, 5, 9, 0, 0, 84, 85, 5, 11, 0, 0, 85, 86, 5, 18, 0, 0, 86, 87, 5, 13, 0, 0, 87, 89, 5, 18, 0, 0, 88, 73, 1, 0, 0, 0, 88, 74, 1, 0, 0, 0, 88, 78, 1, 0, 0, 0, 88, 82, 1, 0, 0, 0, 88, 83, 1, 0, 0, 0, 88, 84, 1, 0, 0, 0, 89, 15, 1, 0, 0, 0, 90, 95, 5, 17, 0, 0, 91, 92, 5, 15, 0, 0, 92, 94, 5, 17, 0, 0, 93, 91, 1, 0, 0, 0, 94, 97, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 17, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 7, 22, 36, 43, 50, 71, 88, 95]
12 changes: 5 additions & 7 deletions gen/CsvShiftGrammar.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ REGEXEXTRACT=12
WITH=13
AS=14
COMMA=15
QUOTE=16
ARROW=17
IDENTIFIER=18
STRING=19
WS=20
ARROW=16
IDENTIFIER=17
STRING=18
WS=19
'Input Columns'=1
'Output Columns'=2
'Column'=3
Expand All @@ -33,5 +32,4 @@ WS=20
'with'=13
'as'=14
','=15
'"'=16
'->'=17
'->'=16
Loading

0 comments on commit a06d461

Please sign in to comment.