Skip to content

Commit

Permalink
Merge pull request #287 from Eclalang/issue-#242-multiligne-str
Browse files Browse the repository at this point in the history
fix multi ligne string for lexer. PTGLK !
  • Loading branch information
tot0p authored Feb 27, 2024
2 parents 77ef8a1 + 0b33462 commit 5d8ccab
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
19 changes: 15 additions & 4 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Lexer(sentence string) []Token {
// syntaxes with our tempVal, If the comparison is true,
// tempVal is a known syntaxes, and then a token
if ident.IsSyntaxe(tempVal) {

// canot be a text now
canBeText = false
if (ident.Identifier == COMMENT || ident.Identifier == COMMENTGROUP) && inQuote && len(ret) != 0 {
Expand Down Expand Up @@ -134,8 +135,6 @@ func Lexer(sentence string) []Token {
inQuoteStep = true
QuoteIdentifier = "'"
}
} else {

}
// -----------Quote Token Part END-------------

Expand Down Expand Up @@ -164,14 +163,26 @@ func Lexer(sentence string) []Token {

if QuoteIdentifier == "\"" {
if inQuote {
ret = inQuoteChange(STRING, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
if inQuote && tempVal == "\n" {
ret = inQuoteChange(STRING, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
QuoteIdentifier = ""
inQuote = false
} else {
ret = inQuoteChange(STRING, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
}
} else {
ret = inQuoteChange(STRING, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
QuoteIdentifier = ""
}
} else if QuoteIdentifier == "'" {
if inQuote {
ret = inQuoteChange(CHAR, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
if inQuote && tempVal == "\n" {
ret = inQuoteChange(CHAR, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
QuoteIdentifier = ""
inQuote = false
} else {
ret = inQuoteChange(CHAR, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
}
} else {
ret = inQuoteChange(CHAR, QuoteIdentifier, inQuote && !inQuoteStep, ret, ident, tempVal, prevIndex, sentence)
QuoteIdentifier = ""
Expand Down
6 changes: 3 additions & 3 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func TestCharString2(t *testing.T) {
tLexer(t, testCHARSTRING2, "testCharString2")
}

/*func TestCharString3(t *testing.T) {
tLexer(t, testCHARSTRING3, "testCharString3")
}*/
func TestMultiLigneString(t *testing.T) {
tLexer(t, testMultiLigneString, "testMultiLigneString")
}

func TestPositionDetector_1(t *testing.T) {
var Expected1 = 1 //position
Expand Down
59 changes: 59 additions & 0 deletions lexer/lexer_test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,63 @@ var (
},
},
}
testMultiLigneString = testList{
input: "b := \"hello\nworld\";",
output: []Token{
{
TokenType: TEXT,
Value: `b`,
Position: 1,
Line: 1,
},
{
TokenType: COLON,
Value: `:`,
Position: 3,
Line: 1,
},
{
TokenType: ASSIGN,
Value: `=`,
Position: 4,
Line: 1,
},
{
TokenType: DQUOTE,
Value: `"`,
Position: 6,
Line: 1,
},
{
TokenType: STRING,
Value: "hello\n",
Position: 7,
Line: 1,
},
{
TokenType: TEXT,
Value: `world`,
Position: 1,
Line: 2,
},
{
TokenType: DQUOTE,
Value: `"`,
Position: 6,
Line: 2,
},
{
TokenType: STRING,
Value: `;`,
Position: 7,
Line: 2,
},
{
TokenType: EOF,
Value: ``,
Position: 8,
Line: 2,
},
},
}
)

0 comments on commit 5d8ccab

Please sign in to comment.