Skip to content

Commit

Permalink
Rename doc heading
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhowes committed Jul 15, 2023
1 parent 579cecd commit 0a10abe
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Sources/MathParser/Documentation.docc/GettinStarted.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Overview
# Getting Started

Basic math expression parser built with Point•Free's swift-parsing package (v0.12.0).

Expand Down
23 changes: 13 additions & 10 deletions Sources/MathParser/MathParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final public class MathParser {
public typealias BinaryFunctionMap = (String) -> BinaryFunction?
/// Dictionary of binary function names and their implementations.
public typealias BinaryFunctionDict = [String: BinaryFunction]
/// Return value for the `parseResult` method.
/// Return value for the ``MathParser/parseResult(_:)`` method.
public typealias Result = Swift.Result<Evaluator, MathParserError>
/**
Default symbols to use for parsing.
Expand Down Expand Up @@ -152,16 +152,19 @@ final public class MathParser {
Parse an expression into a token that can be evaluated at a later time.
- parameter text: the expression to parse
- returns: optional Evaluator to use to obtain results from the parsed expression. This is nil if
the given expression is not valid.
- returns: optional ``Evaluator`` to use to obtain results from the parsed expression. This is nil if
the given expression to parse is not valid.
*/
public func parse(_ text: String) -> Evaluator? {
guard let token = try? expression.parse(text) else { return nil }
return Evaluator(token: token, usingImpliedMultiplication: enableImpliedMultiplication)
}

/**
Parse an expression into a token that can be evaluated at a later time. Returns a `Result` enum with two cases:
Parse an expression into a token that can be evaluated at a later time, and returns a `Result` value that conveys
information about the parsing result.
The `Result` enum has two cases:
- `.success` -- holds an ``Evaluator`` instance for evaluations of the parsed expression
- `.failure` -- holds a ``MathParserError`` instance that describes the parse failure
Expand All @@ -180,7 +183,7 @@ final public class MathParser {

// MARK: - implementation details

/// When true, two parsed operands in a row implies multiplication
// When true, two parsed operands in a row implies multiplication
private let enableImpliedMultiplication: Bool

// Any of these will terminate an identifier (as well as whitespace). NOTE: this must be kept up-to-date with any
Expand All @@ -198,7 +201,7 @@ final public class MathParser {
","
]

/**
/*
Parser for a numeric constant. NOTE: we disallow signed numbers here due to ambiguities that are introduced if
implied multiplication mode is enabled. We allow for negative values through the negation operation which demands
that the "-" appear just before the number without any spaces between them.
Expand All @@ -224,27 +227,27 @@ final public class MathParser {
End()
}
// NOTE: the chain of expression parsers from here to exponentiation causes a loop so we need to be Lazy here.
// NOTE: the chain of expression parsers from here to exponentiation causes a loop so we need to be "lazy" here.
private lazy var subexpression: some TokenParser = Lazy {
self.additionAndSubtraction
}
lazy var additionAndSubtraction = InfixOperation(
private lazy var additionAndSubtraction = InfixOperation(
name: "+|-",
associativity: .left,
operator: additionOrSubtractionOperator,
operand: multiplicationAndDivision
)
lazy var multiplicationAndDivision = InfixOperation(
private lazy var multiplicationAndDivision = InfixOperation(
name: "*|/",
associativity: .left,
operator: multiplicationOrDivisionOperator,
operand: exponentiation,
implied: enableImpliedMultiplication ? self.multiplicationReducer : nil
)
lazy var exponentiation = InfixOperation(
private lazy var exponentiation = InfixOperation(
name: "Pow",
associativity: .right,
operator: exponentiationOperator,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/documentation/mathparser.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/GettinStarted",
"kind" : "article",
"role" : "article",
"title" : "Overview",
"title" : "Getting Started",
"type" : "topic",
"url" : "\/documentation\/mathparser\/gettinstarted"
},
Expand Down
14 changes: 11 additions & 3 deletions docs/data/documentation/mathparser/gettinstarted.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"role" : "article",
"roleHeading" : "Article",
"title" : "Overview"
"title" : "Getting Started"
},
"primaryContentSections" : [
{
Expand Down Expand Up @@ -924,15 +924,23 @@
"doc://MathParser/documentation/MathParser/MathParser/parseResult(_:)": {
"abstract" : [
{
"text" : "Parse an expression into a token that can be evaluated at a later time. Returns a ",
"text" : "Parse an expression into a token that can be evaluated at a later time, and returns a ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " enum with two cases:",
"text" : " value that conveys",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "information about the parsing result.",
"type" : "text"
}
],
Expand Down
17 changes: 13 additions & 4 deletions docs/data/documentation/mathparser/mathparser.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@
"type" : "text"
},
{
"code" : "parseResult",
"type" : "codeVoice"
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/MathParser\/parseResult(_:)",
"isActive" : true,
"type" : "reference"
},
{
"text" : " method.",
Expand Down Expand Up @@ -1193,15 +1194,23 @@
"doc://MathParser/documentation/MathParser/MathParser/parseResult(_:)": {
"abstract" : [
{
"text" : "Parse an expression into a token that can be evaluated at a later time. Returns a ",
"text" : "Parse an expression into a token that can be evaluated at a later time, and returns a ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " enum with two cases:",
"text" : " value that conveys",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "information about the parsing result.",
"type" : "text"
}
],
Expand Down
13 changes: 11 additions & 2 deletions docs/data/documentation/mathparser/mathparser/parse(_:).json
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,24 @@
{
"inlineContent" : [
{
"text" : "optional Evaluator to use to obtain results from the parsed expression. This is nil if",
"text" : "optional ",
"type" : "text"
},
{
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/Evaluator",
"isActive" : true,
"type" : "reference"
},
{
"text" : " to use to obtain results from the parsed expression. This is nil if",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "the given expression is not valid.",
"text" : "the given expression to parse is not valid.",
"type" : "text"
}
],
Expand Down
46 changes: 40 additions & 6 deletions docs/data/documentation/mathparser/mathparser/parseresult(_:).json
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{
"abstract" : [
{
"text" : "Parse an expression into a token that can be evaluated at a later time. Returns a ",
"text" : "Parse an expression into a token that can be evaluated at a later time, and returns a ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " enum with two cases:",
"text" : " value that conveys",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "information about the parsing result.",
"type" : "text"
}
],
Expand Down Expand Up @@ -207,6 +215,23 @@
"text" : "Discussion",
"type" : "heading"
},
{
"inlineContent" : [
{
"text" : "The ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " enum has two cases:",
"type" : "text"
}
],
"type" : "paragraph"
},
{
"items" : [
{
Expand Down Expand Up @@ -408,8 +433,9 @@
"type" : "text"
},
{
"code" : "parseResult",
"type" : "codeVoice"
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/MathParser\/parseResult(_:)",
"isActive" : true,
"type" : "reference"
},
{
"text" : " method.",
Expand Down Expand Up @@ -446,15 +472,23 @@
"doc://MathParser/documentation/MathParser/MathParser/parseResult(_:)": {
"abstract" : [
{
"text" : "Parse an expression into a token that can be evaluated at a later time. Returns a ",
"text" : "Parse an expression into a token that can be evaluated at a later time, and returns a ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " enum with two cases:",
"text" : " value that conveys",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "information about the parsing result.",
"type" : "text"
}
],
Expand Down
81 changes: 77 additions & 4 deletions docs/data/documentation/mathparser/mathparser/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"type" : "text"
},
{
"code" : "parseResult",
"type" : "codeVoice"
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/MathParser\/parseResult(_:)",
"isActive" : true,
"type" : "reference"
},
{
"text" : " method.",
Expand Down Expand Up @@ -260,8 +261,9 @@
"type" : "text"
},
{
"code" : "parseResult",
"type" : "codeVoice"
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/MathParser\/parseResult(_:)",
"isActive" : true,
"type" : "reference"
},
{
"text" : " method.",
Expand Down Expand Up @@ -295,6 +297,77 @@
"type" : "topic",
"url" : "\/documentation\/mathparser\/mathparser\/result"
},
"doc://MathParser/documentation/MathParser/MathParser/parseResult(_:)": {
"abstract" : [
{
"text" : "Parse an expression into a token that can be evaluated at a later time, and returns a ",
"type" : "text"
},
{
"code" : "Result",
"type" : "codeVoice"
},
{
"text" : " value that conveys",
"type" : "text"
},
{
"text" : " ",
"type" : "text"
},
{
"text" : "information about the parsing result.",
"type" : "text"
}
],
"fragments" : [
{
"kind" : "keyword",
"text" : "func"
},
{
"kind" : "text",
"text" : " "
},
{
"kind" : "identifier",
"text" : "parseResult"
},
{
"kind" : "text",
"text" : "("
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:SS",
"text" : "String"
},
{
"kind" : "text",
"text" : ") -> "
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:10MathParserAAC",
"text" : "MathParser"
},
{
"kind" : "text",
"text" : "."
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:10MathParserAAC6Resulta",
"text" : "Result"
}
],
"identifier" : "doc:\/\/MathParser\/documentation\/MathParser\/MathParser\/parseResult(_:)",
"kind" : "symbol",
"role" : "symbol",
"title" : "parseResult(_:)",
"type" : "topic",
"url" : "\/documentation\/mathparser\/mathparser\/parseresult(_:)"
},
"doc://MathParser/documentation/MathParser/MathParserError": {
"abstract" : [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/index/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"path" : "\/documentation\/mathparser\/gettinstarted",
"title" : "Overview",
"title" : "Getting Started",
"type" : "article"
},
{
Expand Down

0 comments on commit 0a10abe

Please sign in to comment.