bro/engine/lexer

Types

Lexer = object
  input*: string
  pos*, line*, col*: int
  current*: char
  strbuf*: string
TokenKind = enum
  tkUnknown, tkEOF, tkIdentifier, tkCssVar, tkInt, tkFloat, tkString,
  tkSemicolon = ";", tkColon = ":", tkComma = ",", tkDot = ".", tkHash = "#",
  tkLParen = "(", tkRParen = ")", tkLBrace = "{", tkRBrace = "}",
  tkLBracket = "[", tkRBracket = "]", tkPlus = "+", tkMinus = "-",
  tkAsterisk = "*", tkDivide = "/", tkPercent = "%", tkEqual = "=",
  tkDoubleEqual = "==", tkNotEqual = "!=", tkLT = "<", tkLTE = "<=", tkGT = ">",
  tkGTE = ">=", tkAmp = "&", tkAndAnd = "&&", tkOrOr = "||", tkOr = "or",
  tkKeywordIs = "is", tkKeywordIsnot = "isnot", tkAnd = "and",
  tkKeywordNot = "not", tkBacktick = "`", tkAt = "@", tkAssign = "=",
  tkPlusAssign = "+=", tkMinusAssign = "-=", tkAsteriskAssign = "*=",
  tkSlashAssign = "/=", tkPercentAssign = "%=", tkBang = "!", tkTilde = "~",
  tkTildeAssign = "~=", tkCaret = "^", tkCaretAssign = "^=",
  tkPipeAssign = "|=", tkDollarAssign = "$=", tkKeywordVar = "var",
  tkKeywordLet = "let", tkKeywordConst = "const",
  tkKeywordFunction = "function", tkKeywordReturn = "return",
  tkKeywordIf = "if", tkKeywordElse = "else", tkKeywordElif = "elif",
  tkKeywordWhile = "while", tkKeywordFor = "for", tkKeywordIn = "in",
  tkKeywordOf = "of", tkKeywordCase = "case", tkKeywordBreak = "break",
  tkKeywordContinue = "continue", tkKeywordEcho = "echo",
  tkKeywordTrue = "true", tkKeywordFalse = "false", tkKeywordNull = "null",
  tkKeywordUndefined = "undefined", tkKeywordImport = "import",
  tkKeywordIterator = "iterator", tkKeywordMixin = "mixin", tkComment,
  tkDocBlock, tkDocBlockBang
TokenTuple = tuple[kind: TokenKind, value: string, line: int, col: int,
                   pos: int, wsno: int]

Procs

proc getToken(lex: var Lexer): TokenTuple {....raises: [], tags: [], forbids: [].}
Returns the next token from the input
proc initToken(lex: var Lexer; kind: static TokenKind): TokenTuple
proc initToken(lex: var Lexer; kind: static TokenKind; line, col, pos, wsno: int): TokenTuple
proc initToken(lex: var Lexer; value: sink string; kind: TokenKind;
               line, col, pos, wsno: int): TokenTuple {....raises: [], tags: [],
    forbids: [].}
proc newLexer(input: string): Lexer {....raises: [], tags: [], forbids: [].}
proc peek(lex: Lexer; offset = 1): char {....raises: [], tags: [], forbids: [].}
proc peekToken(lex: Lexer; expectToken: string): bool {....raises: [], tags: [],
    forbids: [].}
proc skipWhitespace(lex: var Lexer) {....raises: [], tags: [], forbids: [].}