Skip to content

Commit

Permalink
Finish 0.0.1 : Scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasMostefaoui committed Mar 12, 2018
2 parents 5f9292f + 401d549 commit 094cadb
Show file tree
Hide file tree
Showing 19 changed files with 1,770 additions and 38 deletions.
70 changes: 70 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
disabled_rules: # rule identifiers to exclude from running
- function_parameter_count
- trailing_whitespace
- colon
opt_in_rules: # some rules are only opt-in
- empty_count
- force_unwrapping
- explicit_acl
- explicit_top_level_acl
- missing_docs
- comma
- control_statement
- fatal_error_message
- unneeded_break_in_switch
- unused_optional_binding
- array_init
- empty_parentheses_with_trailing_closure
- block_based_kvo
- class_delegate_protocol
- explicit_type_interface
- first_where
- for_where
- shorthand_operator
- no_extension_access_modifier
- syntactic_sugar
- weak_delegate

included: # paths to include during linting. `--path` is ignored if present.
- LoxInterpreter
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 120
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
identifier_name:
excluded:
- id
- on
- off
- ID
- URL
- GlobalAPIKey
min_length:
warning: 2
error: 1
max_length: 40
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
26 changes: 26 additions & 0 deletions LoxInterpreter/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Nyris. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
14 changes: 7 additions & 7 deletions LoxLanguage/LoxError.swift → LoxInterpreter/LoxError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import Foundation

struct LoxError : CustomStringConvertible {
var description: String {
public struct LoxError : CustomStringConvertible {
public var description: String {
return "\(self.fileName):\(self.lineNumber) => \(self.message) at \(self.location)"
}

let fileName:String
let lineNumber:Int
let message:String
let location:String

public let fileName:String
public let filePath:String
public let lineNumber:Int
public let message:String
public let location:String

}
19 changes: 19 additions & 0 deletions LoxInterpreter/LoxInterpreter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// LoxInterpreter.h
// LoxInterpreter
//
// Created by MOSTEFAOUI Anas on 04/03/2018.
// Copyright © 2018 Nyris. All rights reserved.
//

#import <Cocoa/Cocoa.h>

//! Project version number for LoxInterpreter.
FOUNDATION_EXPORT double LoxInterpreterVersionNumber;

//! Project version string for LoxInterpreter.
FOUNDATION_EXPORT const unsigned char LoxInterpreterVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <LoxInterpreter/PublicHeader.h>


Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

import Foundation

class LoxInterpreter {
public class LoxInterpreter {

var shouldExit:Bool = false
var hadError:Bool = false
private var shouldExit:Bool = false
private var hadError:Bool = false
public private(set) var scanner:ScannerInterface

func readFrom(filePath:String) {
public init(scanner:ScannerInterface) {
self.scanner = scanner
}

public func readFrom(filePath:String) {
guard filePath.isEmpty == false else {
fatalError("File path is empty")
}
Expand All @@ -26,7 +31,7 @@ class LoxInterpreter {
execute(code: fileContent)
}

func relp() {
public func relp() {
repeat {
print("> ")
guard let code = readLine(strippingNewline: true) else { continue }
Expand All @@ -35,17 +40,20 @@ class LoxInterpreter {
} while(shouldExit == false)
}

private func execute(code:String) {
private func execute(code:String) {
guard self.hadError == false else {
exit(2)
}
self.scanner.source = code
_ = self.scanner.scan()

}

func error(line:Int, message:String) {
private func error(line:Int, message:String) {

}

func reportError(error:LoxError) {
private func reportError(error:LoxError) {
print(error)
self.hadError = true
}
Expand Down
Loading

0 comments on commit 094cadb

Please sign in to comment.