-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
770 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/pegjs/lib/compiler/passes/report-incorrect-plucking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
// | ||
// Check if the given element's expression is of type `semantic_*` | ||
// | ||
function isSemanticPredicate( element ) { | ||
|
||
const type = element.expression.type; | ||
|
||
if ( type === "semantic_and" ) return true; | ||
if ( type === "semantic_not" ) return true; | ||
|
||
return false; | ||
|
||
} | ||
|
||
// | ||
// Compiler pass to ensure the following are enforced: | ||
// | ||
// - plucking can not be done with an action block | ||
// - cannot pluck a semantic predicate | ||
// | ||
function reportIncorrectPlucking( ast, session ) { | ||
|
||
session.buildVisitor( { | ||
|
||
action( node ) { | ||
|
||
this.visit( node.expression, true ); | ||
|
||
}, | ||
|
||
labeled( node, action ) { | ||
|
||
if ( node.pick !== true ) return void 0; | ||
|
||
if ( action === true ) | ||
|
||
session.error( `"@" cannot be used with an action block.`, node.location ); | ||
|
||
if ( isSemanticPredicate( node ) ) | ||
|
||
session.error( `"@" cannot be used on a semantic predicate.`, node.location ); | ||
|
||
this.visit( node.expression ); | ||
|
||
}, | ||
|
||
} )( ast ); | ||
|
||
} | ||
|
||
module.exports = reportIncorrectPlucking; |
Oops, something went wrong.