Skip to content

Commit

Permalink
Improve things (#1)
Browse files Browse the repository at this point in the history
fix: Handle negative numbers
  • Loading branch information
huacnlee authored Apr 12, 2024
1 parent ae0728a commit 85a9705
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 364 deletions.
4 changes: 4 additions & 0 deletions examples/example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name,city,state,zip,"latitude","longitude",signed
Mcdonalds,"Los Angeles",CA,90001,33.973951,-118.248405,true
Dennys,"New York",NY,10001,40.750634,-73.997177,true
"Burger King",Chicago,IL,60601,41.884151,-87.622848,false
4 changes: 2 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ module.exports = grammar({
$.float,
$.integer,
),
integer: $ => /\d+/,
integer: $ => /-?\d+/,
hex: $ => /0[xX][\da-fA-F]+/,
float: $ => /(0|[1-9]\d*)\.\d+/,
float: $ => /-?(0|[1-9]\d*)\.\d+/,
string: $ => choice(
seq($.quote, $.quote),
seq($.quote, $.escaped, $.quote),
Expand Down
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
"version": "0.1.0",
"description": "CSV grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
"parser",
"tree-sitter",
"csv"
],
"keywords": ["parser", "tree-sitter", "csv"],
"author": "Arnau Siches",
"license": "MIT",
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"test": "tree-sitter test"
"test": "tree-sitter test",
"dev": "npm run build && tree-sitter highlight examples/*.csv"
},
"dependencies": {
"nan": "^2.17.0",
Expand All @@ -24,9 +21,7 @@
"tree-sitter": [
{
"scope": "source.csv",
"file-types": [
"csv"
]
"file-types": ["csv"]
}
]
}
3 changes: 1 addition & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
(null)
(na)
] @constant.builtin

(string) @string

(escape_sequence) @constant.character.escape


; Punctuation
(delimiter) @punctuation.delimiter
(quote) @punctuation.bracket

39 changes: 28 additions & 11 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,50 @@
"value": "true|TRUE|false|FALSE"
},
"_number": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "hex"
},
{
"type": "SYMBOL",
"name": "float"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "integer"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "hex"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "integer"
}
]
}
]
},
"integer": {
"type": "PATTERN",
"value": "\\d+"
"value": "-?\\d+"
},
"hex": {
"type": "PATTERN",
"value": "0[xX][\\da-fA-F]+"
},
"float": {
"type": "PATTERN",
"value": "(0|[1-9]\\d*)\\.\\d+"
"value": "-?(0|[1-9]\\d*)\\.\\d+"
},
"string": {
"type": "CHOICE",
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
"type": "\r\n",
"named": false
},
{
"type": "-",
"named": false
},
{
"type": "boolean",
"named": true
Expand Down
Loading

0 comments on commit 85a9705

Please sign in to comment.