-
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.
- Loading branch information
1 parent
0b39b91
commit 6eb352b
Showing
8 changed files
with
142 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require: rubocop-rspec | ||
AllCops: | ||
NewCops: enable |
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Zodiac | ||
# Encapsulates lexer evaluation logic for a specific token kind. | ||
class LexerEvaluator | ||
def initialize(token_kind, condition, evaluator) | ||
@token_kind = token_kind | ||
@condition = condition | ||
@evaluator = evaluator | ||
end | ||
|
||
def evaluate(input) | ||
return nil unless @condition.call(input) | ||
|
||
{ kind: @token_kind, value: @evaluator.call } | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Zodiac | ||
# Evaluates a list of lexers and returns the first token that matches. | ||
class LexerEvaluatorEngine | ||
def initialize(lexers, default_evaluator) | ||
@lexers = lexers | ||
@default_evaluator = default_evaluator | ||
end | ||
|
||
def execute(input) | ||
@lexers.each do |lexer| | ||
token = lexer.evaluate(input) | ||
|
||
return token if token | ||
end | ||
|
||
@default_evaluator.call | ||
|
||
nil | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.