Octave dialect
User files are MATLAB-strict unless a file or the session opts into the Octave dialect. Shipped library files keep their current permissive parse until the library is converted to base MATLAB syntax. This is the same lexer Nexus already uses for its own scripts. It is not a copy of Octave.
Canonical heading spelling (design #2402): %#dialect: octave. Session switch: nexus-cli --dialect octave or dialect("octave").
One file
Put the heading on the first content line of the file. A UTF-8 BOM, blank lines, and one Unix shebang (#!...) before it are ignored. Copyright or help comments must come after the heading. Only that file is affected. Functions it calls keep their own file heading or the session dialect.
%#dialect: octave
function r = demo ()
if ! (1 != 0)
x = 0;
endif
x++;
x += 1;
r = x;
endfunction
#dialect: octave is the same marker. The word dialect and the value octave are case-insensitive. Anything after octave on that line, other than spaces, means the line is not a marker. Design record: docs/adr/2402-per-file-language-heading.md.
A whole session
Start Nexus with nexus-cli --dialect octave, or call dialect("octave") after startup. dialect() with no arguments returns "matlab" or "octave". dialect("matlab") puts the session back. The command-line name is the same pair, and anything else is a usage error.
The session switch covers user files and text passed to eval or --eval. It does not change how shipped library files are parsed. A session set to octave parses every user file as octave. A per-file %#dialect: octave opts one file in while the session stays matlab. Design #2402 also reserves %#dialect: matlab as an explicit base marker (useful on shipped files after library conversion); absence of a heading already means base MATLAB for user files.
What changes
Nexus uses a hybrid policy (evaluation #2403, closed): spellings that valid MATLAB never accepts can be dual-accepted later without changing MATLAB programs. Constructs that are the same text with different meaning need the dialect heading or session switch. The per-construct class-B decisions (double quotes, display, broadcasting warnings, and the rest) are recorded under semantics #2405 in AI_Docs/octave/CLASS_B_SEMANTICS_2405.md. Statement-start bang-shell is shared MATLAB/Octave behaviour (#12913), not a class-B split.
!as logical not is dual-accepted in expression position (same meaning as~).!=stays dialect-gated in MATLAB-strict user files. Statement-start shell escape (!cmd) runs viasystem(#12913); use~or parenthesize for NOT at statement start.- Octave
**/.**are synonyms for^/.^(#12894). Under%#dialect: octave, the session dialect, or command-line /evaltext, they parse and evaluate like power. In a MATLAB-strict unmarked user file they are refused the same way as!=(MATLAB portable code keeps^/.^only). - Postfix
++/--and compound assignment (+=and the rest of that family) parse as they do in the shipped library. Prefix++x/--xmutate only under the dialect heading or session (nexus#12895); in MATLAB-strict text they stay two unary signs, matching MATLAB. Without the dialect, a MATLAB-strict user file keepsMATLAB:m_incomplete_statementfor a bare postfix increment, andMATLAB:UndefinedFunctionfor compound assignment. endif,endfor,endwhile,endfunction, and the other end-family keywords are accepted. They are also accepted in MATLAB-strict user files, because the lexer already accepted them. A MATLAB file can keep using plainend.#starts a comment, in both dialects. MATLAB-strict user files already accepted it.- A double-quoted literal is a char row, and backslash escapes are applied when the file is parsed.
"\n"is a newline. In a MATLAB-strict user file the same quotes are a 1-by-1 string and a backslash is a backslash. That meaning clash is why double quotes stay under the dialect heading. printf(template, ...)writes to standard output the wayfprintfdoes, with the first argument as the template.puts(s)writessand a newline and returns 0.fputs(fid, s)writesswith no extra newline and returns 0. In a MATLAB-strict caller these raiseMATLAB:UndefinedFunctionwith MATLAB's missing-function message. They are still built-in names, soexist("printf","builtin")is 5 in either dialect. A MATLAB script that never calls them is unchanged.test(name)runs%!blocks innamethrough__test__. It is allowed when the session is octave, when the caller was parsed as octave, or whennameis a file whose header is the dialect marker. Otherwise it raisesMATLAB:UndefinedFunction. Shipped code keeps calling__test__directly.
Diagnostics for unmarked Octave syntax
If a MATLAB-strict user file (no heading, session left on matlab) uses a still-gated Octave-only construct such as !=, **, prefix ++, or a still-gated (){} index chain, Nexus names the construct, names the line when known, states that it is Octave-language syntax, and suggests adding %#dialect: octave at the top of the file. Dual-accepted class-A spellings (unary !, long-form endif, postfix ++, chained a(1)(2)) do not emit that diagnostic. Details: issue #2407 and AI_Docs/octave/DIAGNOSTICS_2407.md.
Note for toolbox authors
Default every new toolbox .m to MATLAB syntax with no dialect heading. That matches the product base language and keeps user copies of shipped files working under MATLAB-strict parse.
- Mark a file
%#dialect: octaveonly when it truly needs Octave-only surface syntax (for example double-quoted char escapes, or dialect builtins such asprintfused as Octave does). - Shipped Nexus scripts under the install prefix (and
NEXUS_SOURCE_SCRIPTS/ toolbox roots) still use the legacy permissive path rule until that exception is removed. A useraddpathof a copy outside those roots is a user file: without a heading it is MATLAB-strict. - Do not paste GNU Octave GPL sources into Camlogic toolboxes. Prefer clean-room MATLAB-syntax implementations, or call documented Nexus library helpers. See the clean-room notes under
AI_Docs/and issue #1369. - Optional add-on layout and install paths are on the Toolboxes page.
Other languages
Octave is the first non-base language mode. Python work (#1620–#1622, language front ends under #2410 / #2412) is the next language track, not a substitute for this dialect. The same %#dialect: <language> heading shape is intended for later languages; Python may also use a .py extension when that front end lands.
pkg Depends
Forge packages often declare Depends: octave (>= X.Y). Nexus pkg treats octave the same as Depends: nexus: both are checked against the running interpreter version(). Missing third-party package dependencies still fail. Use help pkg for the full package manager surface.
Limits
Anything Octave-specific that the library lexer does not already accept is out of scope until the matching parser or library child lands. A .p file does not store the header: after pcode, the file follows the session dialect only. Help text skips a leading dialect header, so help does not show that line as the doc string. Blocks executed by test are evaluated as text. With the session left on matlab, double quotes inside a block are strings.
Related
- Epic: Octave language support (#2401); status on this branch
AI_Docs/octave/EPIC_2401_PROGRESS.md, ADRdocs/adr/2401-octave-language-support.md - Design: per-file language heading (#2402); ADR
docs/adr/2402-per-file-language-heading.md(accepted onoctave-support) - User dialect header / session switch (#1106)
- Dual-accept evaluation (#2403, closed): hybrid recommendation in
docs/octave-dual-accept-analysis.md - Diagnostics for unmarked Octave constructs (#2407):
AI_Docs/octave/DIAGNOSTICS_2407.md