summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-json-parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/compiler-core/slang-json-parser.h')
-rw-r--r--source/compiler-core/slang-json-parser.h48
1 files changed, 35 insertions, 13 deletions
diff --git a/source/compiler-core/slang-json-parser.h b/source/compiler-core/slang-json-parser.h
index 2e907abb2..96531aee9 100644
--- a/source/compiler-core/slang-json-parser.h
+++ b/source/compiler-core/slang-json-parser.h
@@ -11,18 +11,32 @@ class JSONListener
{
public:
/// Start an object
- virtual void startObject() = 0;
+ virtual void startObject(SourceLoc loc) = 0;
/// End an object
- virtual void endObject() = 0;
+ virtual void endObject(SourceLoc loc) = 0;
/// Start an array
- virtual void startArray() = 0;
+ virtual void startArray(SourceLoc loc) = 0;
/// End and array
- virtual void endArray() = 0;
+ virtual void endArray(SourceLoc loc) = 0;
- /// Add the key lexeme. Must be followed by addLexemeValue.
- virtual void addLexemeKey(const UnownedStringSlice& key) = 0;
+
+ /// Add the key. Must be followed by addXXXValue.
+ virtual void addKey(const UnownedStringSlice& key, SourceLoc loc) = 0;
/// Can be performed in an array or after an addLexemeKey in an object
- virtual void addLexemeValue(JSONTokenType type, const UnownedStringSlice& value) = 0;
+ virtual void addLexemeValue(JSONTokenType type, const UnownedStringSlice& value, SourceLoc loc) = 0;
+
+ /// An integer value
+ virtual void addIntegerValue(int64_t value, SourceLoc loc) = 0;
+ /// Add a floating point value
+ virtual void addFloatValue(double value, SourceLoc loc) = 0;
+ /// Add a boolean value
+ virtual void addBoolValue(bool value, SourceLoc loc) = 0;
+
+ /// Add a string value. NOTE! string is unescaped/quoted
+ virtual void addStringValue(const UnownedStringSlice& string, SourceLoc loc) = 0;
+
+ /// Add a null value
+ virtual void addNullValue(SourceLoc loc) = 0;
};
class JSONWriter : public JSONListener
@@ -75,12 +89,17 @@ public:
static bool isAfter(Location loc) { return isObjectLike(loc) && (Index(loc) & 2) != 0; }
// Implement JSONListener
- virtual void startObject() SLANG_OVERRIDE;
- virtual void endObject() SLANG_OVERRIDE;
- virtual void startArray() SLANG_OVERRIDE;
- virtual void endArray() SLANG_OVERRIDE;
- virtual void addLexemeKey(const UnownedStringSlice& key) SLANG_OVERRIDE;
- virtual void addLexemeValue(JSONTokenType type, const UnownedStringSlice& value) SLANG_OVERRIDE;
+ virtual void startObject(SourceLoc loc) SLANG_OVERRIDE;
+ virtual void endObject(SourceLoc loc) SLANG_OVERRIDE;
+ virtual void startArray(SourceLoc loc) SLANG_OVERRIDE;
+ virtual void endArray(SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addKey(const UnownedStringSlice& key, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addLexemeValue(JSONTokenType type, const UnownedStringSlice& value, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addIntegerValue(int64_t value, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addFloatValue(double value, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addBoolValue(bool value, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addStringValue(const UnownedStringSlice& string, SourceLoc loc) SLANG_OVERRIDE;
+ virtual void addNullValue(SourceLoc loc) SLANG_OVERRIDE;
/// Get the builder
StringBuilder& getBuilder() { return m_builder; }
@@ -142,6 +161,9 @@ protected:
void _maybeEmitComma();
void _maybeEmitFieldComma();
+ void _preValue(SourceLoc loc);
+ void _postValue();
+
void _indent() { m_currentIndent++; }
void _dedent() { --m_currentIndent; SLANG_ASSERT(m_currentIndent >= 0); }