Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExpressionParser.h « GCodeBuffer « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c70393a3dc491638640b7b58d235288bd40debc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * ExpressionParser.h
 *
 *  Created on: 6 Mar 2020
 *      Author: David
 */

#ifndef SRC_GCODES_GCODEBUFFER_EXPRESSIONPARSER_H_
#define SRC_GCODES_GCODEBUFFER_EXPRESSIONPARSER_H_

#include <RepRapFirmware.h>
#include <General/StringBuffer.h>
#include <ObjectModel/ObjectModel.h>
#include <GCodes/GCodeException.h>

class ExpressionParser
{
public:
	ExpressionParser(const GCodeBuffer& p_gb, const char *text, const char *textLimit, int p_column = -1) noexcept;

	ExpressionValue Parse(bool evaluate = true) THROWS(GCodeException);
	bool ParseBoolean() THROWS(GCodeException);
	float ParseFloat() THROWS(GCodeException);
	int32_t ParseInteger() THROWS(GCodeException);
	uint32_t ParseUnsigned() THROWS(GCodeException);

	void SkipWhiteSpace() noexcept;
	void CheckForExtraCharacters() THROWS(GCodeException);
	const char *GetEndptr() const noexcept { return currentp; }

private:
	GCodeException ConstructParseException(const char *str) const noexcept;
	GCodeException ConstructParseException(const char *str, const char *param) const noexcept;
	GCodeException ConstructParseException(const char *str, uint32_t param) const noexcept;

	ExpressionValue ParseInternal(bool evaluate = true, uint8_t priority = 0) THROWS(GCodeException);
	ExpressionValue ParseExpectKet(bool evaluate, char expectedKet) THROWS(GCodeException);
	ExpressionValue ParseNumber() noexcept
		pre(readPointer >= 0; isdigit(gb.buffer[readPointer]));
	ExpressionValue ParseIdentifierExpression(bool evaluate, bool applyLengthOperator) THROWS(GCodeException)
		pre(readPointer >= 0; isalpha(gb.buffer[readPointer]));
	void ParseQuotedString(const StringRef& str) THROWS(GCodeException);

	void ConvertToFloat(ExpressionValue& val, bool evaluate) const THROWS(GCodeException);
	void ConvertToBool(ExpressionValue& val, bool evaluate) const THROWS(GCodeException);
	void ConvertToString(ExpressionValue& val, bool evaluate) THROWS(GCodeException);

	void BalanceNumericTypes(ExpressionValue& val1, ExpressionValue& val2, bool evaluate) const THROWS(GCodeException);
	void BalanceTypes(ExpressionValue& val1, ExpressionValue& val2, bool evaluate) THROWS(GCodeException);
	void EnsureNumeric(ExpressionValue& val, bool evaluate) const THROWS(GCodeException);
	static bool TypeHasNoLiterals(TypeCode t) noexcept;

	const char *GetAndFix() THROWS(GCodeException);
	int GetColumn() const noexcept;
	char CurrentCharacter() const noexcept;
	void AdvancePointer() noexcept { ++currentp; }		// could check that we havebn't reached endp but we should stop before that happens

	const char *currentp;
	const char * const startp;
	const char * const endp;
	const GCodeBuffer& gb;
	int column;
	char stringBufferStorage[StringBufferLength];
	StringBuffer stringBuffer;
	String<MaxVariableNameLength> obsoleteField;
};

#endif /* SRC_GCODES_GCODEBUFFER_EXPRESSIONPARSER_H_ */