Skip to content

Commit

Permalink
Require at least one digit before or after '.' in a float
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Nov 9, 2018
1 parent febcfe0 commit ebfe918
Show file tree
Hide file tree
Showing 3 changed files with 4,322 additions and 4,490 deletions.
23 changes: 11 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,19 @@ module.exports = grammar({
)
)),

float: $ => token(
seq(
float: $ => {
const digits = repeat1(/[0-9]+_?/);
const exponent = seq(/[eE][\+-]?/, digits)

return token(seq(
choice(
seq(repeat(/[0-9]+_?/), '.', repeat(/[0-9]+_?/), optional(/[eE][\+-]?/), repeat(/[0-9]+_?/)),
seq(repeat(/[0-9]+_?/), optional(/[eE][\+-]?/), repeat1(/[0-9]+_?/))
seq(digits, '.', optional(digits), optional(exponent)),
seq(optional(digits), '.', digits, optional(exponent)),
seq(digits, exponent)
),
optional(
choice(
optional(/[Ll]/), // long numbers
optional(/[jJ]/) // complex numbers
)
)
)
),
optional(choice(/[Ll]/, /[jJ]/))
))
},

identifier: $ => /[a-zA-Zα-ωΑ-Ω_][a-zA-Zα-ωΑ-Ω_0-9]*/,

Expand Down
127 changes: 88 additions & 39 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3814,7 +3814,7 @@
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
Expand All @@ -3824,39 +3824,71 @@
"type": "STRING",
"value": "."
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[eE][\\+-]?"
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[eE][\\+-]?"
},
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "."
},
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
Expand All @@ -3866,20 +3898,53 @@
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[eE][\\+-]?"
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[eE][\\+-]?"
},
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
}
]
},
{
"type": "BLANK"
}
]
},
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
},
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[eE][\\+-]?"
},
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[0-9]+_?"
}
}
]
}
]
}
Expand All @@ -3892,28 +3957,12 @@
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[Ll]"
},
{
"type": "BLANK"
}
]
"type": "PATTERN",
"value": "[Ll]"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[jJ]"
},
{
"type": "BLANK"
}
]
"type": "PATTERN",
"value": "[jJ]"
}
]
},
Expand Down
Loading

0 comments on commit ebfe918

Please sign in to comment.