@@ -44,20 +44,21 @@ let ruleOverrides = {};
44
44
function mkRuleOverrides ( substitutions ) {
45
45
const overrides = { } ;
46
46
for ( const substitution of substitutions ) {
47
- const keys = Object . keys ( substitution )
47
+ const keys = Object . keys ( substitution ) ;
48
48
if ( keys . includes ( 'override' ) ) {
49
49
overrides [ substitution . name ] = substitution . override ;
50
50
continue ;
51
51
}
52
52
if ( keys . includes ( 'pattern' ) && keys . includes ( 'replacement' ) ) {
53
53
let postlude = '' ;
54
54
if ( keys . includes ( 'postlude' ) ) {
55
- postlude = substitution . postlude
55
+ postlude = substitution . postlude ;
56
56
}
57
- overrides [ substitution . name ] = ( rhs , defaultBody ) => ( safelyReplace ( defaultBody , substitution . pattern , substitution . replacement ) + postlude )
57
+ overrides [ substitution . name ] = ( rhs , defaultBody ) =>
58
+ safelyReplace ( defaultBody , substitution . pattern , substitution . replacement ) + postlude ;
58
59
}
59
60
}
60
- return overrides
61
+ return overrides ;
61
62
}
62
63
63
64
let reservedWordProductions = [ ] ;
@@ -72,7 +73,6 @@ function mkReservedWordProductions(productions) {
72
73
// E.g., `"blah" | "blarg"` => `blah | blarg`.
73
74
const terminalsToRules = ohmString => ohmString . replace ( / " / g, '' ) ;
74
75
75
-
76
76
const PRELUDE = raw `
77
77
Start = Script
78
78
@@ -115,10 +115,15 @@ let grammarName; // Initialized in main(), below.
115
115
semantics . addOperation (
116
116
'toOhm()' ,
117
117
( ( ) => {
118
- function handleProduction ( nonterminal , rhs , parameterListOpt = undefined , kind = 'LEXICAL' ) {
118
+ function handleProduction (
119
+ nonterminal ,
120
+ rhs ,
121
+ parameterListOpt = undefined ,
122
+ kind = 'LEXICAL'
123
+ ) {
119
124
// const isLexical = parameterListOpt === undefined;
120
- const isLexical = kind === 'LEXICAL'
121
- const strippedNonTerminal = nonterminal . sourceString . replaceAll ( '|' , '' )
125
+ const isLexical = kind === 'LEXICAL' ;
126
+ const strippedNonTerminal = nonterminal . sourceString . replaceAll ( '|' , '' ) ;
122
127
const ruleName = isLexical
123
128
? lexicalRuleName ( strippedNonTerminal )
124
129
: syntacticRuleName ( strippedNonTerminal ) ;
@@ -132,28 +137,30 @@ semantics.addOperation(
132
137
const handlePositiveLookahead = ( _ , _op , exprList ) => {
133
138
const parsedExprList = exprList . isIteration ( )
134
139
? exprList . children . map ( c => c . toOhm ( ) )
135
- : [ exprList . toOhm ( ) ]
140
+ : [ exprList . toOhm ( ) ] ;
136
141
137
142
if ( parsedExprList . length > 1 ) {
138
143
return `&(${ parsedExprList . join ( '|' ) } )` ;
139
144
}
140
145
return `&${ parsedExprList } ` ;
141
- }
146
+ } ;
142
147
const handleNegativeLookahead = ( _ , _op , exprList ) => {
143
148
const parsedExprList = exprList . isIteration ( )
144
149
? exprList . children . map ( c => c . toOhm ( ) )
145
- : [ exprList . toOhm ( ) ]
150
+ : [ exprList . toOhm ( ) ] ;
146
151
if ( parsedExprList . length > 1 ) {
147
152
return `~(${ parsedExprList . join ( '|' ) } )` ;
148
153
}
149
154
return `~${ parsedExprList } ` ;
150
- }
155
+ } ;
151
156
152
157
return {
153
158
Productions ( productionIter ) {
154
159
const rules = productionIter . children . map ( c => c . toOhm ( ) ) ;
155
160
for ( const param of new Set ( this . allParameters ) ) {
156
- rules . push ( ...[ `with${ param } = /* fixme */` , `no${ param } = ~any /* is this right? */` ] ) ;
161
+ rules . push (
162
+ ...[ `with${ param } = /* fixme */` , `no${ param } = ~any /* is this right? */` ]
163
+ ) ;
157
164
}
158
165
const prettyRules = [ ...rules ] . join ( '\n\n ' ) ;
159
166
const indentedAdditionalRules = this . getAdditionalRules ( ) . map ( str => ` ${ str } ` ) ;
@@ -228,7 +235,7 @@ semantics.addOperation(
228
235
: ohmTerminal ;
229
236
} ,
230
237
term_link ( _ ) {
231
- return ''
238
+ return '' ;
232
239
} ,
233
240
assertion ( _open , assertionContents , _close ) {
234
241
return assertionContents . toOhm ( ) ;
@@ -305,7 +312,7 @@ semantics.addOperation(
305
312
} ,
306
313
nonterminal ( _optPipe , _ , _2 , _optPipe2 ) {
307
314
const { sourceString} = this ;
308
- const trimmedSourceString = sourceString . replaceAll ( '|' , '' )
315
+ const trimmedSourceString = sourceString . replaceAll ( '|' , '' ) ;
309
316
const root = this . context . productions ;
310
317
if ( root . productionsByName . has ( trimmedSourceString ) ) {
311
318
return trimmedSourceString ;
@@ -327,7 +334,7 @@ semantics.addOperation(
327
334
case ';' :
328
335
return '#sc' ;
329
336
}
330
- return `"${ sourceString . replace ( '\\' , '\\\\' ) } "` ;
337
+ return `"${ sourceString . replace ( '\\' , '\\\\' ) } "` ;
331
338
} ,
332
339
literal ( _open , charIter , _close ) {
333
340
const name = charIter . sourceString ;
@@ -595,15 +602,16 @@ function addContext(semantics, getActions) {
595
602
grammarName = process . argv [ 2 ] ;
596
603
const inputFilename = process . argv [ 3 ] ;
597
604
if ( process . argv . length > 4 ) {
598
- const overrideConfig = JSON . parse ( readFileSync ( process . argv [ 4 ] , { encoding : 'utf-8' } ) ) ;
605
+ const overrideConfig = JSON . parse ( readFileSync ( process . argv [ 4 ] , { encoding : 'utf-8' } ) ) ;
599
606
if ( overrideConfig . substitutions ) {
600
607
ruleOverrides = mkRuleOverrides ( overrideConfig . substitutions ) ;
601
608
}
602
609
if ( overrideConfig . reservedWords ) {
603
- reservedWordProductions = mkReservedWordProductions ( overrideConfig . reservedWords )
610
+ reservedWordProductions = mkReservedWordProductions ( overrideConfig . reservedWords ) ;
604
611
// Add a rule override for each of the reserved word productions.
605
612
for ( const prod of reservedWordProductions ) {
606
- ruleOverrides [ lexicalRuleName ( prod ) ] = ( rhs , defaultBody ) => terminalsToRules ( defaultBody ) ;
613
+ ruleOverrides [ lexicalRuleName ( prod ) ] = ( rhs , defaultBody ) =>
614
+ terminalsToRules ( defaultBody ) ;
607
615
}
608
616
}
609
617
}
0 commit comments