Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkowz committed Aug 1, 2015
1 parent 58a5874 commit fa3f881
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 36 deletions.
4 changes: 3 additions & 1 deletion Swifternalization/ExpressionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ or `RegexExpressionParser`.
Defines methods and properties that are needed to work as parser.
*/
protocol ExpressionParser {
/// pattern of expression
/**
Pattern of expression.
*/
var pattern: ExpressionPattern {get}

/**
Expand Down
16 changes: 12 additions & 4 deletions Swifternalization/ExpressionPatternType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@

import Foundation

/// Supported expression types
/**
Supported expression types.
*/
enum ExpressionPatternType: String {
/// works on Int only, e.g. `x<5`, `x=3`
/**
Works with Int/Float, e.g. `x<5`, `x=3`, `x<4.5`.
*/
case Inequality = "ie"

/// works on Int only, e.g. `4<x<10`, `1<=x<18`
/**
Works on Int/Float only, e.g. `4<x<10`, `1<=x<18`, `1.3<=x<15.4`.
*/
case InequalityExtended = "iex"

/// regular expression, e.g. `[02-9]+`
/**
Regular expression, e.g. `[02-9]+`.
*/
case Regex = "exp"
}
8 changes: 6 additions & 2 deletions Swifternalization/InequalityExpressionMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ Struct that is used to validate inequality expressions.
*/
struct InequalityExpressionMatcher: ExpressionMatcher {

/// `InequalitySign` of expression to be matched.
/**
`InequalitySign` of expression to be matched.
*/
let sign: InequalitySign

/// Value that will be used during validation to compare to passed one.
/**
A value that will be used during validation to compare to passed one.
*/
let value: Double

/**
Expand Down
6 changes: 4 additions & 2 deletions Swifternalization/InequalityExpressionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import Foundation
Parses inequality expression patterns. e.g. `ie:x=5`.
*/
class InequalityExpressionParser: ExpressionParser {
/// Pattern of expression.
/**
A pattern of expression.
*/
let pattern: ExpressionPattern

/**
Expand Down Expand Up @@ -46,7 +48,7 @@ class InequalityExpressionParser: ExpressionParser {
}

/**
Get value - Int.
Get value - Double.

:returns: value or nil if value cannot be found
*/
Expand Down
10 changes: 7 additions & 3 deletions Swifternalization/InequalityExtendedExpressionMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
import Foundation

/**
Validates inequality extended expressions
Validates inequality extended expressions.
*/
struct InequalityExtendedExpressionMatcher: ExpressionMatcher {

/// Matcher that validates left side of expressions
/**
Matcher that validates left side of expressions.
*/
let leftMatcher: InequalityExpressionMatcher

/// Matcher that validates right side of expressions
/**
Matcher that validates right side of expressions.
*/
let rightMatcher: InequalityExpressionMatcher

/**
Expand Down
28 changes: 22 additions & 6 deletions Swifternalization/InequalitySign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@ import Foundation
Defines inequality signs used by inquality and inequality extended expressions.
*/
enum InequalitySign: String {
/// Less than a value
/**
Less than a value.
*/
case LessThan = "<"
/// Less than or equal a value

/**
Less than or equal a value.
*/
case LessThanOrEqual = "<="
/// Equal a value

/**
Equal a value.
*/
case Equal = "="
/// Greater than or equal a value

/**
Greater than or equal a value.
*/
case GreaterThanOrEqual = ">="
/// Greater than a value

/**
Greater than a value.
*/
case GreaterThan = ">"

/// Inverts enum
/**
Inverts enum.
*/
func invert() -> InequalitySign {
switch self {
case .LessThan: return .GreaterThan
Expand Down
12 changes: 9 additions & 3 deletions Swifternalization/InternalPattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import Foundation
Represents internal patterns used by the framework to avoid copy-pastes.
*/
enum InternalPattern: String {
/// Pattern that matches expressions.
/**
Pattern that matches expressions.
*/
case Expression = "(?<=\\{)(.+)(?=\\})"

/// Pattern that matches expression types.
/**
Pattern that matches expression types.
*/
case ExpressionPatternType = "(^.{2,3})(?=:)"

/// Pattern that matches key without expression.
/**
Pattern that matches key without expression.
*/
case KeyWithoutExpression = "^(.*?)(?=\\{)"
}
8 changes: 6 additions & 2 deletions Swifternalization/RegexExpressionMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

import Foundation

/// Type that represents pattern with regular expression
/**
Type that represents pattern with regular expression.
*/
internal typealias RegexPattern = String

/**
Matcher is responsible for matching expressions that contains
regular expressions.
*/
struct RegexExpressionMatcher: ExpressionMatcher {
/// Expression pattern with regular expression inside.
/**
Expression pattern with regular expression inside.
*/
let pattern: RegexPattern

/**
Expand Down
4 changes: 3 additions & 1 deletion Swifternalization/RegexExpressionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import Foundation
Parser that parses expressions that contains regular expressions.
*/
class RegexExpressionParser: ExpressionParser {
/// Expression pattern - regular expression.
/**
Expression pattern - regular expression.
*/
let pattern: ExpressionPattern

/**
Expand Down
24 changes: 18 additions & 6 deletions Swifternalization/Shared Expressions/SharedBaseExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,35 @@
// Copyright (c) 2015 Tomasz Szulc. All rights reserved.
//

/// Contains base expressions that matches every country.
/**
Contains base expressions that matches every country.
*/
class SharedBaseExpression: SharedExpressionProtocol {

/// Return expressions that matches every country.
/**
Return expressions that matches every country.
*/
static func allExpressions() -> [SharedExpression] {
return [

/// Matches value equals 1.
/**
Matches value equals 1.
*/
SharedExpression(identifier: "one", pattern: "ie:x=1"),

/// Matches value greater than 1.
/**
Matches value greater than 1.
*/
SharedExpression(identifier: ">one", pattern: "ie:x>1"),

/// Matches value equals 2.
/**
Matches value equals 2.
*/
SharedExpression(identifier: "two", pattern: "ie:x=2"),

/// Matches value other than 1.
/**
Matches value other than 1.
*/
SharedExpression(identifier: "other", pattern: "exp:(^[^1])|(^\\d{2,})")
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
// Copyright (c) 2015 Tomasz Szulc. All rights reserved.
//

/// Contains Polish expressions.
/**
Contains Polish expressions.
*/
class SharedPolishExpression: SharedExpressionProtocol {

/// Return expressions that are valid in Poland.
/**
Return expressions that are valid in Poland.
*/
static func allExpressions() -> [SharedExpression] {
return [
/**
Expand Down
16 changes: 12 additions & 4 deletions Swifternalization/SharedExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@ localizing app.
Rules: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
*/
protocol SharedExpressionProtocol {
/// Method returns all expressions for class that conform this protocol
/**
Method returns all expressions for class that conform this protocol
*/
static func allExpressions() -> [SharedExpression]
}

/**
Represents built-in expression and expressions from Expressions.strings file.
*/
struct SharedExpression {
/// Identifier of expression.
/**
Identifier of expression.
*/
let identifier: String

/// Pattern of expression.
/**
Pattern of expression.
*/
let pattern: String

/// Creates expression.
/**
Creates expression.
*/
init(identifier: String, pattern: String) {
self.identifier = identifier
self.pattern = pattern
Expand Down

0 comments on commit fa3f881

Please sign in to comment.