This file contains hidden or 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
| class TextScanner < SimpleScanner | |
| def self.from_string(plain_markdown) | |
| text = plain_markdown | |
| .each_char | |
| .take_while { |char| SimpleScanner.from_string(char).null? } | |
| .join('') | |
| Token.new(type: 'TEXT', value: text) | |
| rescue InvalidTokenError | |
| Token.null | |
| end |
This file contains hidden or 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
| class SimpleScanner | |
| TOKEN_TYPES = { | |
| '_' => 'UNDERSCORE', | |
| '*' => 'STAR', | |
| "\n" => 'NEWLINE' | |
| }.freeze | |
| def self.from_string(plain_markdown) | |
| char = plain_markdown[0] | |
| Token.new(type: TOKEN_TYPES[char], value: char) |
This file contains hidden or 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
| A paragraph __with__ some *text* |
This file contains hidden or 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
| class Token | |
| attr_reader :type, :value | |
| def initialize(type:, value:) | |
| @type = type | |
| @value = value | |
| raise InvalidTokenError if value.nil? || type.nil? | |
| end | |
| def self.null | |
| NullToken.new |
This file contains hidden or 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
| foo = 1 |
This file contains hidden or 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
| foo = bar # expects a number on the right hand side of the equation | |
| foo # no equals, no number | |
| foo = # nothing here! | |
| = foo # nothing on the left hand side |
This file contains hidden or 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
| RuleName := SomeOtherRule A_TERMINAL |
This file contains hidden or 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
| Start := a | |
| | b | |
| | c |
This file contains hidden or 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
| A := a* |
This file contains hidden or 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
| B := b+ |