mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Add header sequences for zcg cpp
This commit is contained in:
parent
f14357537e
commit
40fedc905d
@ -0,0 +1,66 @@
|
||||
#include "HeaderCommonMatchers.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HeaderMatcherFactory.h"
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::Align(const supplier_t* labelSupplier)
|
||||
{
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Type(HeaderParserValueType::DECLSPEC),
|
||||
create.Char('('),
|
||||
create.Type(HeaderParserValueType::ALIGN),
|
||||
create.Char('('),
|
||||
create.Integer(),
|
||||
create.Char(')'),
|
||||
create.Char(')')
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return HeaderParserValue::Integer(values[4].get().GetPos(), values[4].get().IntegerValue());
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::ArrayDef(const supplier_t* labelSupplier)
|
||||
{
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Char('['),
|
||||
create.Or({
|
||||
create.Integer(),
|
||||
create.Identifier()
|
||||
}),
|
||||
create.Char(']')
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
if(values[1].get().m_type == HeaderParserValueType::INTEGER)
|
||||
return HeaderParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue());
|
||||
|
||||
return HeaderParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue()));
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::Typename(const supplier_t* labelSupplier)
|
||||
{
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Identifier(),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Char(':'),
|
||||
create.Char(':'),
|
||||
create.Identifier()
|
||||
}))
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << values[0].get().IdentifierValue();
|
||||
|
||||
for (auto i = 3u; i < values.size(); i += 3)
|
||||
str << "::" << values[i].get().IdentifierValue();
|
||||
|
||||
return HeaderParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
}).Build();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
#include "Parsing/Matcher/MatcherLabel.h"
|
||||
|
||||
class HeaderCommonMatchers
|
||||
{
|
||||
public:
|
||||
typedef AbstractMatcher<HeaderParserValue> matcher_t;
|
||||
typedef IMatcherForLabelSupplier<HeaderParserValue> supplier_t;
|
||||
|
||||
static constexpr int LABEL_ALIGN = std::numeric_limits<int>::max() - 1;
|
||||
static constexpr int LABEL_ARRAY_DEF = std::numeric_limits<int>::max() - 2;
|
||||
static constexpr int LABEL_TYPENAME = std::numeric_limits<int>::max() - 3;
|
||||
|
||||
static std::unique_ptr<matcher_t> Align(const supplier_t* labelSupplier);
|
||||
static std::unique_ptr<matcher_t> ArrayDef(const supplier_t* labelSupplier);
|
||||
static std::unique_ptr<matcher_t> Typename(const supplier_t* labelSupplier);
|
||||
};
|
@ -18,6 +18,16 @@ MatcherFactoryWrapper<HeaderParserValue> HeaderMatcherFactory::Identifier() cons
|
||||
return MatcherFactoryWrapper<HeaderParserValue>(std::make_unique<HeaderMatcherValueType>(HeaderParserValueType::IDENTIFIER));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<HeaderParserValue> HeaderMatcherFactory::Integer() const
|
||||
{
|
||||
return MatcherFactoryWrapper<HeaderParserValue>(std::make_unique<HeaderMatcherValueType>(HeaderParserValueType::INTEGER));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<HeaderParserValue> HeaderMatcherFactory::FloatingPoint() const
|
||||
{
|
||||
return MatcherFactoryWrapper<HeaderParserValue>(std::make_unique<HeaderMatcherValueType>(HeaderParserValueType::FLOATING_POINT));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<HeaderParserValue> HeaderMatcherFactory::Char(char c) const
|
||||
{
|
||||
return MatcherFactoryWrapper<HeaderParserValue>(std::make_unique<HeaderMatcherCharacter>(c));
|
||||
|
@ -10,5 +10,7 @@ public:
|
||||
|
||||
_NODISCARD MatcherFactoryWrapper<HeaderParserValue> Type(HeaderParserValueType type) const;
|
||||
_NODISCARD MatcherFactoryWrapper<HeaderParserValue> Identifier() const;
|
||||
_NODISCARD MatcherFactoryWrapper<HeaderParserValue> Integer() const;
|
||||
_NODISCARD MatcherFactoryWrapper<HeaderParserValue> FloatingPoint() const;
|
||||
_NODISCARD MatcherFactoryWrapper<HeaderParserValue> Char(char c) const;
|
||||
};
|
||||
|
@ -0,0 +1,21 @@
|
||||
#include "SequenceCloseBlock.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceCloseBlock::SequenceCloseBlock()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Char('}'),
|
||||
create.Optional(create.And({
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Char(';').Tag(TAG_SEMICOLON)
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceCloseBlock::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceCloseBlock final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_SEMICOLON = 1;
|
||||
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceCloseBlock();
|
||||
};
|
@ -0,0 +1,25 @@
|
||||
#include "SequenceEnum.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceEnum::SequenceEnum()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Optional(create.Type(HeaderParserValueType::TYPEDEF).Tag(TAG_TYPEDEF)),
|
||||
create.Type(HeaderParserValueType::ENUM),
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Optional(create.And({
|
||||
create.Char(':'),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_PARENT_TYPE)
|
||||
})),
|
||||
create.Char('{')
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceEnum::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceEnum final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_TYPEDEF = 1;
|
||||
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
static constexpr auto CAPTURE_PARENT_TYPE = 2;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceEnum();
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
#include "SequenceEnumMember.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceEnumMember::SequenceEnumMember()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.Optional(create.And({
|
||||
create.Char('='),
|
||||
create.Or({
|
||||
create.Identifier().Capture(CAPTURE_VALUE),
|
||||
create.Integer().Capture(CAPTURE_VALUE)
|
||||
})
|
||||
})),
|
||||
create.Or({
|
||||
create.Char(','),
|
||||
create.Char('}').NoConsume()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceEnumMember::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceEnumMember final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
static constexpr auto CAPTURE_VALUE = 2;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceEnumMember();
|
||||
};
|
@ -0,0 +1,23 @@
|
||||
#include "SequenceForwardDecl.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceForwardDecl::SequenceForwardDecl()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Or({
|
||||
create.Type(HeaderParserValueType::ENUM),
|
||||
create.Type(HeaderParserValueType::STRUCT),
|
||||
create.Type(HeaderParserValueType::UNION)
|
||||
}),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.Char(';')
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceForwardDecl::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceForwardDecl final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_ENUM = 1;
|
||||
static constexpr auto TAG_STRUCT = 2;
|
||||
static constexpr auto TAG_UNION = 3;
|
||||
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceForwardDecl();
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
#include "SequenceStruct.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceStruct::SequenceStruct()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Align(this), HeaderCommonMatchers::LABEL_ALIGN);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Optional(create.Type(HeaderParserValueType::TYPEDEF).Tag(TAG_TYPEDEF)),
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST)),
|
||||
create.Type(HeaderParserValueType::STRUCT),
|
||||
create.Optional(create.Label(HeaderCommonMatchers::LABEL_ALIGN).Capture(CAPTURE_ALIGN)),
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Optional(create.And({
|
||||
create.Char(':'),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_PARENT_TYPE)
|
||||
})),
|
||||
create.Char('{')
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceStruct::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceStruct final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr int TAG_TYPEDEF = 1;
|
||||
|
||||
static constexpr int CAPTURE_NAME = 1;
|
||||
static constexpr int CAPTURE_ALIGN = 2;
|
||||
static constexpr int CAPTURE_PARENT_TYPE = 3;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceStruct();
|
||||
};
|
@ -0,0 +1,48 @@
|
||||
#include "SequenceTypedef.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceTypedef::SequenceTypedef()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Align(this), HeaderCommonMatchers::LABEL_ALIGN);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::ArrayDef(this), HeaderCommonMatchers::LABEL_ARRAY_DEF);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
|
||||
AddLabeledMatchers(
|
||||
{
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST).Tag(TAG_CONST)),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.OptionalLoop(create.Char('*').Tag(TAG_POINTER)),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.OptionalLoop(create.Label(HeaderCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY)),
|
||||
create.Char(';')
|
||||
}, LABEL_ARRAY_OF_POINTERS);
|
||||
|
||||
AddLabeledMatchers(
|
||||
{
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST).Tag(TAG_CONST)),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char('('),
|
||||
create.Loop(create.Char('*').Tag(TAG_POINTER)),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.Char(')'),
|
||||
create.Loop(create.Label(HeaderCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY)),
|
||||
create.Char(';')
|
||||
}, LABEL_POINTER_TO_ARRAY);
|
||||
|
||||
AddMatchers({
|
||||
create.Type(HeaderParserValueType::TYPEDEF),
|
||||
create.Optional(create.Label(HeaderCommonMatchers::LABEL_ALIGN).Capture(CAPTURE_ALIGN)),
|
||||
create.Or({
|
||||
create.Label(LABEL_ARRAY_OF_POINTERS).Tag(TAG_ARRAY_OF_POINTERS),
|
||||
create.Label(LABEL_POINTER_TO_ARRAY).Tag(TAG_POINTER_TO_ARRAY)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceTypedef::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceTypedef final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_ARRAY_OF_POINTERS = 1;
|
||||
static constexpr auto TAG_POINTER_TO_ARRAY = 2;
|
||||
static constexpr auto TAG_CONST = 3;
|
||||
static constexpr auto TAG_POINTER = 4;
|
||||
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
static constexpr auto CAPTURE_ALIGN = 2;
|
||||
static constexpr auto CAPTURE_TYPE = 3;
|
||||
static constexpr auto CAPTURE_ARRAY = 4;
|
||||
|
||||
static constexpr auto LABEL_ARRAY_OF_POINTERS = 1;
|
||||
static constexpr auto LABEL_POINTER_TO_ARRAY = 2;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceTypedef();
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
#include "SequenceUnion.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceUnion::SequenceUnion()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Align(this), HeaderCommonMatchers::LABEL_ALIGN);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Optional(create.Type(HeaderParserValueType::TYPEDEF).Tag(TAG_TYPEDEF)),
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST)),
|
||||
create.Type(HeaderParserValueType::UNION),
|
||||
create.Optional(create.Label(HeaderCommonMatchers::LABEL_ALIGN).Capture(CAPTURE_ALIGN)),
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Optional(create.And({
|
||||
create.Char(':'),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_PARENT_TYPE)
|
||||
})),
|
||||
create.Char('{')
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceUnion::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceUnion final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr int TAG_TYPEDEF = 1;
|
||||
|
||||
static constexpr int CAPTURE_NAME = 1;
|
||||
static constexpr int CAPTURE_ALIGN = 2;
|
||||
static constexpr int CAPTURE_PARENT_TYPE = 3;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceUnion();
|
||||
};
|
@ -0,0 +1,48 @@
|
||||
#include "SequenceVariable.h"
|
||||
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
|
||||
SequenceVariable::SequenceVariable()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Align(this), HeaderCommonMatchers::LABEL_ALIGN);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::ArrayDef(this), HeaderCommonMatchers::LABEL_ARRAY_DEF);
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
|
||||
AddLabeledMatchers(
|
||||
{
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST).Tag(TAG_CONST)),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.OptionalLoop(create.Char('*').Tag(TAG_POINTER)),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.OptionalLoop(create.Label(HeaderCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY)),
|
||||
create.Optional(create.And({
|
||||
create.Char(':'),
|
||||
create.Integer().Capture(CAPTURE_BIT_SIZE)
|
||||
})),
|
||||
create.Char(';')
|
||||
}, LABEL_ARRAY_OF_POINTERS);
|
||||
|
||||
AddLabeledMatchers(
|
||||
{
|
||||
create.Optional(create.Type(HeaderParserValueType::CONST).Tag(TAG_CONST)),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char('('),
|
||||
create.Loop(create.Char('*').Tag(TAG_POINTER)),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.Char(')'),
|
||||
create.Loop(create.Label(HeaderCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY)),
|
||||
create.Char(';')
|
||||
}, LABEL_POINTER_TO_ARRAY);
|
||||
|
||||
AddMatchers(create.Or({
|
||||
create.Label(LABEL_ARRAY_OF_POINTERS),
|
||||
create.Label(LABEL_POINTER_TO_ARRAY)
|
||||
}));
|
||||
}
|
||||
|
||||
void SequenceVariable::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
{
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
|
||||
class SequenceVariable final : public HeaderParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_ARRAY_OF_POINTERS = 1;
|
||||
static constexpr auto TAG_POINTER_TO_ARRAY = 2;
|
||||
static constexpr auto TAG_CONST = 3;
|
||||
static constexpr auto TAG_POINTER = 4;
|
||||
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
static constexpr auto CAPTURE_ALIGN = 2;
|
||||
static constexpr auto CAPTURE_TYPE = 3;
|
||||
static constexpr auto CAPTURE_ARRAY = 4;
|
||||
static constexpr auto CAPTURE_BIT_SIZE = 5;
|
||||
|
||||
static constexpr auto LABEL_ARRAY_OF_POINTERS = 1;
|
||||
static constexpr auto LABEL_POINTER_TO_ARRAY = 2;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceVariable();
|
||||
};
|
@ -30,12 +30,24 @@ protected:
|
||||
|
||||
virtual void ProcessMatch(ParserState* state, SequenceResult<TokenType>& result) const = 0;
|
||||
|
||||
void AddMatchers(std::unique_ptr<matcher_t> matcher)
|
||||
{
|
||||
assert(!m_entry);
|
||||
m_entry = std::move(matcher);
|
||||
}
|
||||
|
||||
void AddMatchers(std::initializer_list<Movable<std::unique_ptr<matcher_t>>> matchers)
|
||||
{
|
||||
assert(!m_entry);
|
||||
m_entry = std::make_unique<MatcherAnd<TokenType>>(matchers);
|
||||
}
|
||||
|
||||
void AddLabeledMatchers(std::unique_ptr<matcher_t> matcher, const int label)
|
||||
{
|
||||
assert(m_matchers.find(label) == m_matchers.end());
|
||||
m_matchers.emplace(label, std::move(matcher));
|
||||
}
|
||||
|
||||
void AddLabeledMatchers(std::initializer_list<Movable<std::unique_ptr<matcher_t>>> matchers, const int label)
|
||||
{
|
||||
assert(m_matchers.find(label) == m_matchers.end());
|
||||
|
Loading…
x
Reference in New Issue
Block a user