• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3879 (tree)
Zeit2018-09-19 00:55:22
Autormagicant

Log Message

Use maybe_line_continuations instead of ensure_buffer

The ensure_buffer function can read more than needed. The
maybe_line_continuations is preferred.

Ändern Zusammenfassung

Diff

--- yash/branches/token_based_parser/parser.c (revision 3878)
+++ yash/branches/token_based_parser/parser.c (revision 3879)
@@ -823,6 +823,8 @@
823823 void maybe_line_continuations(parsestate_T *ps, size_t index)
824824 {
825825 assert(index <= ps->src.length);
826+ if (index == ps->src.length)
827+ read_more_input(ps);
826828 while (ps->src.contents[index] == L'\\' &&
827829 ps->src.contents[index + 1] == L'\n')
828830 line_continuation(ps, index);
@@ -890,7 +892,8 @@
890892 size_t count_name_length(parsestate_T *ps, bool isnamechar(wchar_t c))
891893 {
892894 size_t saveindex = ps->index;
893- while (ensure_buffer(ps, 1), isnamechar(ps->src.contents[ps->index]))
895+ while (maybe_line_continuations(ps, ps->index),
896+ isnamechar(ps->src.contents[ps->index]))
894897 ps->index++;
895898
896899 size_t result = ps->index - saveindex;
@@ -1761,7 +1764,7 @@
17611764 } \
17621765 } while (0)
17631766
1764- while (ensure_buffer(ps, 1),
1767+ while (maybe_line_continuations(ps, ps->index),
17651768 indq || !testfunc(ps->src.contents[ps->index])) {
17661769
17671770 switch (ps->src.contents[ps->index]) {
@@ -1854,11 +1857,12 @@
18541857 {
18551858 switch (ps->src.contents[ps->index++]) {
18561859 case L'$':
1857- ensure_buffer(ps, 2);
1860+ maybe_line_continuations(ps, ps->index);
18581861 switch (ps->src.contents[ps->index]) {
18591862 case L'{':
18601863 return parse_paramexp_in_brace(ps);
18611864 case L'(':
1865+ maybe_line_continuations(ps, ps->index + 1);
18621866 if (ps->src.contents[ps->index + 1] == L'(') {
18631867 wordunit_T *wu = tryparse_arith(ps);
18641868 if (wu != NULL)
@@ -1885,7 +1889,7 @@
18851889 paramexp_T *pe;
18861890 size_t namelen; /* parameter name length */
18871891
1888- ensure_buffer(ps, 1);
1892+ maybe_line_continuations(ps, ps->index);
18891893 switch (ps->src.contents[ps->index]) {
18901894 case L'@': case L'*': case L'#': case L'?':
18911895 case L'-': case L'$': case L'!':
@@ -1932,13 +1936,15 @@
19321936 ps->index++;
19331937
19341938 /* parse PT_NUMBER */
1935- ensure_buffer(ps, 3);
1939+ maybe_line_continuations(ps, ps->index);
19361940 if (ps->src.contents[ps->index] == L'#') {
1941+ maybe_line_continuations(ps, ps->index + 1);
19371942 switch (ps->src.contents[ps->index + 1]) {
19381943 case L'\0': case L'}':
19391944 case L'+': case L'=': case L':': case L'/': case L'%':
19401945 break;
19411946 case L'-': case L'?': case L'#':
1947+ maybe_line_continuations(ps, ps->index + 2);
19421948 if (ps->src.contents[ps->index + 2] != L'}')
19431949 break;
19441950 /* falls thru! */
@@ -1950,7 +1956,7 @@
19501956 }
19511957
19521958 /* parse nested expansion */
1953- // ensure_buffer(2); // we've already called `ensure_buffer'
1959+ // maybe_line_continuations(ps, ps->index); // already called above
19541960 if (!posixly_correct && ps->src.contents[ps->index] == L'{') {
19551961 pe->pe_type |= PT_NEST;
19561962 pe->pe_nest = parse_paramexp_in_brace(ps);
@@ -1957,14 +1963,15 @@
19571963 } else if (!posixly_correct
19581964 && (ps->src.contents[ps->index] == L'`'
19591965 || (ps->src.contents[ps->index] == L'$'
1960- && (ps->src.contents[ps->index + 1] == L'{'
1966+ && (maybe_line_continuations(ps, ps->index + 1),
1967+ ps->src.contents[ps->index + 1] == L'{'
19611968 || ps->src.contents[ps->index + 1] == L'(')))) {
19621969 size_t neststartindex = ps->index;
19631970 pe->pe_nest = parse_special_word_unit(ps, false);
1964- if (ps->index != neststartindex)
1965- pe->pe_type |= PT_NEST;
1966- else
1971+ if (ps->index == neststartindex)
19671972 goto parse_name;
1973+ pe->pe_type |= PT_NEST;
1974+ maybe_line_continuations(ps, ps->index);
19681975 } else {
19691976 parse_name:;
19701977 /* no nesting: parse parameter name normally */
@@ -1975,7 +1982,7 @@
19751982 ps->index++;
19761983 break;
19771984 default:
1978- while (ensure_buffer(ps, 1),
1985+ while (maybe_line_continuations(ps, ps->index),
19791986 is_name_char(ps->src.contents[ps->index]))
19801987 ps->index++;
19811988 break;
@@ -1989,7 +1996,7 @@
19891996 }
19901997
19911998 /* parse indices */
1992- ensure_buffer(ps, 3);
1999+ // maybe_line_continuations(ps, ps->index); // already called above
19932000 if (!posixly_correct && ps->src.contents[ps->index] == L'[') {
19942001 ps->index++;
19952002 pe->pe_start = parse_word_to(ps, is_comma_or_closing_bracket);
@@ -2001,20 +2008,22 @@
20012008 if (pe->pe_end == NULL)
20022009 serror(ps, Ngt("the index is missing"));
20032010 }
2004- if (ps->src.contents[ps->index] == L']')
2005- ps->index++;
2006- else
2011+ if (ps->src.contents[ps->index] == L']') {
2012+ maybe_line_continuations(ps, ++ps->index);
2013+ } else {
20072014 serror(ps, Ngt("`%ls' is missing"), L"]");
2008- ensure_buffer(ps, 3);
2015+ }
20092016 }
20102017
20112018 /* parse PT_COLON */
2019+ // maybe_line_continuations(ps, ps->index); // already called above
20122020 if (ps->src.contents[ps->index] == L':') {
20132021 pe->pe_type |= PT_COLON;
2014- ps->index++;
2022+ maybe_line_continuations(ps, ++ps->index);
20152023 }
20162024
20172025 /* parse '-', '+', '#', etc. */
2026+ // maybe_line_continuations(ps, ps->index); // already called above
20182027 switch (ps->src.contents[ps->index]) {
20192028 case L'-': pe->pe_type |= PT_MINUS; goto parse_subst;
20202029 case L'+': pe->pe_type |= PT_PLUS; goto parse_subst;
@@ -2043,6 +2052,7 @@
20432052 }
20442053
20452054 parse_match:
2055+ maybe_line_continuations(ps, ps->index + 1);
20462056 if (pe->pe_type & PT_COLON) {
20472057 if ((pe->pe_type & PT_MASK) == PT_SUBST)
20482058 pe->pe_type |= PT_MATCHHEAD | PT_MATCHTAIL;
@@ -2049,7 +2059,7 @@
20492059 else
20502060 serror(ps, Ngt("invalid use of `%lc' in parameter expansion"),
20512061 (wint_t) L':');
2052- ps->index += 1;
2062+ maybe_line_continuations(ps, ++ps->index);
20532063 } else if (ps->src.contents[ps->index] ==
20542064 ps->src.contents[ps->index + 1]) {
20552065 if ((pe->pe_type & PT_MASK) == PT_MATCH)
@@ -2075,7 +2085,7 @@
20752085 goto check_closing_brace;
20762086 } else {
20772087 pe->pe_match = parse_word_to(ps, is_slash_or_closing_brace);
2078- ensure_buffer(ps, 1);
2088+ // maybe_line_continuations(ps, ps->index); // called in parse_word_to
20792089 if (ps->src.contents[ps->index] != L'/')
20802090 goto check_closing_brace;
20812091 }
@@ -2085,7 +2095,7 @@
20852095 pe->pe_subst = parse_word_to(ps, is_closing_brace);
20862096
20872097 check_closing_brace:
2088- ensure_buffer(ps, 1);
2098+ // maybe_line_continuations(ps, ps->index); // already called above
20892099 if (ps->src.contents[ps->index] == L'}')
20902100 ps->index++;
20912101 else
@@ -2113,7 +2123,7 @@
21132123 result->wu_type = WT_CMDSUB;
21142124 result->wu_cmdsub = extract_command_in_paren(ps);
21152125
2116- ensure_buffer(ps, 1);
2126+ maybe_line_continuations(ps, ps->index);
21172127 if (ps->src.contents[ps->index] == L')')
21182128 ps->index++;
21192129 else
@@ -2188,7 +2198,7 @@
21882198 assert(ps->src.contents[ps->index - 1] == L'`');
21892199 wb_init(&buf);
21902200 for (;;) {
2191- ensure_buffer(ps, 1);
2201+ maybe_line_continuations(ps, ps->index);
21922202 switch (ps->src.contents[ps->index]) {
21932203 case L'\0':
21942204 serror(ps,
@@ -2241,7 +2251,7 @@
22412251 int nestparen = 0;
22422252
22432253 for (;;) {
2244- ensure_buffer(ps, 1);
2254+ maybe_line_continuations(ps, ps->index);
22452255 switch (ps->src.contents[ps->index]) {
22462256 case L'\0':
22472257 serror(ps, Ngt("`%ls' is missing"), L"))");
@@ -2276,7 +2286,7 @@
22762286 nestparen--;
22772287 if (nestparen >= 0)
22782288 break;
2279- ensure_buffer(ps, 2);
2289+ maybe_line_continuations(ps, ps->index + 1);
22802290 switch (ps->src.contents[ps->index + 1]) {
22812291 case L')':
22822292 MAKE_WORDUNIT_STRING;
@@ -2934,7 +2944,7 @@
29342944 size_t startindex = ps->index;
29352945
29362946 for (;;) {
2937- ensure_buffer(ps, 1);
2947+ maybe_line_continuations(ps, ps->index);
29382948 switch (ps->src.contents[ps->index]) {
29392949 case L'\0':
29402950 goto done;
Show on old repository browser