Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/crystal-dfa/nfa_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe DFA::NFA do
DFA::NFA.create_nfa(ast).should eq expected
end

it "creates a state for a ConcateNode" do
context "creates a state for a ConcateNode" do
it "works for the binary case" do
ast = DFA::AST::ConcatNode.new [
DFA::AST::LiteralNode.new('a').as(DFA::AST::ASTNode),
Expand All @@ -31,7 +31,7 @@ describe DFA::NFA do
end
end

it "creates a state for an AlternationNode" do
context "creates a state for an AlternationNode" do
it "works for the binary case" do
ast = DFA::AST::AlternationNode.new [
DFA::AST::LiteralNode.new('a').as(DFA::AST::ASTNode),
Expand Down Expand Up @@ -99,7 +99,7 @@ describe DFA::NFA do
DFA::NFA.create_nfa(ast).should eq expected
end

it "creates a state for a CharacterClassNode([a-z]) One-or-More" do
context "creates a state for a CharacterClassNode([a-z]) One-or-More" do
it "creates a state for the simple range case [a-z]" do
ast = DFA::AST::CharacterClassNode.new(false, Array(String).new, [('a'..'z')])
expected = r_state('a', 'z')
Expand Down
2 changes: 1 addition & 1 deletion src/core_ext/range.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module IntersectionMethods(T)
end
end

struct Tuple(T)
struct Tuple(*T)
include IntersectionMethods(T)

def -(other : self)
Expand Down
20 changes: 10 additions & 10 deletions src/crystal-dfa/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ module DFA
end

class NameParslet < PrefixParslet
def parse(parser, token)
def parse(parser, token) : AST::LiteralNode
AST::LiteralNode.new(token[:value].not_nil!)
end
end

class AnyCharacterParslet < PrefixParslet
def parse(parser, token)
def parse(parser, token) : AST::CharacterClassNode
AST::CharacterClassNode.new(false, Array(String).new, ANY_CHAR_RANGES)
end
end

class SpecialCharacterClassParslet < PrefixParslet
def parse(parser, token)
def parse(parser, token) : AST::ASTNode
_next = parser.consume
raise "unexpected end of input" unless _next

Expand All @@ -180,7 +180,7 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class GroupParslet < PrefixParslet
def parse(parser, token)
def parse(parser, token) : AST::GroupNode
# ignore non capturing group designators
if (_peek = parser.peek) &&
_peek[:type] == :QSTM
Expand All @@ -199,7 +199,7 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class CharacterRangeParslet < InfixParslet
def parse(parser, left, token)
def parse(parser, left, token) : AST::CharacterRangeNode
parser.consume(:MINUS)
right = parser.parseExpression(precedence)

Expand All @@ -218,7 +218,7 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class CharacterClassParslet < PrefixParslet
def parse(parser, token)
def parse(parser, token) : AST::CharacterClassNode | AST::AlternationNode
negate = (peek = parser.peek) &&
(peek[:type] == :NEGATE) &&
parser.consume ? true : false
Expand Down Expand Up @@ -266,7 +266,7 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class ConcatParslet < InfixParslet
def parse(parser, left : AST::ASTNode, token)
def parse(parser, left : AST::ASTNode, token) : AST::ConcatNode
exp = AST::ConcatNode.new([left.as(AST::ASTNode)])

_next = parser.parseExpression(Precedence[:LITERAL] - 1).as(AST::ASTNode?)
Expand All @@ -282,7 +282,7 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class CurlyQuantifierParslet < InfixParslet
def parse(parser, left : AST::ASTNode, token)
def parse(parser, left : AST::ASTNode, token) : AST::QuantifierNode
parser.consume(:LCURLY)

values = parse_quantifications(
Expand Down Expand Up @@ -318,14 +318,14 @@ Lexer::IDENTIFIERS.key_for(_next[:type])
end

class QuantifierParslet(T) < InfixParslet
def parse(parser, left : AST::ASTNode, token)
def parse(parser, left : AST::ASTNode, token) : AST::ASTNode
parser.consume
T.new(left)
end
end

class AlternationParslet < InfixParslet
def parse(parser, left : AST::ASTNode, token)
def parse(parser, left : AST::ASTNode, token) : AST::AlternationNode
exp = AST::AlternationNode.new([left.as(AST::ASTNode)])
while (peek = parser.peek) && (peek[:type] == :PIPE)
parser.consume
Expand Down