it.grypho.scala.leonardo.cli

Members list

Type members

Classlikes

object AsciiMath

Reads MathLive's AsciiMath into Leonardo's own grammar, or refuses (issue F_0017 slice 2).

Reads MathLive's AsciiMath into Leonardo's own grammar, or refuses (issue F_0017 slice 2).

Why AsciiMath and not LaTeX. A `` holds LaTeX, and reading that would mean writing a parser for a typesetting language, where \frac{d}{dx} is layout rather than meaning and f(x) is ambiguous between application and multiplication. But the vendored MathLive build already exports convertLatexToAsciiMath, and AsciiMath's arithmetic core IS this grammar: a LaTeX fraction arrives as (a+b)/(c+d), x^{2} as x^2, 2 x as 2x, \theta as theta. What remains is a bounded rewrite table, which is this file.

It refuses on its own authority, and that is the load-bearing half. The grammar has no unknown-identifier error: an unrecognised name is a _Variable and juxtaposition is multiplication, so sqrt(x) handed to Parser.parse yields the product of a free variable named sqrt with x — an answer to a different question rather than a complaint. Nothing here may pass text through in the hope that the parser will object. The whitelist is Parser.ReservedWords, the same surface F_0030's REPL diagnostic uses, so the browser reader and the prompt cannot disagree about what counts as a function.

What is not converted is refused by name. The calculus binders (int, d/dx, lim) convert since F_0033 and the reductions (sum, prod, choose) since F_0037; what remains refused -- oint, the transform braces, and the shape-less spelling of each structured form (a lim without its (x->a), a sum without its range, an int without its differential) -- is refused with the grammar's own spelling, never pattern-matched out of an undocumented intermediate form.

It lives in repl rather than in web because it concerns the input language, not the browser: it emits grammar text and validates names exactly as Session does, so the two rules stay neighbours, and a terminal user pasting AsciiMath gets the same treatment.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
AsciiMath.type
object ColorScheme

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class ColorScheme(command: AttributedStyle, function: AttributedStyle, constant: AttributedStyle, number: AttributedStyle, operator: AttributedStyle, equation: AttributedStyle, paren: AttributedStyle, variable: AttributedStyle)

Colour mapping for one syntactic role in the Leonardo prompt.

Colour mapping for one syntactic role in the Leonardo prompt.

Each field is an AttributedStyle applied to a matching token class during highlighting. Plain sets every field to AttributedStyle.DEFAULT, disabling all colouring.

Value parameters

command

REPL command keywords (simplify, derive, colors, ...)

constant

named constants (pi, e, i) and the truth literals (true, false, unknown)

equation

bare = (equation relation)

function

mathematical function names (sin, cos, exp, ...)

number

numeric literals

operator

arithmetic operators, :=, and the word connectives (and, or, not, implies, xor, iff)

paren

parentheses and square brackets

variable

user identifiers and everything else

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class LeonardoHighlighter(schemeName: () => String) extends Highlighter

JLine Highlighter that token-colours the Leonardo prompt as the user types.

JLine Highlighter that token-colours the Leonardo prompt as the user types.

A single left-to-right scan classifies each character run as one of: := / :load / :save (operators / pseudo-commands), numeric literals, word tokens (command keyword, function, constant, or variable), and single-character operators and brackets. The active scheme is fetched via schemeName on every keystroke, so colors dark / colors light / colors none takes effect immediately.

reader is never used; call highlightBuffer directly in tests and tooling.

Attributes

Supertypes
trait Highlighter
class Object
trait Matchable
class Any
object Session

Companion object: constants and IO helpers shared across the REPL entry point.

Companion object: constants and IO helpers shared across the REPL entry point.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Session.type
final class Session

Interactive command-line session over the Leonardo library.

Interactive command-line session over the Leonardo library.

Session state lives outside the library's Environment because the two kinds of assignment differ: a constant right-hand side becomes a numeric binding (a _Value the Environment can hold), while a right-hand side with free variables becomes a named definition (a symbolic _Expression, which the Environment deliberately cannot hold). Definitions are late-bound: they are substituted into input at use time, so redefining f also changes any g defined in terms of f.

Assignment uses := (CAS convention): bare = always parses as an _Equation, so x = 2*x + 1 is a relation to evaluate, never a binding. Session scripts (:save) emit := and old =-style scripts are not accepted.

Commands:

x := 3.001           bind a value (constant right-hand side)
f := sin(x) + x      define a function (right-hand side with free variables)
h := lhs = rhs       bind a named equation (can be passed to solve(h, x))
g := consolidate(e)  freeze the simplified+evaluated result of e into g (not late-bound)
lhs = rhs            equation: true/false when concrete; solvable via solve()
lhs == rhs           equality check: evaluates to bool but not solvable
         evaluate, e.g.  f + 1  or  derive(f, x)
simplify       structural simplification, no numeric evaluation
expand         distribute products over sums
precision         set decimal precision
exact on | off       exact rational arithmetic (default: off); see "help exact"
exact precision   digits an irrational is approximated to (default: 30, max 1000)
pretty on | off      multi-line, column-aligned matrix display (default: off)
latex on | off       also emit each result as LaTeX, for a front end that can
                     typeset it (default: off); see [[Session.lastLatex]]
logic symmetric on|off  spell truth values as -1 / 0 / 1 (default: off)
logic minmax|product|lukasiewicz   fuzzy t-norm family (default: minmax)
env                  list precision, bindings, and definitions
unset          remove a binding or definition
:load          run a session script (file IO handled by the read loop)
:save          write current state to a replayable script (read loop)
help                 this summary
quit | exit          leave (handled by the read loop)

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object ShareEncoding

The URL-fragment format a session travels in, shared by every producer of one (issue F_0045).

The URL-fragment format a session travels in, shared by every producer of one (issue F_0045).

It lives here, in the module that owns Session.script, because two components need the same answer and neither can reach the other. web.ShareLink builds the fragment in the browser; docs.Lesson builds one on the JVM to put a "run this" link beside an executed lesson transcript. web is a Scala.js project and the documentation helper is a JVM one, so the only place both can import from is the cross-built repl module — and a second hand-maintained encoder is exactly the drift ColorSchemeNamesTest exists to prevent elsewhere.

encodeComponent is encodeURIComponent, re-implemented rather than delegated, and that is the substance of this object. The browser has the function as a global and the JDK does not: java.net.URLEncoder.encode is not the same thing — it is application/x-www-form-urlencoded, which emits + for a space, and decodeURIComponent returns that + as a literal plus sign. A script encoded that way reloads as a valid but different session, every space in it silently corrupted, which is the confidently-wrong failure this project declines everywhere.

So the unreserved set is spelled out and everything else is percent-encoded from its UTF-8 bytes. UTF-8 is hand-rolled from code points rather than taken from String.getBytes(UTF_8): this file compiles for both platforms, and a charset's breadth of support is precisely the kind of difference that compiles everywhere and diverges at run time — the DoubleRender lesson. Hex digits are upper case, as the browser's own function emits them, so a fragment built here is byte-identical to one built by the page.

Decoding is not here. decodeURIComponent is only ever needed in the browser, where it exists and is the authority; re-implementing it would add a second thing to keep in step for no caller. ShareLinkTest checks the two agree by decoding this encoder's output with the real one.

Published API since F_0236 (it was private[leonardo]): the course repository builds its run links through the released leonardo-repl, and a copy of the format there would be a second definition to drift. Public, MiMa now protects it. The contract a caller relies on: a fragment is Key followed by encodeURIComponent of a Session.script, hex in upper case, and a session longer than MaxFragment encoded characters yields no link at all (a Left), never a truncated one. Append it to an /app/ URL after #.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
final class repl

Attributes

Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

def repl(): Unit

Entry point for the interactive Leonardo REPL.

Entry point for the interactive Leonardo REPL.

Attributes