Skip to content

Commit 2756588

Browse files
authored
Merge pull request stadelmanma#49 from stadelmanma/use-external-scanner-for-number-literals
Use external scanner for number literals
2 parents 7a2e77f + 93810e0 commit 2756588

File tree

8 files changed

+27978
-26506
lines changed

8 files changed

+27978
-26506
lines changed

grammar.js

+13-25
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ module.exports = grammar({
5151
name: 'fortran',
5252

5353
externals: $ => [
54-
$._line_continuation
54+
$._line_continuation,
55+
$._integer_literal,
56+
$._float_literal,
57+
$._boz_literal
5558
],
5659

5760
extras: $ => [
@@ -522,9 +525,9 @@ module.exports = grammar({
522525
$.read_statement
523526
),
524527

525-
statement_label: $ => /\d+/,
528+
statement_label: $ => prec(1, alias($._integer_literal, 'statement_label')),
526529

527-
_statement_label_reference: $ => alias($.statement_label, $.statement_label_reference),
530+
statement_label_reference: $ => alias($.statement_label, 'statement_label_reference'),
528531

529532
assignment_statement: $ => prec.right(PREC.ASSIGNMENT, seq(
530533
$._expression,
@@ -827,7 +830,7 @@ module.exports = grammar({
827830
)),
828831

829832
format_identifier: $ => choice(
830-
$._statement_label_reference,
833+
$.statement_label_reference,
831834
$._io_expressions
832835
),
833836

@@ -1010,27 +1013,6 @@ module.exports = grammar({
10101013

10111014
array_literal: $ => seq('(/', commaSep1($._expression), '/)'),
10121015

1013-
number_literal: $ => token(
1014-
choice(
1015-
// integer, real with and without exponential notation
1016-
/(((\d*\.)?\d+)|(\d+(\.\d*)?))([eEdD][-+]?\d+)?(_[a-zA-Z_]+)?/,
1017-
// binary literal
1018-
/[bB]'[01]+'/,
1019-
/'[01]+'[bB]/,
1020-
/[bB]"[01]+"/,
1021-
/"[01]+"[bB]/,
1022-
// octal literal
1023-
/[oO]'[0-8]+'/,
1024-
/'[0-8]+'[oO]/,
1025-
/[oO]"[0-8]+"/,
1026-
/"[0-8]+"[oO]/,
1027-
// hexcadecimal
1028-
/[zZ]'[0-9a-fA-F]+'/,
1029-
/'[0-9a-fA-F]+'[zZ]/,
1030-
/[zZ]"[0-9a-fA-F]+"/,
1031-
/"[0-9a-fA-F]+"[zZ]/
1032-
)),
1033-
10341016
complex_literal: $ => seq(
10351017
'(',
10361018
choice($.number_literal, $.identifier),
@@ -1039,6 +1021,12 @@ module.exports = grammar({
10391021
')'
10401022
),
10411023

1024+
number_literal: $ => choice(
1025+
$._integer_literal,
1026+
$._float_literal,
1027+
$._boz_literal
1028+
),
1029+
10421030
string_literal: $ => choice(
10431031
$._double_quoted_string,
10441032
$._single_quoted_string

src/grammar.json

+44-66
Original file line numberDiff line numberDiff line change
@@ -2594,16 +2594,25 @@
25942594
]
25952595
},
25962596
"statement_label": {
2597-
"type": "PATTERN",
2598-
"value": "\\d+"
2597+
"type": "PREC",
2598+
"value": 1,
2599+
"content": {
2600+
"type": "ALIAS",
2601+
"content": {
2602+
"type": "SYMBOL",
2603+
"name": "_integer_literal"
2604+
},
2605+
"named": false,
2606+
"value": "statement_label"
2607+
}
25992608
},
2600-
"_statement_label_reference": {
2609+
"statement_label_reference": {
26012610
"type": "ALIAS",
26022611
"content": {
26032612
"type": "SYMBOL",
26042613
"name": "statement_label"
26052614
},
2606-
"named": true,
2615+
"named": false,
26072616
"value": "statement_label_reference"
26082617
},
26092618
"assignment_statement": {
@@ -3801,7 +3810,7 @@
38013810
},
38023811
"edit_descriptor": {
38033812
"type": "PATTERN",
3804-
"value": "[a-zA-Z0-9\\/:.*]+"
3813+
"value": "[a-zA-Z0-9/:.*]+"
38053814
},
38063815
"read_statement": {
38073816
"type": "CHOICE",
@@ -4323,7 +4332,7 @@
43234332
"members": [
43244333
{
43254334
"type": "SYMBOL",
4326-
"name": "_statement_label_reference"
4335+
"name": "statement_label_reference"
43274336
},
43284337
{
43294338
"type": "SYMBOL",
@@ -5615,66 +5624,6 @@
56155624
}
56165625
]
56175626
},
5618-
"number_literal": {
5619-
"type": "TOKEN",
5620-
"content": {
5621-
"type": "CHOICE",
5622-
"members": [
5623-
{
5624-
"type": "PATTERN",
5625-
"value": "(((\\d*\\.)?\\d+)|(\\d+(\\.\\d*)?))([eEdD][-+]?\\d+)?(_[a-zA-Z_]+)?"
5626-
},
5627-
{
5628-
"type": "PATTERN",
5629-
"value": "[bB]'[01]+'"
5630-
},
5631-
{
5632-
"type": "PATTERN",
5633-
"value": "'[01]+'[bB]"
5634-
},
5635-
{
5636-
"type": "PATTERN",
5637-
"value": "[bB]\"[01]+\""
5638-
},
5639-
{
5640-
"type": "PATTERN",
5641-
"value": "\"[01]+\"[bB]"
5642-
},
5643-
{
5644-
"type": "PATTERN",
5645-
"value": "[oO]'[0-8]+'"
5646-
},
5647-
{
5648-
"type": "PATTERN",
5649-
"value": "'[0-8]+'[oO]"
5650-
},
5651-
{
5652-
"type": "PATTERN",
5653-
"value": "[oO]\"[0-8]+\""
5654-
},
5655-
{
5656-
"type": "PATTERN",
5657-
"value": "\"[0-8]+\"[oO]"
5658-
},
5659-
{
5660-
"type": "PATTERN",
5661-
"value": "[zZ]'[0-9a-fA-F]+'"
5662-
},
5663-
{
5664-
"type": "PATTERN",
5665-
"value": "'[0-9a-fA-F]+'[zZ]"
5666-
},
5667-
{
5668-
"type": "PATTERN",
5669-
"value": "[zZ]\"[0-9a-fA-F]+\""
5670-
},
5671-
{
5672-
"type": "PATTERN",
5673-
"value": "\"[0-9a-fA-F]+\"[zZ]"
5674-
}
5675-
]
5676-
}
5677-
},
56785627
"complex_literal": {
56795628
"type": "SEQ",
56805629
"members": [
@@ -5718,6 +5667,23 @@
57185667
}
57195668
]
57205669
},
5670+
"number_literal": {
5671+
"type": "CHOICE",
5672+
"members": [
5673+
{
5674+
"type": "SYMBOL",
5675+
"name": "_integer_literal"
5676+
},
5677+
{
5678+
"type": "SYMBOL",
5679+
"name": "_float_literal"
5680+
},
5681+
{
5682+
"type": "SYMBOL",
5683+
"name": "_boz_literal"
5684+
}
5685+
]
5686+
},
57215687
"string_literal": {
57225688
"type": "CHOICE",
57235689
"members": [
@@ -5872,6 +5838,18 @@
58725838
{
58735839
"type": "SYMBOL",
58745840
"name": "_line_continuation"
5841+
},
5842+
{
5843+
"type": "SYMBOL",
5844+
"name": "_integer_literal"
5845+
},
5846+
{
5847+
"type": "SYMBOL",
5848+
"name": "_float_literal"
5849+
},
5850+
{
5851+
"type": "SYMBOL",
5852+
"name": "_boz_literal"
58755853
}
58765854
],
58775855
"inline": [

0 commit comments

Comments
 (0)