• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3883 (tree)
Time2018-09-19 00:55:25
Authormagicant

Log Message

Remove unused functions in parser.c

The parse_word_to function is renamed to parse_word, which is one of the
functions removed in this commit.

Change Summary

Incremental Difference

--- yash/branches/token_based_parser/parser.c (revision 3882)
+++ yash/branches/token_based_parser/parser.c (revision 3883)
@@ -549,22 +549,14 @@
549549 __attribute__((nonnull));
550550 static void rewind_index(parsestate_T *ps, size_t to)
551551 __attribute__((nonnull));
552-static void ensure_buffer(parsestate_T *ps, size_t n)
553- __attribute__((nonnull));
554552 static size_t count_name_length(parsestate_T *ps, bool isnamechar(wchar_t c))
555553 __attribute__((nonnull));
556-static void skip_blanks_and_comment(parsestate_T *ps)
557- __attribute__((nonnull));
558554 static void next_token(parsestate_T *ps)
559555 __attribute__((nonnull));
560-static bool skip_to_next_token(parsestate_T *ps)
561- __attribute__((nonnull));
562556 static void next_line(parsestate_T *ps)
563557 __attribute__((nonnull));
564558 static bool parse_newline_list(parsestate_T *ps)
565559 __attribute__((nonnull));
566-static bool is_command_delimiter_char(wchar_t c)
567- __attribute__((const));
568560 static bool is_comma_or_closing_bracket(wchar_t c)
569561 __attribute__((const));
570562 static bool is_slash_or_closing_brace(wchar_t c)
@@ -571,10 +563,6 @@
571563 __attribute__((const));
572564 static bool is_closing_brace(wchar_t c)
573565 __attribute__((const));
574-static bool has_token(const parsestate_T *ps, const wchar_t *t)
575- __attribute__((pure,nonnull));
576-static const wchar_t *check_opening_token(parsestate_T *ps)
577- __attribute__((nonnull));
578566 static bool psubstitute_alias(parsestate_T *ps, substaliasflags_T f)
579567 __attribute__((nonnull));
580568 static void psubstitute_alias_recursive(parsestate_T *ps, substaliasflags_T f)
@@ -606,10 +594,8 @@
606594 __attribute__((nonnull,malloc,warn_unused_result));
607595 static redir_T *tryparse_redirect(parsestate_T *ps)
608596 __attribute__((nonnull,malloc,warn_unused_result));
609-static wordunit_T *parse_word(parsestate_T *ps, bool globalaliases)
597+static wordunit_T *parse_word(parsestate_T *ps, bool testfunc(wchar_t c))
610598 __attribute__((nonnull,malloc,warn_unused_result));
611-static wordunit_T *parse_word_to(parsestate_T *ps, bool testfunc(wchar_t c))
612- __attribute__((nonnull,malloc,warn_unused_result));
613599 static void skip_to_next_single_quote(parsestate_T *ps)
614600 __attribute__((nonnull));
615601 static wordunit_T *parse_special_word_unit(parsestate_T *ps, bool indq)
@@ -628,8 +614,6 @@
628614 __attribute__((nonnull,malloc,warn_unused_result));
629615 static wordunit_T *tryparse_arith(parsestate_T *ps)
630616 __attribute__((nonnull,malloc,warn_unused_result));
631-static wchar_t *parse_word_as_wcs(parsestate_T *ps)
632- __attribute__((nonnull,malloc,warn_unused_result));
633617 static command_T *parse_compound_command(parsestate_T *ps)
634618 __attribute__((nonnull,malloc,warn_unused_result));
635619 static command_T *parse_group(parsestate_T *ps)
@@ -856,35 +840,6 @@
856840 }
857841 }
858842
859-/* If a line continuation is found within `n' characters from the current
860- * position `ps->index', removes the backslash-newline pair and reads the next
861- * line.
862- * If a backslash that is not a line continuation is found within `n' characters
863- * from the current position, this function does nothing. */
864-/* For quickness, `n' should be as small as possible. */
865-void ensure_buffer(parsestate_T *ps, size_t n)
866-{
867- size_t index = ps->index;
868- if (ps->src.contents[index] == L'\0')
869- read_more_input(ps);
870- while (index - ps->index < n) {
871- switch (ps->src.contents[index]) {
872- case L'\0': case L'\'':
873- return;
874- case L'\\':
875- if (ps->src.contents[index + 1] != L'\n')
876- return;
877- line_continuation(ps, index);
878- if (ps->info->lastinputresult != INPUT_OK)
879- return;
880- break;
881- default:
882- index++;
883- break;
884- }
885- }
886-}
887-
888843 /* Returns the length of the name at the current position.
889844 * Whether a character can be part of the name is determined by `isnamechar'.
890845 * This function processes line continuations and reads so many lines that the
@@ -898,41 +853,6 @@
898853 return index - ps->index;
899854 }
900855
901-/* Advances the current position `ps->index', skipping blank characters,
902- * comments, and line continuations.
903- * This function calls `read_more_input' if the current line has not been read
904- * or when a line continuation is encountered.
905- * The current position is advanced to the next non-blank character.
906- * Line continuations are actually removed rather than skipped. */
907-/* Note that a newline is not a blank character. After a comment was skipped,
908- * the position will be at the newline character (or EOF) that follows. */
909-void skip_blanks_and_comment(parsestate_T *ps)
910-{
911- if (ps->src.contents[ps->index] == L'\0')
912- if (read_more_input(ps) != INPUT_OK)
913- return;
914-
915-start:
916- /* skip blanks */
917- while (iswblank(ps->src.contents[ps->index]))
918- ps->index++;
919-
920- /* skip a comment */
921- if (ps->src.contents[ps->index] == L'#') {
922- do {
923- ps->index++;
924- } while (ps->src.contents[ps->index] != L'\n' &&
925- ps->src.contents[ps->index] != L'\0');
926- }
927-
928- /* remove line continuation */
929- if (ps->src.contents[ps->index] == L'\\' &&
930- ps->src.contents[ps->index + 1] == L'\n') {
931- line_continuation(ps, ps->index);
932- goto start;
933- }
934-}
935-
936856 /* Moves to the next token, updating `index', `next_index', `tokentype', and
937857 * `token' of the parse state.
938858 * The existing `token' is freed. */
@@ -1036,7 +956,7 @@
1036956 /* Okay, the next token seems to be a word, possibly being a
1037957 * reserved word or an IO_NUMBER token. */
1038958 ps->index = index;
1039- wordunit_T *token = parse_word_to(ps, is_token_delimiter_char);
959+ wordunit_T *token = parse_word(ps, is_token_delimiter_char);
1040960 index = ps->index;
1041961
1042962 wordfree(ps->token);
@@ -1060,25 +980,6 @@
1060980 ps->next_index = index;
1061981 }
1062982
1063-/* Advances the current position `ps->index', skipping blank characters,
1064- * comments and newlines, up to the next token.
1065- * This function calls `read_more_input' if the next token cannot be found in
1066- * the current line.
1067- * Returns true iff at least one newline token is skipped. */
1068-bool skip_to_next_token(parsestate_T *ps)
1069-{
1070- bool newline = false;
1071-
1072- skip_blanks_and_comment(ps);
1073- while (ps->info->lastinputresult == INPUT_OK &&
1074- ps->src.contents[ps->index] == L'\n') {
1075- newline = true;
1076- next_line(ps);
1077- skip_blanks_and_comment(ps);
1078- }
1079- return newline;
1080-}
1081-
1082983 /* Parses the newline token at the current position and proceeds to the next
1083984 * line. The contents of pending here-documents are read if any. The current
1084985 * token is cleared. */
@@ -1123,18 +1024,6 @@
11231024 }
11241025 }
11251026
1126-/* Checks if the specified character delimits a simple command. */
1127-bool is_command_delimiter_char(wchar_t c)
1128-{
1129- switch (c) {
1130- case L'\0': case L'\n': case L';': case L'&': case L'|':
1131- case L'(': case L')':
1132- return true;
1133- default:
1134- return false;
1135- }
1136-}
1137-
11381027 bool is_comma_or_closing_bracket(wchar_t c)
11391028 {
11401029 return c == L']' || c == L',';
@@ -1150,37 +1039,7 @@
11501039 return c == L'}';
11511040 }
11521041
1153-/* Checks if token `t' exists at the current position in `ps->src'.
1154- * `t' must not be a proper substring of another operator token. (For example,
1155- * `t' cannot be L"&" because it is a proper substring of another operator token
1156- * L"&&". However, L"do" is OK for `t' even though it is a substring of the
1157- * keyword L"done", which is not an operator token.)
1158- * This function does not handle line continuations. The caller may need to call
1159- * `ensure_buffer(wcslen(t))' before calling this function. */
1160-bool has_token(const parsestate_T *ps, const wchar_t *t)
1161-{
1162- const wchar_t *c = matchwcsprefix(&ps->src.contents[ps->index], t);
1163- return c != NULL && is_token_delimiter_char(*c);
1164-}
11651042
1166-/* Checks if there is an 'opening' token such as "(", "{", and "if" at the
1167- * current position. If there is one, the token string is returned.
1168- * Otherwise, NULL is returned.
1169- * This function calls `ensure_buffer(ps, 9)'. */
1170-const wchar_t *check_opening_token(parsestate_T *ps)
1171-{
1172- ensure_buffer(ps, 9);
1173- if (ps->src.contents[ps->index] == L'(') return L"(";
1174- if (has_token(ps, L"{")) return L"{";
1175- if (has_token(ps, L"if")) return L"if";
1176- if (has_token(ps, L"for")) return L"for";
1177- if (has_token(ps, L"while")) return L"while";
1178- if (has_token(ps, L"until")) return L"until";
1179- if (has_token(ps, L"case")) return L"case";
1180- if (has_token(ps, L"function")) return L"function";
1181- return NULL;
1182-}
1183-
11841043 /* Performs alias substitution with the given parse state. Proceeds to the
11851044 * next token if substitution occurred. This function does not substitute an
11861045 * IO_NUMBER token, but do a keyword token. */
@@ -1213,8 +1072,7 @@
12131072
12141073 /* Parses commands.
12151074 * If `toeol' is true, commands are parsed up to the end of the current input;
1216- * otherwise, up to the next closing token.
1217- * You don't have to call `skip_blanks_and_comment' beforehand. */
1075+ * otherwise, up to the next closing token. */
12181076 and_or_T *parse_command_list(parsestate_T *ps, bool toeol)
12191077 {
12201078 and_or_T *first = NULL, **lastp = &first;
@@ -1282,8 +1140,7 @@
12821140 return first;
12831141 }
12841142
1285-/* Parses commands until a closing token is found.
1286- * You don't have to call `skip_blanks_and_comment' beforehand. */
1143+/* Parses commands until a closing token is found. */
12871144 and_or_T *parse_compound_list(parsestate_T *ps)
12881145 {
12891146 return parse_command_list(ps, false);
@@ -1728,16 +1585,6 @@
17281585 return result;
17291586 }
17301587
1731-/* Parses a word at the current position. If `globalaliases' is true, global
1732- * aliases are substituted before the word is parsed. */
1733-wordunit_T *parse_word(parsestate_T *ps, bool globalaliases)
1734-{
1735- if (globalaliases)
1736- psubstitute_alias_recursive(ps, 0);
1737-
1738- return parse_word_to(ps, is_token_delimiter_char);
1739-}
1740-
17411588 /* Parses a word at the current position.
17421589 * `testfunc' is a function that determines if a character is a word delimiter.
17431590 * The parsing proceeds up to an unescaped character for which `testfunc'
@@ -1744,7 +1591,7 @@
17441591 * returns false.
17451592 * It is not an error if there is no characters to be a word, in which case
17461593 * NULL is returned. */
1747-wordunit_T *parse_word_to(parsestate_T *ps, bool testfunc(wchar_t c))
1594+wordunit_T *parse_word(parsestate_T *ps, bool testfunc(wchar_t c))
17481595 {
17491596 wordunit_T *first = NULL, **lastp = &first;
17501597 bool indq = false; /* in double quotes? */
@@ -2000,12 +1847,12 @@
20001847 // maybe_line_continuations(ps, ps->index); // already called above
20011848 if (!posixly_correct && ps->src.contents[ps->index] == L'[') {
20021849 ps->index++;
2003- pe->pe_start = parse_word_to(ps, is_comma_or_closing_bracket);
1850+ pe->pe_start = parse_word(ps, is_comma_or_closing_bracket);
20041851 if (pe->pe_start == NULL)
20051852 serror(ps, Ngt("the index is missing"));
20061853 if (ps->src.contents[ps->index] == L',') {
20071854 ps->index++;
2008- pe->pe_end = parse_word_to(ps, is_comma_or_closing_bracket);
1855+ pe->pe_end = parse_word(ps, is_comma_or_closing_bracket);
20091856 if (pe->pe_end == NULL)
20101857 serror(ps, Ngt("the index is missing"));
20111858 }
@@ -2082,11 +1929,11 @@
20821929 ps->index += 1;
20831930 }
20841931 if ((pe->pe_type & PT_MASK) == PT_MATCH) {
2085- pe->pe_match = parse_word_to(ps, is_closing_brace);
1932+ pe->pe_match = parse_word(ps, is_closing_brace);
20861933 goto check_closing_brace;
20871934 } else {
2088- pe->pe_match = parse_word_to(ps, is_slash_or_closing_brace);
2089- // maybe_line_continuations(ps, ps->index); // called in parse_word_to
1935+ pe->pe_match = parse_word(ps, is_slash_or_closing_brace);
1936+ // maybe_line_continuations(ps, ps->index); // called in parse_word
20901937 if (ps->src.contents[ps->index] != L'/')
20911938 goto check_closing_brace;
20921939 }
@@ -2093,7 +1940,7 @@
20931940
20941941 parse_subst:
20951942 ps->index++;
2096- pe->pe_subst = parse_word_to(ps, is_closing_brace);
1943+ pe->pe_subst = parse_word(ps, is_closing_brace);
20971944
20981945 check_closing_brace:
20991946 // maybe_line_continuations(ps, ps->index); // already called above
@@ -2317,19 +2164,6 @@
23172164 return NULL;
23182165 }
23192166
2320-/* Returns a word token at the current index as a newly malloced string.
2321- * The current position is advanced to the character that just follows the word.
2322- * This function never returns NULL, but may return an empty string. */
2323-wchar_t *parse_word_as_wcs(parsestate_T *ps)
2324-{
2325- psubstitute_alias_recursive(ps, 0);
2326-
2327- size_t startindex = ps->index;
2328- wordfree(parse_word_to(ps, is_token_delimiter_char));
2329- assert(startindex <= ps->index);
2330- return xwcsndup(&ps->src.contents[startindex], ps->index - startindex);
2331-}
2332-
23332167 /* Parses a compound command.
23342168 * `command' is the name of the command to parse such as "(" and "if".
23352169 * Returns NULL iff the current token does not start a compound command. */
Show on old repository browser