@@ -31,10 +31,11 @@ function getInputFile(oriLines: string[]): string {
31
31
"\n-----------------------------------\n\n" ;
32
32
}
33
33
34
- function getScopesAtMarkers ( text : string , grammar : vt . IGrammar ) : string {
34
+ function getScopesAtMarkers ( text : string , grammar : vt . IGrammar ) : { markerScopes : string , wholeBaseline : string } {
35
35
let oriLines = text . split ( '\n' ) ;
36
36
let ruleStack :vt . StackElement [ ] = undefined ;
37
37
let outputLines : string [ ] = [ ] ;
38
+ let baselineLines : string [ ] = [ ] ;
38
39
let markers = 0 ;
39
40
for ( let i in oriLines ) {
40
41
let oriLine = oriLines [ i ] ;
@@ -45,16 +46,23 @@ function getScopesAtMarkers(text: string, grammar: vt.IGrammar): string {
45
46
ruleStack = lineTokens . ruleStack ;
46
47
47
48
outputLines . push ( ">" + line ) ;
49
+ baselineLines . push ( ">" + line ) ;
48
50
for ( let token of lineTokens . tokens ) {
49
51
for ( let markerLocation of markerLocations ) {
50
52
if ( token . startIndex <= markerLocation && markerLocation < token . endIndex ) {
51
53
writeTokenLine ( token , '[' + ( parseInt ( i ) + 1 ) + ', ' + ( markerLocation + 1 ) + ']: ' , ' ' , outputLines ) ;
52
54
}
53
55
}
56
+
57
+ writeTokenLine ( token , "" , "" , baselineLines ) ;
54
58
}
55
59
}
56
60
57
- return markers ? ( getInputFile ( oriLines ) + outputLines . join ( '\n' ) ) : null ;
61
+ const oriLineText = getInputFile ( oriLines ) ;
62
+ return {
63
+ markerScopes : markers ? ( oriLineText + outputLines . join ( '\n' ) ) : null ,
64
+ wholeBaseline : oriLineText + baselineLines . join ( '\n' )
65
+ } ;
58
66
}
59
67
60
68
function writeTokenLine ( token : vt . IToken , preTextForToken : string , postTextForToken : string , outputLines : string [ ] ) {
@@ -71,26 +79,6 @@ function writeTokenLine(token: vt.IToken, preTextForToken: string, postTextForTo
71
79
outputLines . push ( startingSpaces + preTextForToken + token . scopes . join ( ' ' ) + postTextForToken ) ;
72
80
}
73
81
74
- function baselineWholeFile ( text : string , grammar : vt . IGrammar ) : string {
75
- let oriLines = text . split ( '\n' ) ;
76
- let ruleStack : vt . StackElement [ ] = undefined ;
77
- let outputLines : string [ ] = [ ] ;
78
- for ( let i in oriLines ) {
79
- let oriLine = oriLines [ i ] ;
80
- let markerLocations = getMarkerLocations ( oriLine ) ;
81
- let line = oriLine . split ( marker ) . join ( '' ) ;
82
- let lineTokens = grammar . tokenizeLine ( line , ruleStack ) ;
83
- ruleStack = lineTokens . ruleStack ;
84
-
85
- outputLines . push ( ">" + line ) ;
86
- for ( let token of lineTokens . tokens ) {
87
- writeTokenLine ( token , "" , "" , outputLines ) ;
88
- }
89
- }
90
-
91
- return getInputFile ( oriLines ) + outputLines . join ( '\n' ) ;
92
- }
93
-
94
82
for ( var fileName of fs . readdirSync ( 'cases' ) ) {
95
83
const text = fs . readFileSync ( path . join ( './cases' , fileName ) , 'utf8' ) ;
96
84
let parsedFileName = path . parse ( fileName ) ;
@@ -99,11 +87,11 @@ for (var fileName of fs.readdirSync('cases')) {
99
87
fs . mkdirSync ( 'generated' ) ;
100
88
}
101
89
let outputFileName = path . join ( './generated' , parsedFileName . name + '.txt' ) ;
102
- let scopesFileText = getScopesAtMarkers ( text , grammar ) ;
103
- if ( scopesFileText ) {
104
- fs . writeFile ( outputFileName , getScopesAtMarkers ( text , grammar ) , "utf8" ) ;
90
+ const { markerScopes , wholeBaseline } = getScopesAtMarkers ( text , grammar ) ;
91
+ if ( markerScopes ) {
92
+ fs . writeFile ( outputFileName , markerScopes , "utf8" ) ;
105
93
}
106
94
107
95
let outputBaselineName = path . join ( './generated' , parsedFileName . name + '.baseline.txt' ) ;
108
- fs . writeFile ( outputBaselineName , baselineWholeFile ( text , grammar ) , "utf8" ) ;
96
+ fs . writeFile ( outputBaselineName , wholeBaseline , "utf8" ) ;
109
97
}
0 commit comments