diff --git a/parser/code.go b/parser/code.go index 535ba8b..e4a0743 100644 --- a/parser/code.go +++ b/parser/code.go @@ -7,10 +7,12 @@ import ( "go.arsenm.dev/amu/scanner" ) -func (p *Parser) parseCode(tok scanner.Token, lit string) *ast.Code { +func (p *Parser) parseCode() *ast.Code { // Create new code code := &ast.Code{} + tok, lit := p.scan() + // If token is not WORD or literal is not "=list" if tok != scanner.WORD || lit != "=code" { // Return nil as this code is invalid diff --git a/parser/list.go b/parser/list.go index 783852e..cc19e33 100644 --- a/parser/list.go +++ b/parser/list.go @@ -6,10 +6,12 @@ import ( ) // parseList attempts to parse a list -func (p *Parser) parseList(tok scanner.Token, lit string) *ast.List { +func (p *Parser) parseList() *ast.List { // Create new list list := &ast.List{} + tok, lit := p.scan() + // If token is not WORD or literal is not "=list" if tok != scanner.WORD || lit != "=list" { // Return nil as this list is invalid diff --git a/parser/para.go b/parser/para.go index 14e6042..69f0385 100644 --- a/parser/para.go +++ b/parser/para.go @@ -39,8 +39,9 @@ parseLoop: para.Fragments = append(para.Fragments, ast.ParaFragment{Punct: &lit}) case scanner.WORD: if strings.HasPrefix(lit, "+") { + p.unscan() // Attempt to parse function - function := p.parseFunc(tok, lit) + function := p.parseFunc() // If successful if function != nil { // Add function to para @@ -55,7 +56,7 @@ parseLoop: // Create new nil slice of ast.FormatType var types []ast.FormatType if strings.HasPrefix(lit, "_") { - // Remove leading and trailing "_" + // Remove leading and trailing "_" lit = strings.Trim(lit, "_") // Add italic format to slice types = append(types, ast.FormatTypeItalic) @@ -113,10 +114,12 @@ parseLoop: } // parseFunc appempts to parse a function call -func (p *Parser) parseFunc(tok scanner.Token, lit string) *ast.Func { +func (p *Parser) parseFunc() *ast.Func { // Create new function function := &ast.Func{} + tok, lit := p.scan() + // If the token is not a word or does not have a prefix of "+" if tok != scanner.WORD || !strings.HasPrefix(lit, "+") { // Return nil as this is an invalid function call @@ -174,7 +177,7 @@ parseLoop: // Write word to current buffer currentBuf.WriteString(lit) case scanner.PUNCT: - // If closing bracket found but no text stored + // If closing bracket found but no text stored if lit == "]" && currentBuf.Len() == 0 { // Unscan token p.unscan() diff --git a/parser/parser.go b/parser/parser.go index 18b0a6e..bb0c73c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -144,8 +144,9 @@ parseLoop: continue } } else if tok == scanner.WORD && lit == "=list" { + p.unscan() // Attempt to parse list - list := p.parseList(tok, lit) + list := p.parseList() // If successful if list != nil { // Add list to AST @@ -154,8 +155,9 @@ parseLoop: continue } } else if tok == scanner.WORD && lit == "=code" { + p.unscan() // Attempt to parse code - code := p.parseCode(tok, lit) + code := p.parseCode() // If successful if code != nil { // Add code to AST