Skip to content

Commit

Permalink
Fix parsing of negative numbers (#12)
Browse files Browse the repository at this point in the history
* Add failing test for negative numbers

* Fix parsing of negative numbers

* Rearrange assertion to avoid extra diff noise
  • Loading branch information
rtsao authored Mar 4, 2021
1 parent 9668e88 commit 94e1023
Show file tree
Hide file tree
Showing 4 changed files with 1,153 additions and 1,218 deletions.
4 changes: 3 additions & 1 deletion corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ a {
c: 5em;
margin: 10E3px;
margin: -456.8px;
margin: -5px;
margin: -0.0px;
}

Expand All @@ -97,6 +98,7 @@ a {
(declaration (property_name) (integer_value (unit)))
(declaration (property_name) (float_value (unit)))
(declaration (property_name) (float_value (unit)))
(declaration (property_name) (integer_value (unit)))
(declaration (property_name) (float_value (unit))))))

============================
Expand Down Expand Up @@ -240,5 +242,5 @@ a-property: calc(5px + var(--a-variable));
---

(stylesheet
(declaration (property_name) (plain_value))
(declaration (property_name) (integer_value (unit)))
(declaration (property_name) (call_expression (function_name) (arguments (binary_expression (integer_value (unit)) (call_expression (function_name) (arguments (plain_value))))))))
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ module.exports = grammar({
')'
),

identifier: $ => /[a-zA-Z-_][a-zA-Z0-9-_]*/,
identifier: $ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*/,

at_keyword: $ => /@[a-zA-Z-_]+/,

Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@
},
"identifier": {
"type": "PATTERN",
"value": "[a-zA-Z-_][a-zA-Z0-9-_]*"
"value": "(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*"
},
"at_keyword": {
"type": "PATTERN",
Expand Down
Loading

0 comments on commit 94e1023

Please sign in to comment.