interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / osh / osh_parse_ref.h

45 lines · 2001 bytes Raw Blame History
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_parse_ref.h -- a tiny independent C reference parser for osh R1, used ONLY for differential testing of the
19 * OSC parser (osh_parse.osc). Written from the grammar (osh_parse.osc.in header, design E-parser-design.md section 3)
20 * as a recursive-descent parser over the reference tokenizer's tokens, not from the .osc state machine. Not a shell.
21 */
22#ifndef OSH_PARSE_REF_H
23#define OSH_PARSE_REF_H
24#include <stddef.h>
25#include <stdint.h>
26
27#include "osh_lex_ref.h"
28
29#define OSH_PREF_CMDS 32
30#define OSH_PREF_PIPES 16
31
32typedef struct {
33 unsigned status; /* 0 list complete, 100 need more input, else a refusal code (203..208, 231..242, 248) */
34 uint64_t err_off; /* byte offset of a refusal */
35 unsigned ncmd, npipe;
36 uint64_t cmd[OSH_PREF_CMDS][8]; /* {first token, end token, nassign, nword, nredir, pipeline, position, 0} */
37 uint64_t pipe[OSH_PREF_PIPES][4]; /* {first command, ncmds, connector_after, first token} */
38 unsigned next_tok; /* status 0: index of the first token the list did not consume */
39} OshRefParse;
40
41/* Parse the first list of the token stream lx (which must have status 0, a complete lexer run over in[0..n)). eoi
42 * is the same flag the lexer was run with. */
43void osh_parse_ref(const uint8_t *in, size_t n, const OshRefLex *lx, int eoi, OshRefParse *out);
44
45#endif /* OSH_PARSE_REF_H */