Skip to content
LexerLangv0.1.0

lexer serve

The one command that runs things, and its flags: --port, --watch, --background, --production.

Terminal
lexer serve <file> [--port N] [--watch] [--background]
                   [--production] [--log <file>]

Reads the file, parses it and runs it. There is no build and no runserve already does both.

Flags may come before or after the filename:

Terminal
lexer serve app.lexer --port 8080

The exit code is 0 on success and 1 on failure.

Flags#

FlagEffect
--port Nthe CLI port; overrides the port set inside the application
--watchrestarts the application whenever the file changes
--backgroundstarts a separate process and writes output to .logs/YYYYMMDD.log
--productionproduction mode; out.log becomes the default when --log is absent
--log <file>redirects output to a file; does not change the mode

--port and --production answer different questions: one is where to listen, the other is how much the error page says.

Development#

Terminal
lexer serve app.lexer --watch

Every time you save the file the server shuts down gracefully and comes back up. Refreshing the browser is enough.

--watch follows not only the entry file but the .lx files it imports; changing a file under lib/ restarts it too.

In the background#

Terminal
lexer serve app.lexer --background --port 8080

The process detaches from the terminal. out() output and [lexer]-prefixed diagnostics go to .logs/YYYYMMDD.log in the application directory.

Text
foreground  →  terminal
background  →  <application directory>/.logs/YYYYMMDD.log

The filename carries the date as YYYYMMDD rather than DDMMYY so that chronological order and filesystem order are the same thing.

Run mode#

Terminal
lexer serve app.lexer                       # development (default)
lexer serve app.lexer --production          # production
LEXER_ENV=production lexer serve app.lexer  # production

The CLI wins: when --production is given, the environment variable is not consulted.

The mode only changes the error page:

Text
development:  sayfa calistirilamadi: /path/app.lexer:25:19: tanimsiz degisken: $yok
production:   sayfa calistirilamadi (olay: 4b17df5d3b21)

The detail is written to the log file under the same id. You find the logged line from the code the user reports, and no file path or line number leaks to the browser.

Reading the mode from the language#

LexerLang
use modes

if mode == modes.development then
    out("development mode")
end if
NameWhat it isNeeds use
modethe value itselfno
modes.development · modes.productionconstantsyes
modes.currentthe same as modeyes
modes.is_production() · modes.is_development()shorthandyes

mode and modes are deliberately separate: one is a value, the other a set.

The application cannot change the mode. If it could, the answer to "which mode are we in" could change midway through a run.

Port#

The port can come from three places, in this order of precedence:

Terminal
lexer serve app.lexer --port 8080     # 1. CLI flag
LexerLang
$app.listen({port: 3000})             # 2. listen argument
$app = new http_server({port: 3000})  # 3. object setting

Next#

Process managementstatus, logs, stop.