gavr123456789 / Niva

Smalltalk like programming language
https://gavr123456789.github.io/niva-site
41 stars 2 forks source link

Parser bug with Dots leaded by keyword msg #286

Closed gavr123456789 closed 1 month ago

gavr123456789 commented 2 months ago
type Lexer
  input: String
  pos: Int
  readPos: Int
  ch: Char

constructor Lexer input::String = [
  l = Lexer input: input pos: 0 readPos: 0 ch: 'ъ'
  l readChar 
  ^l 
] 

Lexer readChar = [
  readPos >= input count => 
    ch <- '\u0000' |=>  
    ch <- input at: readPos

  pos <- readPos
  readPos <- readPos inc
]

Lexer readIdentifier -> String = [
  localPos = pos
  ch isLetter => .readChar
  ^input slice: localPos..<pos
]

Lexer nextToken -> Token = [
  tok = | ch 
  | '=' => Token kind: TokenType.ASSIGN
  | ';' => Token kind: TokenType.SEMICOLON
  | '(' => Token kind: TokenType.LPAREN
  | ')' => Token kind: TokenType.RPAREN
  | ',' => Token kind: TokenType.COMMA
  | '+' => Token kind: TokenType.PLUS
  | '{' => Token kind: TokenType.LBRACE
  | '}' => Token kind: TokenType.RBRACE
  |=> [
    // Token kind: TokenType.EOF
    ch isLetter || (ch == '_') => [
      lit = .readIdentifier // THIS LINE PRODUCES ERROR
      Token lit: (.readIdentifier) kind: (Token lookupIdent: "")
    ] |=> [
      Token kind: TokenType.ILLEGAL
    ]
  ]

  .readChar
  ^ tok
]