Commit 0f92901d authored by Cool Fire's avatar Cool Fire
Browse files

Move lexer functions into own class and created skeleton functions for lexer

parent 2ab4392f
......@@ -2,28 +2,49 @@
# Encoding: utf-8
# frozen_string_literal: true
require_relative 'LexerFunctions.rb'
# Main class for the PHP lexer
class Lexer
class Lexer < LexerFunctions
require_relative 'LexerConstants.rb'
attr_accessor :input
# Kickstart the lexer
def start
lex method :lex_text
end
# Main lexer function loop
def lex(state)
state = state.call until state.nil?
end
def lex_text
puts 'lex_text'
method :lex_number
# Send lex token to parser queue
def emit(type)
# Put input[start..pos] into queue
end
# Get next char
def nxt
# Move pos right by one and return the char
end
# Ignore character
def ignore
# start = pos
end
# Take a step back
def backup
# pos -= 1
end
def lex_number
puts 'lex_number'
nil
# Look at the next char without consuming it
def peek
c = nxt
backup
c
end
end
......
#!/usr/bin/env ruby
# Encoding: utf-8
# frozen_string_literal: true
# Class that contains all of the language lexing functions
class LexerFunctions
def lex_text
puts 'lex_text'
method :lex_number
end
def lex_number
puts 'lex_number'
nil
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment