10.9. Parser Matching Utilities
Figure 10.1 shows two methods that support matching: bestMatch() and completeMatch(). The bestMatch() method accepts a single assembly, puts it in a vector, and matches against the vector. Then bestMatch() returns one assembly from the output vector of assemblies, choosing the one whose index is advanced furthest. If a grammar matches only part of an input, bestMatch() returns an assembly that shows the progress made. For example, consider matching the grammar
adjectives = ("steaming" | "hot")*;
against the string
"hot hot steaming hot coffee"
The following code sends bestMatch() to a parser for adjectives, showing that the parser can match up to the word "coffee":
package sjm.examples.mechanics; import sjm.parse.*; ...
Get Building Parsers with Java™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.