Skip to content

Commit

Permalink
Merge pull request #148 from gobuffalo/master
Browse files Browse the repository at this point in the history
Comments support
  • Loading branch information
paganotoni authored Oct 27, 2021
2 parents 2c76410 + c2f85ef commit 69d8221
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ You can add comments like this:
<%# This is a comment %>
```

You can also add line comments within a code section

```erb
<%
# this is a comment
not_a_comment()
%>
```

## If/Else Statements

The basic syntax of `if/else if/else` statements is as follows:
Expand Down
8 changes: 8 additions & 0 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func (l *Lexer) nextInsideToken() token.Token {
case '`':
tok.Type = token.B_STRING
tok.Literal = l.readBString()
case '#':
for l.ch != 0 {
l.readChar()
if l.ch == '\n' || l.ch == '\r' {
break
}
}
tok = l.nextInsideToken()
case '[':
tok = l.newToken(token.LBRACKET)
case ']':
Expand Down
24 changes: 24 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ func Test_NextToken_Simple(t *testing.T) {
}
}

func Test_NextToken_SkipLineComments(t *testing.T) {
r := require.New(t)
input := `<%=
# comment
1
# another line comment
%>`
tests := []struct {
tokenType token.Type
tokenLiteral string
}{
{token.E_START, "<%="},
{token.INT, "1"},
{token.E_END, "%>"},
}

l := New(input)
for _, tt := range tests {
tok := l.NextToken()
r.Equal(tt.tokenType, tok.Type)
r.Equal(tt.tokenLiteral, tok.Literal)
}
}

func Test_EscapeStringQuote(t *testing.T) {
r := require.New(t)
input := `<%= "mark \"cool\" bates" %>`
Expand Down

0 comments on commit 69d8221

Please sign in to comment.