[#105] fix counting newlines in strings
This commit is contained in:
parent
eb3114b7c5
commit
3ce3188e41
9859
scanner/scanner.go
9859
scanner/scanner.go
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||||
@ -92,23 +92,23 @@ func (lex *Lexer) Lex(lval Lval) int {
|
|||||||
|
|
||||||
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
|
||||||
@ -116,20 +116,20 @@ func (lex *Lexer) Lex(lval Lval) int {
|
|||||||
),
|
),
|
||||||
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
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user