-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from ydah/warn-option
Introduce the `-W` and `--warnings` options and support redefined parameterizing rules
- Loading branch information
Showing
19 changed files
with
418 additions
and
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lrama | ||
class Diagnostics | ||
def initialize(grammar, states, logger) | ||
@grammar = grammar | ||
@states = states | ||
@logger = logger | ||
end | ||
|
||
def run(diagnostic) | ||
if diagnostic | ||
diagnose_conflict | ||
diagnose_parameterizing_redefined | ||
end | ||
end | ||
|
||
private | ||
|
||
def diagnose_conflict | ||
if @states.sr_conflicts_count != 0 | ||
@logger.warn("shift/reduce conflicts: #{@states.sr_conflicts_count} found") | ||
end | ||
|
||
if @states.rr_conflicts_count != 0 | ||
@logger.warn("reduce/reduce conflicts: #{@states.rr_conflicts_count} found") | ||
end | ||
end | ||
|
||
def diagnose_parameterizing_redefined | ||
@grammar.parameterizing_rule_resolver.redefined_rules.each do |rule| | ||
@logger.warn("parameterizing rule redefined: #{rule}") | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lrama | ||
class GrammarValidator | ||
def initialize(grammar, states, logger) | ||
@grammar = grammar | ||
@states = states | ||
@logger = logger | ||
end | ||
|
||
def valid? | ||
conflicts_within_threshold? | ||
end | ||
|
||
private | ||
|
||
def conflicts_within_threshold? | ||
return true unless @grammar.expect | ||
|
||
[sr_conflicts_within_threshold(@grammar.expect), rr_conflicts_within_threshold(0)].all? | ||
end | ||
|
||
def sr_conflicts_within_threshold(expected) | ||
return true if expected == @states.sr_conflicts_count | ||
|
||
@logger.error("shift/reduce conflicts: #{@states.sr_conflicts_count} found, #{expected} expected") | ||
false | ||
end | ||
|
||
def rr_conflicts_within_threshold(expected) | ||
return true if expected == @states.rr_conflicts_count | ||
|
||
@logger.error("reduce/reduce conflicts: #{@states.rr_conflicts_count} found, #{expected} expected") | ||
false | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,27 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lrama | ||
class Warning | ||
attr_reader :errors, :warns | ||
|
||
class Logger | ||
def initialize(out = STDERR) | ||
@out = out | ||
@errors = [] | ||
@warns = [] | ||
end | ||
|
||
def error(message) | ||
@out << message << "\n" | ||
@errors << message | ||
end | ||
|
||
def warn(message) | ||
@out << message << "\n" | ||
@warns << message | ||
end | ||
|
||
def has_error? | ||
!@errors.empty? | ||
def error(message) | ||
@out << message << "\n" | ||
end | ||
end | ||
end |
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
Oops, something went wrong.