Add tests for numeric literals and get them passing

pull/48/head
Wilfred Hughes 2021-08-14 19:30:45 +07:00
parent 8242420766
commit 01f453ab81
5 changed files with 469 additions and 418 deletions

@ -12,8 +12,8 @@ const INTEGER_WITH_BASE = token(/#([box]|[0-9][0-9]?r)[0-9a-zA-Z]/);
const FLOAT_WITH_DEC_POINT = token(/[+-]?[0-9]*\.[0-9]+/);
const FLOAT_WITH_EXPONENT = token(/[+-]?[0-9]+[eE][0-9]+/);
const FLOAT_WITH_BOTH = token(/[+-]?[0-9]*\.[0-9]+[eE][0-9]+/);
const FLOAT_INF = token(/-?1.0[eE]+INF/);
const FLOAT_NAN = token(/-?0.0[eE]+NaN/);
const FLOAT_INF = token(/-?1.0[eE]\+INF/);
const FLOAT_NAN = token(/-?0.0[eE]\+NaN/);
const CHAR = token(/\?(\\.|.)/);
@ -27,8 +27,7 @@ module.exports = grammar({
quote: ($) => seq(choice("#'", "'", "`"), $._sexp),
unquote: ($) => seq(choice(",@", ","), $._sexp),
_atom: ($) => choice($.integer, $.float, $.char, $.string, $.symbol),
integer: ($) => choice(INTEGER_BASE10, INTEGER_WITH_BASE),
_atom: ($) => choice($.float, $.integer, $.char, $.string, $.symbol),
float: ($) =>
choice(
FLOAT_WITH_DEC_POINT,
@ -37,6 +36,7 @@ module.exports = grammar({
FLOAT_INF,
FLOAT_NAN
),
integer: ($) => choice(INTEGER_BASE10, INTEGER_WITH_BASE),
char: ($) => CHAR,
string: ($) => STRING,
symbol: ($) => SYMBOL,

@ -95,11 +95,11 @@
"members": [
{
"type": "SYMBOL",
"name": "integer"
"name": "float"
},
{
"type": "SYMBOL",
"name": "float"
"name": "integer"
},
{
"type": "SYMBOL",
@ -115,61 +115,61 @@
}
]
},
"integer": {
"float": {
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[+-]?[0-9]+\\.?"
"value": "[+-]?[0-9]*\\.[0-9]+"
}
},
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "#([box]|[0-9][0-9]?r)[0-9a-zA-Z]"
"value": "[+-]?[0-9]+[eE][0-9]+"
}
}
]
},
"float": {
"type": "CHOICE",
"members": [
},
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[+-]?[0-9]*\\.[0-9]+"
"value": "[+-]?[0-9]*\\.[0-9]+[eE][0-9]+"
}
},
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[+-]?[0-9]+[eE][0-9]+"
"value": "-?1.0[eE]\\+INF"
}
},
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[+-]?[0-9]*\\.[0-9]+[eE][0-9]+"
"value": "-?0.0[eE]\\+NaN"
}
},
}
]
},
"integer": {
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "-?1.0[eE]+INF"
"value": "[+-]?[0-9]+\\.?"
}
},
{
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "-?0.0[eE]+NaN"
"value": "#([box]|[0-9][0-9]?r)[0-9a-zA-Z]"
}
}
]
@ -231,7 +231,7 @@
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[a-zA-Z0-9_?:/*+=<>-]+"
"value": "&?[a-zA-Z0-9_?:/*+=<>-]+"
}
},
"list": {

File diff suppressed because it is too large Load Diff

@ -0,0 +1,16 @@
================================================================================
Float literals
================================================================================
1.0
-.1
3E5
1.0e+INF
--------------------------------------------------------------------------------
(source_file
(float)
(float)
(float)
(float))

@ -0,0 +1,14 @@
================================================================================
Integer literals
================================================================================
1
-1.
+1234
--------------------------------------------------------------------------------
(source_file
(integer)
(integer)
(integer))