@@ -44,20 +44,21 @@ let ruleOverrides = {};
4444function mkRuleOverrides ( substitutions ) {
4545 const overrides = { } ;
4646 for ( const substitution of substitutions ) {
47- const keys = Object . keys ( substitution )
47+ const keys = Object . keys ( substitution ) ;
4848 if ( keys . includes ( 'override' ) ) {
4949 overrides [ substitution . name ] = substitution . override ;
5050 continue ;
5151 }
5252 if ( keys . includes ( 'pattern' ) && keys . includes ( 'replacement' ) ) {
5353 let postlude = '' ;
5454 if ( keys . includes ( 'postlude' ) ) {
55- postlude = substitution . postlude
55+ postlude = substitution . postlude ;
5656 }
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 ;
5859 }
5960 }
60- return overrides
61+ return overrides ;
6162}
6263
6364let reservedWordProductions = [ ] ;
@@ -72,7 +73,6 @@ function mkReservedWordProductions(productions) {
7273// E.g., `"blah" | "blarg"` => `blah | blarg`.
7374const terminalsToRules = ohmString => ohmString . replace ( / " / g, '' ) ;
7475
75-
7676const PRELUDE = raw `
7777 Start = Script
7878
@@ -115,10 +115,15 @@ let grammarName; // Initialized in main(), below.
115115semantics . addOperation (
116116 'toOhm()' ,
117117 ( ( ) => {
118- function handleProduction ( nonterminal , rhs , parameterListOpt = undefined , kind = 'LEXICAL' ) {
118+ function handleProduction (
119+ nonterminal ,
120+ rhs ,
121+ parameterListOpt = undefined ,
122+ kind = 'LEXICAL'
123+ ) {
119124 // 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 ( '|' , '' ) ;
122127 const ruleName = isLexical
123128 ? lexicalRuleName ( strippedNonTerminal )
124129 : syntacticRuleName ( strippedNonTerminal ) ;
@@ -132,28 +137,30 @@ semantics.addOperation(
132137 const handlePositiveLookahead = ( _ , _op , exprList ) => {
133138 const parsedExprList = exprList . isIteration ( )
134139 ? exprList . children . map ( c => c . toOhm ( ) )
135- : [ exprList . toOhm ( ) ]
140+ : [ exprList . toOhm ( ) ] ;
136141
137142 if ( parsedExprList . length > 1 ) {
138143 return `&(${ parsedExprList . join ( '|' ) } )` ;
139144 }
140145 return `&${ parsedExprList } ` ;
141- }
146+ } ;
142147 const handleNegativeLookahead = ( _ , _op , exprList ) => {
143148 const parsedExprList = exprList . isIteration ( )
144149 ? exprList . children . map ( c => c . toOhm ( ) )
145- : [ exprList . toOhm ( ) ]
150+ : [ exprList . toOhm ( ) ] ;
146151 if ( parsedExprList . length > 1 ) {
147152 return `~(${ parsedExprList . join ( '|' ) } )` ;
148153 }
149154 return `~${ parsedExprList } ` ;
150- }
155+ } ;
151156
152157 return {
153158 Productions ( productionIter ) {
154159 const rules = productionIter . children . map ( c => c . toOhm ( ) ) ;
155160 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+ ) ;
157164 }
158165 const prettyRules = [ ...rules ] . join ( '\n\n ' ) ;
159166 const indentedAdditionalRules = this . getAdditionalRules ( ) . map ( str => ` ${ str } ` ) ;
@@ -228,7 +235,7 @@ semantics.addOperation(
228235 : ohmTerminal ;
229236 } ,
230237 term_link ( _ ) {
231- return ''
238+ return '' ;
232239 } ,
233240 assertion ( _open , assertionContents , _close ) {
234241 return assertionContents . toOhm ( ) ;
@@ -305,7 +312,7 @@ semantics.addOperation(
305312 } ,
306313 nonterminal ( _optPipe , _ , _2 , _optPipe2 ) {
307314 const { sourceString} = this ;
308- const trimmedSourceString = sourceString . replaceAll ( '|' , '' )
315+ const trimmedSourceString = sourceString . replaceAll ( '|' , '' ) ;
309316 const root = this . context . productions ;
310317 if ( root . productionsByName . has ( trimmedSourceString ) ) {
311318 return trimmedSourceString ;
@@ -327,7 +334,7 @@ semantics.addOperation(
327334 case ';' :
328335 return '#sc' ;
329336 }
330- return `"${ sourceString . replace ( '\\' , '\\\\' ) } "` ;
337+ return `"${ sourceString . replace ( '\\' , '\\\\' ) } "` ;
331338 } ,
332339 literal ( _open , charIter , _close ) {
333340 const name = charIter . sourceString ;
@@ -595,15 +602,16 @@ function addContext(semantics, getActions) {
595602 grammarName = process . argv [ 2 ] ;
596603 const inputFilename = process . argv [ 3 ] ;
597604 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' } ) ) ;
599606 if ( overrideConfig . substitutions ) {
600607 ruleOverrides = mkRuleOverrides ( overrideConfig . substitutions ) ;
601608 }
602609 if ( overrideConfig . reservedWords ) {
603- reservedWordProductions = mkReservedWordProductions ( overrideConfig . reservedWords )
610+ reservedWordProductions = mkReservedWordProductions ( overrideConfig . reservedWords ) ;
604611 // Add a rule override for each of the reserved word productions.
605612 for ( const prod of reservedWordProductions ) {
606- ruleOverrides [ lexicalRuleName ( prod ) ] = ( rhs , defaultBody ) => terminalsToRules ( defaultBody ) ;
613+ ruleOverrides [ lexicalRuleName ( prod ) ] = ( rhs , defaultBody ) =>
614+ terminalsToRules ( defaultBody ) ;
607615 }
608616 }
609617 }
0 commit comments