omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / osh / osh_lex_ref.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * osh_lex_ref.h -- a tiny independent C reference tokenizer for osh R1, used ONLY for differential |
| 19 | * testing of the OSC lexer (osh_lex.osc). Written from the token rules (ABI draft section 5 and 7, design |
| 20 | * E-parser-design.md section 2), not from the .osc. Not a shell, not for production. |
| 21 | */ |
| 22 | #ifndef OSH_LEX_REF_H |
| 23 | #define OSH_LEX_REF_H |
| 24 | #include <stddef.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | #define OSH_REF_TOKEN_CAP 128 |
| 28 | #define OSH_REF_LINE_CAP 4096 |
| 29 | |
| 30 | typedef struct { |
| 31 | uint64_t kind, flags, nseg, line, start, len, aux; |
| 32 | } OshRefTok; |
| 33 | |
| 34 | typedef struct { |
| 35 | OshRefTok tok[OSH_REF_TOKEN_CAP]; |
| 36 | unsigned ntok; |
| 37 | unsigned status; /* 0 line complete, 100 incomplete, else a refusal code (201, 202, 220..232, 236, 246..250) */ |
| 38 | uint64_t err_off; /* byte offset of a refusal */ |
| 39 | } OshRefLex; |
| 40 | |
| 41 | /* Tokenize the whole buffer in one pass. Same observable result as running the OSC lexer to completion |
| 42 | * over the same bytes, however they were split into calls. eoi = the host set the end-of-input flag: a pending |
| 43 | * word or operator is finished, a final lone backslash is a literal byte (bash), and an open quote or `${` is |
| 44 | * SYNTAX_EOF (248) at offset n. */ |
| 45 | void osh_lex_ref(const uint8_t *in, size_t n, int eoi, OshRefLex *out); |
| 46 | |
| 47 | |
| 48 | #endif /* OSH_LEX_REF_H */ |