Literals and dot
Match concatenated literals and the single-character wildcard.
Build it in your language
The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.
Literal Characters and Dot Metacharacter (.)
A regular expression engine tests whether text satisfies a symbolic pattern. In this first stage, implement prefix matching for literal characters and the dot (.) wildcard matching any single character except a newline.
Mental Model: Parallel Pointers
For anchored prefix matching (op: "match"):
- Advance pointers across pattern and text simultaneously.
- Dot (
.) matches any character except a newline. - Literal characters must match verbatim.
- If pattern reaches its end successfully, emit matched interval
span: [0, length].
Your Goal in this Stage
Read a JSON object from stdin with op: "match", pattern, and text. Return match status and span.
Input Format
{
"op": "match",
"pattern": "c.t",
"text": "cat"
}
Output Format
{
"matched": true,
"span": [0, 3]
}
Step-by-Step Implementation Guide
- Scan loop: Compare each pattern character against text.
- Handle dot: Permit any character except a newline.
- Emit output: Print JSON with
matchedboolean andspanarray.
Acceptance Criteria
- ✅ Matches literal strings.
- ✅ Evaluates dot as single-character wildcard excluding newlines.
- ✅ Emits
span: [0, N].
Dot never matches \n: check that exclusion before accepting the character. match checks a prefix at position zero; it does not require consuming all text.
Starting and checking progress
Open your language starter’s README. From its root, execute the build command in shipcode.yml if present, then run. The scaffold is intentionally unfinished and initially reports missing implementation. After developing this stage, run shipcode test; preserve earlier stages’ behavior and use shipcode submit after passing.
You may use a JSON library for the input/output envelope, but not to implement the project’s algorithm. If your language has no built-in JSON support, document the dependency and update the shipcode.yml build command; verify installation in a clean directory.
Snippets using Math, .shift(), or similar notation illustrate algorithm ideas; they do not require JavaScript. Adapt them to your language. A byte is not always a character: count bytes in binary formats and specify the encoding.
Output and errors
Multiline examples are formatted for readability. Emit compact JSON without optional spaces, with properties in the order shown by the output examples, and a final newline. Keep logs off stdout. Tests compare exact text.
Invalid inputs use stderr containing error, empty stdout, and exit 1. Valid inputs exit 0. Serialize integer results as JSON integers.