forked from crystal-lang/crystal
-
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.
Merge pull request crystal-lang#2 from icyleaf/refactor-lexer-middlewave
Refactor lexer middlewave
- Loading branch information
Showing
24 changed files
with
991 additions
and
583 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Markd::Lexer do | ||
assert_common_lexer_render "> # Foo\n> bar\n> baz", [{ | ||
"type" => "blockquote_start" | ||
}, | ||
{ | ||
"type" => "heading", | ||
"level" => 1, | ||
"text" => "Foo" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "bar\nbaz" | ||
}, | ||
{ | ||
"type" => "blockquote_end" | ||
}] | ||
|
||
assert_common_lexer_render "> # Foo\n>bar\n> baz", [{ | ||
"type" => "blockquote_start" | ||
}, | ||
{ | ||
"type" => "heading", | ||
"level" => 1, | ||
"text" => "Foo" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "bar\nbaz" | ||
}, | ||
{ | ||
"type" => "blockquote_end" | ||
}] | ||
|
||
assert_common_lexer_render "> # Foo\n> bar\n > baz", [{ | ||
"type" => "blockquote_start" | ||
}, | ||
{ | ||
"type" => "heading", | ||
"level" => 1, | ||
"text" => "Foo" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "bar\nbaz" | ||
}, | ||
{ | ||
"type" => "blockquote_end" | ||
}] | ||
|
||
assert_common_lexer_render " > # Foo\n > bar\n > baz", [{ | ||
"type" => "code", | ||
"text" => "> # Foo\n> bar\n> baz" | ||
}] | ||
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,42 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Markd::Lexer do | ||
assert_common_lexer_render " echo hello world", [{ | ||
"type" => "code", | ||
"text" => "echo hello world" | ||
}] | ||
|
||
assert_common_lexer_render " echo hello world\n pwd", [{ | ||
"type" => "code", | ||
"text" => "echo hello world\npwd" | ||
}] | ||
|
||
assert_common_lexer_render "Hello World\n\n echo hello world", [{ | ||
"type" => "paragraph", | ||
"text" => "Hello World" | ||
}, | ||
{ | ||
"type" => "code", | ||
"text" => "echo hello world" | ||
}] | ||
|
||
assert_common_lexer_render " echo hello world", [ | ||
{ | ||
"type" => "code", | ||
"text" => "echo hello world" | ||
}] | ||
|
||
assert_common_lexer_render " echo hello world\n\nHello Earch\n\n echo hello crystal", [ | ||
{ | ||
"type" => "code", | ||
"text" => "echo hello world" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "Hello Earch" | ||
}, | ||
{ | ||
"type" => "code", | ||
"text" => "echo hello crystal" | ||
}] | ||
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,50 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Markd::Lexer do | ||
assert_common_lexer_render "```\necho hello world\n```", [{ | ||
"type" => "code", | ||
"text" => "echo hello world" | ||
}] | ||
|
||
assert_common_lexer_render "```bash\necho hello world\npwd```", [{ | ||
"type" => "code", | ||
"lang" => "bash", | ||
"text" => "echo hello world\npwd", | ||
}] | ||
|
||
assert_common_lexer_render "`````\nhi ther `` ok ```\n`````", [{ | ||
"type" => "code", | ||
"text" => "hi ther `` ok ```" | ||
}] | ||
|
||
assert_common_lexer_render "```\n<\n >\n```", [{ | ||
"type" => "code", | ||
"text" => "<\n >" | ||
}] | ||
|
||
assert_common_lexer_render "~~~\n<\n >\n~~~", [{ | ||
"type" => "code", | ||
"text" => "<\n >" | ||
}] | ||
|
||
assert_common_lexer_render "```\naaa\n~~~\n```", [{ | ||
"type" => "code", | ||
"text" => "aaa\n~~~" | ||
}] | ||
|
||
assert_common_lexer_render "~~~\naaa\n```\n~~~", [{ | ||
"type" => "code", | ||
"text" => "aaa\n```" | ||
}] | ||
|
||
# TODO: fix it | ||
# assert_common_lexer_render "````\naaa\n```\n``````", [{ | ||
# "type" => "code", | ||
# "text" => "aaa\n```" | ||
# }] | ||
|
||
# assert_common_lexer_render "~~~~\naaa\n~~~\n~~~~~", [{ | ||
# "type" => "code", | ||
# "text" => "aaa\n~~~" | ||
# }] | ||
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,57 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Markd::Lexer do | ||
assert_common_lexer_render "# Heading 1", [{ | ||
"type" => "heading", | ||
"level" => 1, | ||
"text" => "Heading 1", | ||
}] | ||
|
||
assert_common_lexer_render "## Heading 2", [{ | ||
"type" => "heading", | ||
"level" => 2, | ||
"text" => "Heading 2", | ||
}] | ||
|
||
assert_common_lexer_render "###### Heading 6", [{ | ||
"type" => "heading", | ||
"level" => 6, | ||
"text" => "Heading 6", | ||
}] | ||
|
||
assert_common_lexer_render "## Heading 2\n### Heading 3", [{ | ||
"type" => "heading", | ||
"level" => 2, | ||
"text" => "Heading 2", | ||
}, | ||
{ | ||
"type" => "heading", | ||
"level" => 3, | ||
"text" => "Heading 3", | ||
}] | ||
|
||
assert_common_lexer_render "####### Heading 7", [{ | ||
"type" => "paragraph", | ||
"text" => "####### Heading 7", | ||
}] | ||
|
||
assert_common_lexer_render "#Heading 1", [{ | ||
"type" => "paragraph", | ||
"text" => "#Heading 1", | ||
}] | ||
|
||
assert_common_lexer_render "#Heading 1", [{ | ||
"type" => "paragraph", | ||
"text" => "#Heading 1", | ||
}] | ||
|
||
assert_common_lexer_render "#Heading 1", [{ | ||
"type" => "paragraph", | ||
"text" => "#Heading 1", | ||
}] | ||
|
||
assert_common_lexer_render "#Heading 1\n#Heading 2", [{ | ||
"type" => "paragraph", | ||
"text" => "#Heading 1\n#Heading 2", | ||
}] | ||
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,75 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Markd::Lexer do | ||
assert_common_lexer_render "---\n___", [{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}] | ||
|
||
assert_common_lexer_render "+++", [{ | ||
"type" => "paragraph", | ||
"text" => "+++" | ||
}] | ||
|
||
assert_common_lexer_render "===", [{ | ||
"type" => "paragraph", | ||
"text" => "===" | ||
}] | ||
|
||
assert_common_lexer_render "--\n**\n__", [{ | ||
"type" => "paragraph", | ||
"text" => "--\n**\n__" | ||
}] | ||
|
||
assert_common_lexer_render " ***\n ***\n ***", [{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}] | ||
|
||
assert_common_lexer_render " ***", [{ | ||
"type" => "code", | ||
"text" => "***" | ||
}] | ||
|
||
assert_common_lexer_render "Foo\n ***", [{ | ||
"type" => "paragraph", | ||
"text" => "Foo\n ***" | ||
}] | ||
|
||
assert_common_lexer_render "_____________________________________\n - - -\n ** * ** * ** * **\n- - - -\n- - - - ", [{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}, | ||
{ | ||
"type" => "hr" | ||
}] | ||
|
||
assert_common_lexer_render "_ _ _ _ a\n\na------\n\n---a---", [{ | ||
"type" => "paragraph", | ||
"text" => "_ _ _ _ a" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "a------" | ||
}, | ||
{ | ||
"type" => "paragraph", | ||
"text" => "---a---" | ||
}] | ||
|
||
end |
Oops, something went wrong.