Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jk/preserve unparsable input #227

Merged
merged 8 commits into from
Mar 6, 2020
Merged

Conversation

voodoo11
Copy link
Collaborator

Context

Introduces new vertex type ParsingErrorVertex which stores original user input. FormulaCellVertex is not constructed if parsing error occures.

engine.setCellContents(adr('A1'), '=SUM(')
expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.ERROR, 'Parsing error'))
expect(engine.getCellFormula(adr('A1'))).toEqual('=SUM(')

Instead of returning ErrorType.NAME, parsing errors are represented as ErrorType.ERROR which corresponds to generic #ERROR!.

How has this been tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

  1. It's not possible to edit an invalid formula #182

Checklist:

  • My code follows the code style of this project,
  • My change requires a change to the documentation,
  • I described the modification in the CHANGELOG.md file.

test/parser/parser.spec.ts Outdated Show resolved Hide resolved
test/parser/decimal.spec.ts Outdated Show resolved Hide resolved
const vertex = buildMatrixVertex(parseResult.ast as ProcedureAst, address)
dependencies.set(vertex, absolutizeDependencies(parseResult.dependencies, address))
this.dependencyGraph.addMatrixVertex(address, vertex)
if (parseResult.errors.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of such checks, couldn't we make this.parser.parse(...) return some object representing the result of parsing? Something like if (parseResult.isCorrectlyParsed()) would be nicer

@@ -941,7 +943,13 @@ export class HyperFormula {
if (!(parsedCellContent instanceof CellContent.Formula)) {
return [false, exampleTemporaryFormulaAddress]
}
const {ast} = this.parser.parse(parsedCellContent.formula, exampleTemporaryFormulaAddress)

const { ast, errors } = this.parser.parse(parsedCellContent.formula, exampleTemporaryFormulaAddress)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -60,6 +63,10 @@ import {
WhiteSpace,
} from './LexerConfig'

export interface FormulaParserResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a lot simpler if we would have two different result classes? One having ONLY ast and one having ONLY errors? Because now we have to do all these ErrorAst sheningans just to have the Ast, but we don't need Ast anymore, as we don't store unparsable formulas in FormulaVertex (which needed an Ast), but in ParserErrorVertex instead. Do I think correctly?

}
const {ast, hasVolatileFunction, hasStructuralChangeFunction, relativeDependencies} = cacheResult

return {ast, hasVolatileFunction, hasStructuralChangeFunction, dependencies: relativeDependencies}
return {ast, errors: [], hasVolatileFunction, hasStructuralChangeFunction, dependencies: relativeDependencies}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for having separate field for that

voodoo11 and others added 2 commits March 2, 2020 08:32
Co-Authored-By: Wojciech Czerniak <wojciech.czerniak@gmail.com>
@voodoo11 voodoo11 merged commit e61c21d into develop Mar 6, 2020
@wojciechczerniak wojciechczerniak deleted the jk/preserve-unparsable-input branch September 15, 2021 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants