Skip to content

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.

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.

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.