Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser permit nolol inline comments (untested) #122

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions pkg/nolol/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ func (p *Parser) ParseInclude() *nast.IncludeDirective {
incl.File = p.CurrentToken.Value
p.Advance()
if !p.IsCurrentType(ast.TypeEOF) {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
}
return incl
}
Expand Down Expand Up @@ -212,7 +216,11 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition {
mdef.Type = p.CurrentToken.Value
p.Advance()

p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}

if mdef.Type != nast.MacroTypeBlock {
mdef.PreComments = make([]string, 0)
Expand Down Expand Up @@ -246,7 +254,11 @@ func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition {
if mdef.Code == nil {
p.ErrorExpectedExpression("inside macro of type expr")
}
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
}

if mdef.Type != nast.MacroTypeBlock {
Expand Down Expand Up @@ -344,7 +356,12 @@ func (p *Parser) ParseStatementLine() *nast.StatementLine {
}

if !p.IsCurrentType(ast.TypeEOF) {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}

}

return &ret
Expand Down Expand Up @@ -374,7 +391,11 @@ func (p *Parser) ParseDefinition() *nast.Definition {
}
decl.Value = value
if !p.IsCurrentType(ast.TypeEOF) {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
}
return decl
}
Expand Down Expand Up @@ -436,7 +457,11 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement {
p.Advance()
continue
} else {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
mlif.ElseBlock = p.ParseBlock(func() bool {
return p.IsCurrent(ast.TypeKeyword, "end")
})
Expand All @@ -447,7 +472,11 @@ func (p *Parser) ParseMultilineIf() nast.NestableElement {
p.Expect(ast.TypeKeyword, "end")

if !p.IsCurrentType(ast.TypeEOF) {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
}

return &mlif
Expand All @@ -470,7 +499,11 @@ func (p *Parser) ParseWhile() nast.NestableElement {
}

p.Expect(ast.TypeKeyword, "do")
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}

loop.Block = p.ParseBlock(func() bool {
return p.IsCurrent(ast.TypeKeyword, "end")
Expand All @@ -479,7 +512,11 @@ func (p *Parser) ParseWhile() nast.NestableElement {
p.Expect(ast.TypeKeyword, "end")

if !p.IsCurrentType(ast.TypeEOF) {
p.Expect(ast.TypeNewline, "")
if p.IsCurrentType(ast.TypeComment) {
p.Advance()
} else {
p.Expect(ast.TypeNewline, "")
}
}

return &loop
Expand Down