just

Types

pub type ContextualKeyword {
  As
  Async
  Await
  From
  Get
  ContextualLet
  Of
  Set
  ContextualStatic
  ContextualYield
}

Constructors

  • As
  • Async
  • Await
  • From
  • Get
  • ContextualLet
  • Of
  • Set
  • ContextualStatic
  • ContextualYield
pub type Error {
  UnknownCharacter(character: String)
  UnterminatedStringLiteral
  UnterminatedMultilineComment
  UnterminatedRegExpLiteral
  UnterminatedTemplateLiteral
  LetterAfterNumber
  NumericSeparatorNotAllowed
  ExpectedExponent
  InvalidPrivateIdentifier(identifier: String)
  ZeroPrefixedNumberInStrictMode
}

Constructors

  • UnknownCharacter(character: String)
  • UnterminatedStringLiteral
  • UnterminatedMultilineComment
  • UnterminatedRegExpLiteral
  • UnterminatedTemplateLiteral
  • LetterAfterNumber
  • NumericSeparatorNotAllowed
  • ExpectedExponent
  • InvalidPrivateIdentifier(identifier: String)
  • ZeroPrefixedNumberInStrictMode

A highlighting token, containing information about the kind of syntax being used. Many similar tokens (e.g. all keywords) are grouped together to simplify them.

For syntax tokens, see Token.

pub type HighlightToken {
  HighlightWhitespace(String)
  HighlightKeyword(String)
  HighlightVariable(String)
  HighlightClass(String)
  HighlightString(String)
  HighlightRegexp(String)
  HighlightNumber(String)
  HighlightFunction(String)
  HighlightOperator(String)
  HighlightComment(String)
  HighlightPunctuation(String)
  HighlightOther(String)
}

Constructors

  • HighlightWhitespace(String)
  • HighlightKeyword(String)
  • HighlightVariable(String)
  • HighlightClass(String)
  • HighlightString(String)
  • HighlightRegexp(String)
  • HighlightNumber(String)
  • HighlightFunction(String)
  • HighlightOperator(String)
  • HighlightComment(String)
  • HighlightPunctuation(String)
  • HighlightOther(String)
pub opaque type Lexer
pub type Token {
  SingleLineComment(String)
  MultiLineComment(String)
  HashBangComment(String)
  Whitespace(String)
  LineTerminator(String)
  EndOfFile
  Identifier(String)
  PrivateIdentifier(String)
  Number(String)
  BigInt(String)
  String(quote: String, contents: String)
  RegularExpression(contents: String, flags: String)
  TemplateHead(String)
  TemplateMiddle(String)
  TemplateTail(String)
  Break
  Case
  Catch
  Class
  Const
  Continue
  Debugger
  Default
  Delete
  Do
  Else
  Export
  Extends
  False
  Finally
  For
  Function
  If
  Import
  In
  Instanceof
  New
  Null
  Return
  Super
  Switch
  This
  Throw
  True
  Try
  Typeof
  Var
  Void
  While
  With
  Let
  Static
  Yield
  Enum
  Implements
  Interface
  Package
  Private
  Protected
  ContextualKeyword(ContextualKeyword)
  LeftBrace
  RightBrace
  LeftParen
  RightParen
  LeftSquare
  RightSquare
  Dot
  TripleDot
  Semicolon
  Comma
  Colon
  Arrow
  Less
  Greater
  LessEqual
  GreaterEqual
  DoubleEqual
  BangEqual
  TripleEqual
  BangDoubleEqual
  Plus
  Minus
  Star
  Slash
  Percent
  DoubleStar
  DoublePlus
  DoubleMinus
  DoubleLess
  DoubleGreater
  TripleGreater
  Ampersand
  Pipe
  Caret
  Tilde
  Bang
  DoubleAmpersand
  DoublePipe
  Question
  DoubleQuestion
  QuestionDot
  Equal
  PlusEqual
  MinusEqual
  StarEqual
  SlashEqual
  PercentEqual
  DoubleStarEqual
  DoubleLessEqual
  DoubleGreaterEqual
  TripleGreaterEqual
  AmpersandEqual
  PipeEqual
  CaratEqual
  DoubleAmpersandEqual
  DoublePipeEqual
  DoubleQuestionEqual
  Unknown(String)
  UnterminatedString(quote: String, contents: String)
  UnterminatedTemplate(String)
  UnterminatedRegularExpression(String)
  UnterminatedComment(String)
}

Constructors

  • SingleLineComment(String)
  • MultiLineComment(String)
  • HashBangComment(String)
  • Whitespace(String)
  • LineTerminator(String)
  • EndOfFile
  • Identifier(String)
  • PrivateIdentifier(String)
  • Number(String)
  • BigInt(String)
  • String(quote: String, contents: String)
  • RegularExpression(contents: String, flags: String)
  • TemplateHead(String)
  • TemplateMiddle(String)
  • TemplateTail(String)
  • Break
  • Case
  • Catch
  • Class
  • Const
  • Continue
  • Debugger
  • Default
  • Delete
  • Do
  • Else
  • Export
  • Extends
  • False
  • Finally
  • For
  • Function
  • If
  • Import
  • In
  • Instanceof
  • New
  • Null
  • Return
  • Super
  • Switch
  • This
  • Throw
  • True
  • Try
  • Typeof
  • Var
  • Void
  • While
  • With
  • Let
  • Static
  • Yield
  • Enum
  • Implements
  • Interface
  • Package
  • Private
  • Protected
  • ContextualKeyword(ContextualKeyword)
  • LeftBrace
  • RightBrace
  • LeftParen
  • RightParen
  • LeftSquare
  • RightSquare
  • Dot
  • TripleDot
  • Semicolon
  • Comma
  • Colon
  • Arrow
  • Less
  • Greater
  • LessEqual
  • GreaterEqual
  • DoubleEqual
  • BangEqual
  • TripleEqual
  • BangDoubleEqual
  • Plus
  • Minus
  • Star
  • Slash
  • Percent
  • DoubleStar
  • DoublePlus
  • DoubleMinus
  • DoubleLess
  • DoubleGreater
  • TripleGreater
  • Ampersand
  • Pipe
  • Caret
  • Tilde
  • Bang
  • DoubleAmpersand
  • DoublePipe
  • Question
  • DoubleQuestion
  • QuestionDot
  • Equal
  • PlusEqual
  • MinusEqual
  • StarEqual
  • SlashEqual
  • PercentEqual
  • DoubleStarEqual
  • DoubleLessEqual
  • DoubleGreaterEqual
  • TripleGreaterEqual
  • AmpersandEqual
  • PipeEqual
  • CaratEqual
  • DoubleAmpersandEqual
  • DoublePipeEqual
  • DoubleQuestionEqual
  • Unknown(String)
  • UnterminatedString(quote: String, contents: String)
  • UnterminatedTemplate(String)
  • UnterminatedRegularExpression(String)
  • UnterminatedComment(String)

Values

pub fn contextual_keyword_name(
  keyword: ContextualKeyword,
) -> String
pub fn highlight_ansi(code: String) -> String

Convert a string of JavaScript source code into ansi highlighting.

Colours taken from contour:

TokenColour
KeywordYellow
ClassCyan
FunctionBlue
OperatorMagenta
CommentItalic grey
String, Number, RegexpGreen
Whitespace, VariableNo colour

If you wish to use other colours or another format, use to_tokens.

pub fn highlight_html(code: String) -> String

Convert a string of JavaScript source code into an HTML string. Each token is wrapped in a <span> with a class indicating the type of

Class names taken from contour:

TokenCSS class
Keywordhl-keyword
Variablehl-variable
Classhl-class
Functionhl-function
Operatorhl-operator
Punctuationhl-punctuation
Commenthl-comment
Stringhl-string
Regexphl-regexp
Numberhl-number
Whitespaceno class

Place the output within a <pre><code>...</code></pre> and add styling for these CSS classes to get highlighting on your website. Here’s some CSS you could use:

pre code .hl-comment  { color: #d4d4d4; font-style: italic }
pre code .hl-function { color: #9ce7ff }
pre code .hl-keyword  { color: #ffd596 }
pre code .hl-operator { color: #ffaff3 }
pre code .hl-string   { color: #c8ffa7 }
pre code .hl-number   { color: #c8ffa7 }
pre code .hl-regexp   { color: #c8ffa7 }
pre code .hl-class    { color: #ffddfa }

If you wish to use another format see to_ansi or to_tokens.

pub fn highlight_tokens(code: String) -> List(HighlightToken)

Convert a string of JavaScript source code into highlighting tokens. Highlighting tokens only contain information about the kind of syntax being used, grouping similar tokens (e.g. all keywords) into one category.

To convert code into syntax tokens, see tokenise.

pub fn ignore_comments(lexer: Lexer) -> Lexer
pub fn ignore_whitespace(lexer: Lexer) -> Lexer
pub fn new(source: String) -> Lexer
pub fn strict_mode(lexer: Lexer) -> Lexer
pub fn stringify_error(error: Error) -> String
pub fn to_source(tokens: List(Token)) -> String
pub fn token_to_source(token: Token) -> String
pub fn tokenise(lexer: Lexer) -> #(List(Token), List(Error))
Search Document