@@ -9,6 +9,7 @@ import type {
9
9
import type { Context } from './Context' ;
10
10
import type { AlgorithmBiblioEntry , ExportedBiblio , StepBiblioEntry , Type } from './Biblio' ;
11
11
import type { BuilderInterface } from './Builder' ;
12
+ import type { AlgorithmElementWithTree } from './Algorithm' ;
12
13
13
14
import * as path from 'path' ;
14
15
import * as fs from 'fs' ;
@@ -45,7 +46,7 @@ import {
45
46
import { lint } from './lint/lint' ;
46
47
import { CancellationToken } from 'prex' ;
47
48
import type { JSDOM } from 'jsdom' ;
48
- import type { OrderedListNode , parseAlgorithm } from 'ecmarkdown' ;
49
+ import type { OrderedListNode } from 'ecmarkdown' ;
49
50
import { getProductions , rhsMatches , getLocationInGrammarFile } from './lint/utils' ;
50
51
import type { AugmentedGrammarEle } from './Grammar' ;
51
52
import { offsetToLineAndColumn } from './utils' ;
@@ -611,29 +612,27 @@ export default class Spec {
611
612
if ( node . hasAttribute ( 'example' ) || ! ( 'ecmarkdownTree' in node ) ) {
612
613
continue ;
613
614
}
614
- // @ts -ignore
615
- const tree = node . ecmarkdownTree as ReturnType < typeof parseAlgorithm > ;
615
+ const tree = ( node as AlgorithmElementWithTree ) . ecmarkdownTree ;
616
616
if ( tree == null ) {
617
617
continue ;
618
618
}
619
- // @ts -ignore
620
- const originalHtml : string = node . originalHtml ;
619
+ const originalHtml = ( node as AlgorithmElementWithTree ) . originalHtml ;
621
620
622
621
const expressionVisitor = ( expr : Expr , path : PathItem [ ] ) => {
623
622
if ( expr . type !== 'call' && expr . type !== 'sdo-call' ) {
624
623
return ;
625
624
}
626
625
627
626
const { callee, arguments : args } = expr ;
628
- if ( ! ( callee . parts . length === 1 && callee . parts [ 0 ] . name === 'text' ) ) {
627
+ if ( ! ( callee . length === 1 && callee [ 0 ] . name === 'text' ) ) {
629
628
return ;
630
629
}
631
- const calleeName = callee . parts [ 0 ] . contents ;
630
+ const calleeName = callee [ 0 ] . contents ;
632
631
633
632
const warn = ( message : string ) => {
634
633
const { line, column } = offsetToLineAndColumn (
635
634
originalHtml ,
636
- callee . parts [ 0 ] . location . start . offset
635
+ callee [ 0 ] . location . start . offset
637
636
) ;
638
637
this . warn ( {
639
638
type : 'contents' ,
@@ -2099,11 +2098,9 @@ function parentSkippingBlankSpace(expr: Expr, path: PathItem[]): PathItem | null
2099
2098
parent . type === 'seq' &&
2100
2099
parent . items . every (
2101
2100
i =>
2102
- ( i . type === 'prose' &&
2103
- i . parts . every (
2104
- p => p . name === 'tag' || ( p . name === 'text' && / ^ \s * $ / . test ( p . contents ) )
2105
- ) ) ||
2106
- i === pointer
2101
+ i === pointer ||
2102
+ ( i . type === 'fragment' &&
2103
+ ( i . frag . name === 'tag' || ( i . frag . name === 'text' && / ^ \s * $ / . test ( i . frag . contents ) ) ) )
2107
2104
)
2108
2105
) {
2109
2106
// if parent is just whitespace/tags around the call, walk up the tree further
@@ -2121,21 +2118,21 @@ function previousText(expr: Expr, path: PathItem[]): string | null {
2121
2118
}
2122
2119
const { parent, index } = part ;
2123
2120
if ( parent . type === 'seq' ) {
2124
- return textFromPreviousPart ( parent , index as number ) ;
2121
+ return textFromPreviousPart ( parent , index ) ;
2125
2122
}
2126
2123
return null ;
2127
2124
}
2128
2125
2129
2126
function textFromPreviousPart ( seq : Seq , index : number ) : string | null {
2130
- const prev = seq . items [ index - 1 ] ;
2131
- if ( prev ?. type === 'prose' && prev . parts . length > 0 ) {
2132
- let prevIndex = prev . parts . length - 1 ;
2133
- while ( prevIndex > 0 && prev . parts [ prevIndex ] . name === 'tag' ) {
2127
+ let prevIndex = index - 1 ;
2128
+ let prev ;
2129
+ while ( ( prev = seq . items [ prevIndex ] ) ?. type === 'fragment' ) {
2130
+ if ( prev . frag . name === 'text' ) {
2131
+ return prev . frag . contents ;
2132
+ } else if ( prev . frag . name === 'tag' ) {
2134
2133
-- prevIndex ;
2135
- }
2136
- const prevProse = prev . parts [ prevIndex ] ;
2137
- if ( prevProse . name === 'text' ) {
2138
- return prevProse . contents ;
2134
+ } else {
2135
+ break ;
2139
2136
}
2140
2137
}
2141
2138
return null ;
@@ -2159,13 +2156,13 @@ function isConsumedAsCompletion(expr: Expr, path: PathItem[]) {
2159
2156
const { parent, index } = part ;
2160
2157
if ( parent . type === 'seq' ) {
2161
2158
// if the previous text ends in `! ` or `? `, this is a completion
2162
- const text = textFromPreviousPart ( parent , index as number ) ;
2159
+ const text = textFromPreviousPart ( parent , index ) ;
2163
2160
if ( text != null && / [ ! ? ] \s $ / . test ( text ) ) {
2164
2161
return true ;
2165
2162
}
2166
2163
} else if ( parent . type === 'call' && index === 0 && parent . arguments . length === 1 ) {
2167
2164
// if this is `Completion(Expr())`, this is a completion
2168
- const { parts } = parent . callee ;
2165
+ const parts = parent . callee ;
2169
2166
if ( parts . length === 1 && parts [ 0 ] . name === 'text' && parts [ 0 ] . contents === 'Completion' ) {
2170
2167
return true ;
2171
2168
}
0 commit comments