Merge pull request #115 from z7zmey/feature-110

[#105] fix counting newlines in strings
This commit is contained in:
Vadym Slizov 2020-07-26 19:15:21 +02:00 committed by GitHub
commit cbf185c8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5805 additions and 4508 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,13 +47,13 @@ func (lex *Lexer) Lex(lval Lval) int {
action heredoc_lbl_start {lblStart = lex.p} action heredoc_lbl_start {lblStart = lex.p}
action heredoc_lbl_end {lblEnd = lex.p} action heredoc_lbl_end {lblEnd = lex.p}
action constant_string_new_line { action new_line {
if lex.data[lex.p] == '\n' { if lex.data[lex.p] == '\n' {
lex.NewLines.Append(lex.p) lex.NewLines.Append(lex.p+1)
} }
if lex.data[lex.p] == '\r' && lex.data[lex.p+1] != '\n' { if lex.data[lex.p] == '\r' && lex.data[lex.p+1] != '\n' {
lex.NewLines.Append(lex.p) lex.NewLines.Append(lex.p+1)
} }
} }
@ -63,7 +63,7 @@ func (lex *Lexer) Lex(lval Lval) int {
action is_not_string_end_or_var { lex.isNotStringEnd('"') && lex.isNotStringVar() } action is_not_string_end_or_var { lex.isNotStringEnd('"') && lex.isNotStringVar() }
action is_not_backqoute_end_or_var { lex.isNotStringEnd('`') && lex.isNotStringVar() } action is_not_backqoute_end_or_var { lex.isNotStringEnd('`') && lex.isNotStringVar() }
newline = ('\r\n' >(nl, 1) | '\r' >(nl, 0) | '\n' >(nl, 0)) %{lex.NewLines.Append(lex.p);}; newline = ('\r\n' >(nl, 1) | '\r' >(nl, 0) | '\n' >(nl, 0)) $new_line %{};
any_line = any | newline; any_line = any | newline;
whitespace = [\t\v\f ]; whitespace = [\t\v\f ];
whitespace_line = [\t\v\f ] | newline; whitespace_line = [\t\v\f ] | newline;
@ -91,45 +91,45 @@ func (lex *Lexer) Lex(lval Lval) int {
# single qoute string # single qoute string
qoute: ( qoute: (
(any - [\\'\r\n]) -> qoute (any - [\\'\r\n]) -> qoute
| "\r" @constant_string_new_line -> qoute | "\r" @new_line -> qoute
| "\n" @constant_string_new_line -> qoute | "\n" @new_line -> qoute
| "\\" -> qoute_any | "\\" -> qoute_any
| "'" -> final | "'" -> final
), ),
qoute_any: ( qoute_any: (
(any - [\r\n]) -> qoute (any - [\r\n]) -> qoute
| "\r" @constant_string_new_line -> qoute | "\r" @new_line -> qoute
| "\n" @constant_string_new_line -> qoute | "\n" @new_line -> qoute
), ),
# double qoute string # double qoute string
double_qoute: ( double_qoute: (
(any - [\\"${\r\n]) -> double_qoute (any - [\\"${\r\n]) -> double_qoute
| "\r" @constant_string_new_line -> double_qoute | "\r" @new_line -> double_qoute
| "\n" @constant_string_new_line -> double_qoute | "\n" @new_line -> double_qoute
| "\\" -> double_qoute_any | "\\" -> double_qoute_any
| '"' -> final | '"' -> final
| '$' -> double_qoute_nonvarname | '$' -> double_qoute_nonvarname
| '{' -> double_qoute_nondollar | '{' -> double_qoute_nondollar
), ),
double_qoute_any: ( double_qoute_any: (
(any - [\r\n]) -> double_qoute (any - [\r\n]) -> double_qoute
| "\r" @constant_string_new_line -> double_qoute | "\r" @new_line -> double_qoute
| "\n" @constant_string_new_line -> double_qoute | "\n" @new_line -> double_qoute
), ),
double_qoute_nondollar: ( double_qoute_nondollar: (
(any - [\\$"\r\n]) -> double_qoute (any - [\\$"\r\n]) -> double_qoute
| "\r" @constant_string_new_line -> double_qoute | "\r" @new_line -> double_qoute
| "\n" @constant_string_new_line -> double_qoute | "\n" @new_line -> double_qoute
| "\\" -> double_qoute_any | "\\" -> double_qoute_any
| '"' -> final | '"' -> final
), ),
double_qoute_nonvarname: ( double_qoute_nonvarname: (
(any - [\\{"\r\n] - varname_first) -> double_qoute (any - [\\{"\r\n] - varname_first) -> double_qoute
| "\r" @constant_string_new_line -> double_qoute | "\r" @new_line -> double_qoute
| "\n" @constant_string_new_line -> double_qoute | "\n" @new_line -> double_qoute
| "\\" -> double_qoute_any | "\\" -> double_qoute_any
| '"' -> final | '"' -> final
); );