Documentation ¶
Overview ¶
The goal for our lexer is not to create a compiler or intrepreter. It's primary purpose is to scan the raw source code as a series of characters and group them into tokens. The implementation will ignore many tokens that other scanner/lexers would not.
The types of tokens that we are concered about: Single line comment tokens (such as // for languages that have adopted c like comment syntax or # for python) Multi line comment tokens (such as /* for c adopted languages and ”' & """ for python) End of file tokens
We should check for string tokens, but we do not need to create the token or store the lexeme. The reason for checking strings is so we can prevent certain edge cases from happening. One example could be where a string contains characters that could be denoted as a comment. For C like languages that could be a string such as "/*" or "//". We don't want the lexer to create tokens for strings that may contain comment syntax.
Each language that is supported will need to satisfy the LexingManager interface and support tokenizing methods for Comments and Strings. This will allow each implementation to utilize the comment notation that is specific to a language.
Index ¶
- Constants
- Variables
- func IsAdoptedFromC(ext string) bool
- type CLexer
- func (cl *CLexer) AnalyzeToken(lex *Lexer) error
- func (cl *CLexer) Comment(lex *Lexer) error
- func (cl *CLexer) MultiLineComment(lex *Lexer) error
- func (cl *CLexer) ParseCommentTokens(lex *Lexer, annotation []byte) ([]Comment, error)
- func (cl *CLexer) SingleLineComment(lex *Lexer) error
- func (cl *CLexer) String(lex *Lexer, delim byte) error
- type Comment
- type Lexer
- type LexingManager
- type Token
- type TokenType
Constants ¶
const ( SINGLE_LINE_COMMENT = iota MULTI_LINE_COMMENT STRING EOF )
Variables ¶
Functions ¶
func IsAdoptedFromC ¶
Types ¶
type CLexer ¶
type CLexer struct{}
func (*CLexer) AnalyzeToken ¶
func (*CLexer) MultiLineComment ¶
func (*CLexer) ParseCommentTokens ¶
func (*CLexer) SingleLineComment ¶
type Comment ¶
type Comment struct { Title []byte Description []byte TokenIndex int Source []byte SourceFileName string }
type Lexer ¶
type Lexer struct { Source []byte FileName string Tokens []Token Start int Current int Line int Manager LexingManager }
func (*Lexer) AnalyzeTokens ¶
type LexingManager ¶
type LexingManager interface { AnalyzeToken(lexer *Lexer) error String(lexer *Lexer, delim byte) error Comment(lexer *Lexer) error ParseCommentTokens(lexer *Lexer, annotation []byte) ([]Comment, error) }
func NewLexingManager ¶
func NewLexingManager(ext string) (LexingManager, error)