forked from ruby/lrama
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the
-W
and --warnings
options
- Loading branch information
Showing
16 changed files
with
425 additions
and
231 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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lrama | ||
class Diagnostics | ||
def initialize(states, logger) | ||
@states = states | ||
@logger = logger | ||
end | ||
|
||
def run(conflicts_sr: false, conflicts_rr: false) | ||
diagnose_conflict(conflicts_sr, conflicts_rr) | ||
end | ||
|
||
private | ||
|
||
def diagnose_conflict(conflicts_sr, conflicts_rr) | ||
if conflicts_sr && @states.sr_conflicts_count != 0 | ||
@logger.warn("shift/reduce conflicts: #{@states.sr_conflicts_count} found") | ||
end | ||
|
||
if conflicts_rr && @states.rr_conflicts_count != 0 | ||
@logger.warn("reduce/reduce conflicts: #{@states.rr_conflicts_count} found") | ||
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
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.