gbranden pushed a commit to branch master
in repository groff.
commit 31adf1f45b20a141a071523fabe5ea7639b71619
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Nov 20 12:03:55 2025 -0600
[troff]: Slightly refactor.
Make the global function `check_missing_character()` a member function
of the `token` class since it operates only on token objects and can be
more economically expressed that way. Rename it.
* src/roff/troff/token.h: Drop `extern` declaration of global
`check_missing_character()`.
(class token): Declare new member function.
* src/roff/troff/input.cpp (check_missing_character): Relocate from
here...
(token::diagnose_non_character): ...to here, renaming.
* src/roff/troff/env.cpp (margin_character):
* src/roff/troff/input.cpp (read_character): Update call sites.
---
ChangeLog | 16 ++++++++++++++++
src/roff/troff/env.cpp | 2 +-
src/roff/troff/input.cpp | 33 ++++++++++++++++++++++++---------
src/roff/troff/token.h | 2 +-
4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 32a18ae96..e9a5fb3a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2025-11-20 G. Branden Robinson <[email protected]>
+
+ [troff]: Slightly refactor. Make the global function
+ `check_missing_character()` a member function of the `token`
+ class since it operates only on token objects and can be more
+ economically expressed that way. Rename it.
+
+ * src/roff/troff/token.h: Drop `extern` declaration of global
+ `check_missing_character()`.
+ (class token): Declare new member function.
+ * src/roff/troff/input.cpp (check_missing_character): Relocate
+ from here...
+ (token::diagnose_non_character): ...to here, renaming.
+ * src/roff/troff/env.cpp (margin_character):
+ * src/roff/troff/input.cpp (read_character): Update call sites.
+
2025-11-20 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (define_character)
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index b7692d96c..67ea36bbf 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1676,7 +1676,7 @@ void margin_character()
tok.skip_spaces();
charinfo *ci = tok.get_charinfo();
if (0 /* nullptr */ == ci) { // no argument
- check_missing_character();
+ tok.diagnose_non_character();
curenv->margin_character_flags &= ~environment::MC_ON;
if (curenv->margin_character_flags == 0U) {
delete curenv->margin_character_node;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 562d64802..d16616ddf 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2015,6 +2015,29 @@ void token::skip_spaces()
next();
}
+void token::diagnose_non_character()
+{
+ // TODO: What about
+ // is_space()
+ // is_stretchable_space()
+ // is_unstrechable_space()
+ // is_horizontal_space()
+ // is_white_space()
+ // is_leader()
+ // is_backspace()
+ // is_dummy()
+ // is_transparent()
+ // is_transparent_dummy()
+ // is_left_brace()
+ // is_page_ejector()
+ // is_hyphen_indicator()
+ // is_zero_width_break()
+ // ?
+ if (!is_newline() && !is_eof() && !is_right_brace() && !is_tab())
+ error("expected ordinary, special, or indexed character, got %1;"
+ " ignoring", description());
+}
+
// Indicate whether an argument lies ahead on the current line in the
// input stream, skipping over spaces. This function is therefore not
// appropriate for use when handling requests or escape sequences that
@@ -8688,20 +8711,12 @@ charinfo *read_character(/* TODO?: bool required */)
charinfo *ci = tok.get_charinfo();
// TODO?: if (required && (0 /* nullptr */ == ci))
if (0 /* nullptr */ == ci)
- check_missing_character();
+ tok.diagnose_non_character();
else
tok.next();
return ci;
}
-void check_missing_character()
-{
- if (!tok.is_newline() && !tok.is_eof() && !tok.is_right_brace()
- && !tok.is_tab())
- error("expected ordinary, special, or indexed character, got %1;"
- " ignoring", tok.description());
-}
-
// this is for \Z
bool token::add_to_zero_width_node_list(node **pp)
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index 41cc3a004..3435cc5e6 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -81,6 +81,7 @@ public:
void next();
void process();
void skip_spaces();
+ void diagnose_non_character();
int nspaces(); // is_space() as integer
bool is_eof();
bool is_space();
@@ -126,7 +127,6 @@ extern symbol read_identifier(bool /* required */ = false);
extern symbol get_long_name(bool /* required */ = false);
extern charinfo *read_character(); // TODO?: bool /* required */ = false
extern char *read_rest_of_line_as_argument();
-extern void check_missing_character();
extern void skip_line();
extern void handle_initial_title();
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit