From 13fac099705259793bfe97bddf912d3951049012 Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 00:35:33 +1200 Subject: [PATCH 1/6] Parser permit inline comments (untested) --- pkg/parser/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 64f1700..f956139 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -172,7 +172,7 @@ func (p *Parser) ErrorString(message string, code string) { func (p *Parser) Expect(tokenType string, tokenValue string) ast.Position { if !p.IsCurrent(tokenType, tokenValue) { var msg string - if tokenType == ast.TypeNewline { + if tokenType == ast.TypeNewline || tokenType == ast.TypeComment { msg = "Expected newline" } else { msg = fmt.Sprintf("Expected token '%s'(%s)", tokenValue, tokenType) From 7ea938afa7ae777ffc6179ea9da45acff7a1a2a2 Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 01:07:17 +1200 Subject: [PATCH 2/6] Parser permit nolol inline comments (untested) --- pkg/nolol/parser.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/nolol/parser.go b/pkg/nolol/parser.go index b83d257..dbc22f2 100644 --- a/pkg/nolol/parser.go +++ b/pkg/nolol/parser.go @@ -220,10 +220,10 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if p.IsCurrentType(ast.TypeComment) { mdef.PreComments = append(mdef.PreComments, p.CurrentToken.Value) p.Advance() - if p.IsCurrentType(ast.TypeNewline) { + if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { p.Advance() } - } else if p.IsCurrentType(ast.TypeNewline) { + } else if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { mdef.PreComments = append(mdef.PreComments, "") p.Advance() } else { @@ -255,10 +255,10 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if p.IsCurrentType(ast.TypeComment) { mdef.PostComments = append(mdef.PostComments, p.CurrentToken.Value) p.Advance() - if p.IsCurrentType(ast.TypeNewline) { + if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { p.Advance() } - } else if p.IsCurrentType(ast.TypeNewline) { + } else if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { mdef.PostComments = append(mdef.PostComments, "") p.Advance() } else { @@ -408,7 +408,7 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { p.Expect(ast.TypeKeyword, "then") - if p.IsCurrentType(ast.TypeNewline) { + if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { p.Advance() } else { // We fucked up, this is not a multiline if. Restore saved state and return From 4e4c5eccec5e80412e532879de55060ba5df4f2b Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 01:08:19 +1200 Subject: [PATCH 3/6] Reverse changes to yolol parser --- pkg/parser/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index f956139..64f1700 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -172,7 +172,7 @@ func (p *Parser) ErrorString(message string, code string) { func (p *Parser) Expect(tokenType string, tokenValue string) ast.Position { if !p.IsCurrent(tokenType, tokenValue) { var msg string - if tokenType == ast.TypeNewline || tokenType == ast.TypeComment { + if tokenType == ast.TypeNewline { msg = "Expected newline" } else { msg = fmt.Sprintf("Expected token '%s'(%s)", tokenValue, tokenType) From 44199c2c06a187f0a8d115067a1279701009b94e Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 01:15:50 +1200 Subject: [PATCH 4/6] Revert changes to nolol parser --- pkg/nolol/parser.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/nolol/parser.go b/pkg/nolol/parser.go index dbc22f2..b83d257 100644 --- a/pkg/nolol/parser.go +++ b/pkg/nolol/parser.go @@ -220,10 +220,10 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if p.IsCurrentType(ast.TypeComment) { mdef.PreComments = append(mdef.PreComments, p.CurrentToken.Value) p.Advance() - if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { + if p.IsCurrentType(ast.TypeNewline) { p.Advance() } - } else if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { + } else if p.IsCurrentType(ast.TypeNewline) { mdef.PreComments = append(mdef.PreComments, "") p.Advance() } else { @@ -255,10 +255,10 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if p.IsCurrentType(ast.TypeComment) { mdef.PostComments = append(mdef.PostComments, p.CurrentToken.Value) p.Advance() - if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { + if p.IsCurrentType(ast.TypeNewline) { p.Advance() } - } else if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { + } else if p.IsCurrentType(ast.TypeNewline) { mdef.PostComments = append(mdef.PostComments, "") p.Advance() } else { @@ -408,7 +408,7 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { p.Expect(ast.TypeKeyword, "then") - if p.IsCurrentType(ast.TypeNewline) || p.IsCurrentType(ast.TypeComment) { + if p.IsCurrentType(ast.TypeNewline) { p.Advance() } else { // We fucked up, this is not a multiline if. Restore saved state and return From 43982a35a96de36340c2c41c2d12c42a9083b7b5 Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 01:47:20 +1200 Subject: [PATCH 5/6] Check for TypeComment before expecting TypeNewline --- pkg/nolol/parser.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/nolol/parser.go b/pkg/nolol/parser.go index b83d257..92cb53e 100644 --- a/pkg/nolol/parser.go +++ b/pkg/nolol/parser.go @@ -147,6 +147,9 @@ func (p *Parser) ParseInclude() *nast.IncludeDirective { incl.File = p.CurrentToken.Value p.Advance() if !p.IsCurrentType(ast.TypeEOF) { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } return incl @@ -212,6 +215,9 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { mdef.Type = p.CurrentToken.Value p.Advance() + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") if mdef.Type != nast.MacroTypeBlock { @@ -246,6 +252,9 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if mdef.Code == nil { p.ErrorExpectedExpression("inside macro of type expr") } + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } @@ -344,6 +353,9 @@ func (p *Parser) ParseStatementLine() *nast.StatementLine { } if !p.IsCurrentType(ast.TypeEOF) { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } @@ -374,6 +386,9 @@ func (p *Parser) ParseDefinition() *nast.Definition { } decl.Value = value if !p.IsCurrentType(ast.TypeEOF) { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } return decl @@ -436,6 +451,9 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { p.Advance() continue } else { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") mlif.ElseBlock = p.ParseBlock(func() bool { return p.IsCurrent(ast.TypeKeyword, "end") @@ -447,6 +465,9 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { p.Expect(ast.TypeKeyword, "end") if !p.IsCurrentType(ast.TypeEOF) { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } @@ -470,6 +491,9 @@ func (p *Parser) ParseWhile() nast.NestableElement { } p.Expect(ast.TypeKeyword, "do") + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") loop.Block = p.ParseBlock(func() bool { @@ -479,6 +503,9 @@ func (p *Parser) ParseWhile() nast.NestableElement { p.Expect(ast.TypeKeyword, "end") if !p.IsCurrentType(ast.TypeEOF) { + if p.IsCurrentType(ast.TypeComment) { + p.Advance() + } p.Expect(ast.TypeNewline, "") } From cafff623af4e553e6a8dd3aa363c2eb19eceb02a Mon Sep 17 00:00:00 2001 From: Woccz <44993506+Woccz@users.noreply.github.com> Date: Thu, 28 Apr 2022 02:07:09 +1200 Subject: [PATCH 6/6] if TypeComment do not expect TypeNewline --- pkg/nolol/parser.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/nolol/parser.go b/pkg/nolol/parser.go index 92cb53e..112a18b 100644 --- a/pkg/nolol/parser.go +++ b/pkg/nolol/parser.go @@ -149,8 +149,9 @@ func (p *Parser) ParseInclude() *nast.IncludeDirective { if !p.IsCurrentType(ast.TypeEOF) { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") } return incl } @@ -217,8 +218,9 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") if mdef.Type != nast.MacroTypeBlock { mdef.PreComments = make([]string, 0) @@ -254,8 +256,9 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition { } if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") } if mdef.Type != nast.MacroTypeBlock { @@ -355,8 +358,10 @@ func (p *Parser) ParseStatementLine() *nast.StatementLine { if !p.IsCurrentType(ast.TypeEOF) { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") + } return &ret @@ -388,8 +393,9 @@ func (p *Parser) ParseDefinition() *nast.Definition { if !p.IsCurrentType(ast.TypeEOF) { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") } return decl } @@ -453,8 +459,9 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { } else { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") mlif.ElseBlock = p.ParseBlock(func() bool { return p.IsCurrent(ast.TypeKeyword, "end") }) @@ -467,8 +474,9 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement { if !p.IsCurrentType(ast.TypeEOF) { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") } return &mlif @@ -493,8 +501,9 @@ func (p *Parser) ParseWhile() nast.NestableElement { p.Expect(ast.TypeKeyword, "do") if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") loop.Block = p.ParseBlock(func() bool { return p.IsCurrent(ast.TypeKeyword, "end") @@ -505,8 +514,9 @@ func (p *Parser) ParseWhile() nast.NestableElement { if !p.IsCurrentType(ast.TypeEOF) { if p.IsCurrentType(ast.TypeComment) { p.Advance() + } else { + p.Expect(ast.TypeNewline, "") } - p.Expect(ast.TypeNewline, "") } return &loop