Generalized errors and moved them to src/meta/errors.nim. Further work in the compiler

This commit is contained in:
Nocturn9x 2021-10-23 11:48:29 +02:00
parent 7237141ec1
commit 8070803d05
4 changed files with 26 additions and 7 deletions

View File

@ -16,16 +16,25 @@ import meta/errors
import strformat
export ast
type
IdentifierKind = enum
Static, Dynamic
LoopContext = enum
Loop, None
IdentifierWrapper = ref object
kind: IdentifierKind
node: ASTNode
isPrivate: bool
Local = ref object
name: ASTNode
depth: int
Compiler* = ref object
ast: seq[ASTNode]
current: int
@ -33,9 +42,11 @@ type
# Keeps track of all identifiers
# in the code
names: seq[IdentifierWrapper]
locals: seq[Local]
localCount: int
currentLoop: LoopContext
scopeDepth: int
CompileError* = object of NimVMException
proc initCompiler*(): Compiler =
## Initializes a new Compiler object

View File

@ -18,9 +18,13 @@ import strutils
import parseutils
import strformat
import tables
import meta/token
import meta/errors
export token # Makes Token available when importing the lexer module
export errors
# Tables of all character tokens that are not keywords
@ -95,7 +99,6 @@ type
start: int
current: int
file: string
LexingError* = object of CatchableError
proc initLexer*(self: Lexer = nil): Lexer =

View File

@ -12,4 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
type NimVMException* = ref object of CatchableError
type
NimVMException* = object of CatchableError
LexingError* = object of NimVMException
ParseError* = object of NimVMException
CompileError* = object of NimVMException

View File

@ -19,8 +19,10 @@ import strformat
import meta/token
import meta/ast
import meta/errors
export token, ast
export token, ast, errors
type
@ -33,8 +35,6 @@ type
file: string
tokens: seq[Token]
context: ParseContext
ParseError* = object of CatchableError
## A parse error
proc initParser*(): Parser =