KiCad PCB EDA Suite
Loading...
Searching...
No Matches
cadstar_parts_lib_parser.cpp File Reference
#include <iostream>
#include "cadstar_parts_lib_parser.h"
#include "cadstar_parts_lib_grammar.h"
#include <fmt.h>
#include <set>
#include <string>

Go to the source code of this file.

Classes

struct  CADSTAR_LIB_PARSER_STATE
 Struture that will be populated by the PEGTL parser. More...
 
struct  CADSTAR_LIB_PARSER_ACTION< Rule >
 
struct  CADSTAR_LIB_PARSER_ACTION< EQUIVALENT_PIN >
 
struct  CADSTAR_LIB_PARSER_ACTION< STR_SEGMENT_EXCLUDING< EXCLUSION_RULES... > >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIERARCHY_NODE_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIERARCHY_CURRENT_NODE >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIERARCHY_PARENT_NODE >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIERARCHY_NODE_NAME >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIERARCHY_PART_NAME >
 
struct  CADSTAR_LIB_PARSER_ACTION< PART_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< READONLY >
 
struct  CADSTAR_LIB_PARSER_ACTION< PINNAME_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< PINLABEL_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< USER_PART_ATTRIBUTE >
 
struct  CADSTAR_LIB_PARSER_ACTION< SYMBOL_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< PIN_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< HIDDEN_PIN_ENTRY >
 
struct  CADSTAR_LIB_PARSER_ACTION< PIN_POSITION >
 
struct  CADSTAR_LIB_PARSER_ACTION< PIN_TYPE >
 

Macros

#define DEFINE_CONTENT_TO_NUMBER_ACTION(Rule, StateVariable)
 
#define DEFINE_CONTENT_TO_STRING_ACTION(Rule)
 
#define DEFINE_STRING_ACTION(Rule, StateVariable)
 
#define DECLARE_SINGLE_MATCH_RULE(Rule, ExtraCode)
 
#define DEFINE_PIN_GROUP_ACTION(Rule, StateVariable)
 
#define DEFINE_SWAP_GROUP_ACTION(Rule, StateVariable)
 
#define DEFINE_ATTRIBUTE_ACTION(Rule, StateVariable)
 

Functions

long helperStringToLong (std::string aString)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (CURRENT_FORMAT_NUMBER, m_ParsedModel.m_FormatNumber)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (PINNUM, m_CurrentLong)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (MAX_PIN_COUNT, m_CurrentPart.m_MaxPinCount)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (PIN_IDENTIFIER, m_CurrentPin.m_Identifier)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (PIN_LOADING, m_CurrentPin.m_Loading)
 
 DEFINE_CONTENT_TO_NUMBER_ACTION (HIERARCHY_NODE_INDEX, m_CurrentLong)
 
 DEFINE_CONTENT_TO_STRING_ACTION (PINNAME)
 
 DEFINE_STRING_ACTION (PART_NAME, m_CurrentPart.m_Name)
 
 DEFINE_STRING_ACTION (PART_VERSION, m_CurrentPart.m_Version)
 
 DEFINE_STRING_ACTION (PART_NUMBER, m_CurrentPart.m_Number)
 
 DEFINE_STRING_ACTION (PART_DESCRIPTION, m_CurrentPart.m_Description)
 
 DEFINE_STRING_ACTION (PCB_COMPONENT, m_CurrentPart.m_Pcb_component)
 
 DEFINE_STRING_ACTION (PCB_ALTERNATE, m_CurrentPart.m_Pcb_alternate)
 
 DEFINE_STRING_ACTION (VALUE, m_CurrentPart.m_Value)
 
 DEFINE_STRING_ACTION (DEFINITION_NAME, m_CurrentPart.m_PartDefinitionName)
 
 DEFINE_STRING_ACTION (STEM, m_CurrentPart.m_ComponentStem)
 
 DEFINE_STRING_ACTION (SYM_ELEMENT_NAME, m_CurrentSwapGroup.m_Name)
 
 DEFINE_STRING_ACTION (USER_PART_ATTRIBUTE_NAME, m_CurrentAttrName)
 
 DEFINE_STRING_ACTION (ATTRIBUTE_NAME, m_CurrentAttrName)
 
 DEFINE_STRING_ACTION (PIN_SIGNAL_NAME, m_CurrentSignalName)
 
 DEFINE_STRING_ACTION (ACCEPTANCE_PART_NAME, m_CurrentPart.m_AcceptancePartName)
 
 DEFINE_STRING_ACTION (ACCEPTANCE_TEXT, m_CurrentPart.m_AcceptanceText)
 
 DEFINE_STRING_ACTION (SPICE_PART_NAME, m_CurrentPart.m_SpicePartName)
 
 DEFINE_STRING_ACTION (SPICE_MODEL, m_CurrentPart.m_SpiceModel)
 
 DEFINE_STRING_ACTION (SCH_NAME, m_CurrentSymbol.m_SymbolName)
 
 DEFINE_STRING_ACTION (SCH_ALTERNATE, m_CurrentSymbol.m_SymbolAlternateName)
 
 DECLARE_SINGLE_MATCH_RULE (PART_VALUE,)
 
 DECLARE_SINGLE_MATCH_RULE (DFN_LINE,)
 
 DECLARE_SINGLE_MATCH_RULE (NGS_LINE, s.m_CurrentPart.m_GateSwappingAllowed=false)
 
 DECLARE_SINGLE_MATCH_RULE (NPV_LINE, s.m_CurrentPart.m_PinsVisible=false)
 
 DECLARE_SINGLE_MATCH_RULE (STM_LINE,)
 
 DECLARE_SINGLE_MATCH_RULE (MXP_LINE,)
 
 DECLARE_SINGLE_MATCH_RULE (SPI_LINE,)
 
 DECLARE_SINGLE_MATCH_RULE (PAC_LINE,)
 
 DEFINE_PIN_GROUP_ACTION (EQUIVALENT_PINS_GROUP, m_CurrentPart.m_PinEquivalences)
 
 DEFINE_PIN_GROUP_ACTION (INTERNAL_SWAP_GATE, m_CurrentSwapGroup.m_Gates)
 
 DEFINE_PIN_GROUP_ACTION (EXTERNAL_SWAP_GATE, m_CurrentSwapGroup.m_Gates)
 
 DEFINE_SWAP_GROUP_ACTION (INTERNAL_SWAP_GROUP, m_CurrentPart.m_InternalSwapGroup)
 
 DEFINE_SWAP_GROUP_ACTION (EXTERNAL_SWAP_GROUP, m_CurrentPart.m_ExternalSwapGroup)
 
 DEFINE_ATTRIBUTE_ACTION (SCM_ATTRIBUTE, m_CurrentPart.m_SchAttributes)
 
 DEFINE_ATTRIBUTE_ACTION (PCB_ATTRIBUTE, m_CurrentPart.m_PcbAttributes)
 
 DEFINE_ATTRIBUTE_ACTION (PART_ATTRIBUTE, m_CurrentPart.m_PartAttributes)
 
 DEFINE_ATTRIBUTE_ACTION (SCH_PCB_ATTRIBUTE, m_CurrentPart.m_SchAndPcbAttributes)
 
template<typename INPUT_TYPE >
bool checkHeaderHelper (INPUT_TYPE &aInput)
 
template<typename INPUT_TYPE >
CADSTAR_PARTS_LIB_MODEL readCadstarHelper (INPUT_TYPE &aInput)
 

Macro Definition Documentation

◆ DECLARE_SINGLE_MATCH_RULE

#define DECLARE_SINGLE_MATCH_RULE (   Rule,
  ExtraCode 
)
Value:
template <> \
{ \
template <typename ActionInput> \
static void apply( const ActionInput& in, CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( s.m_CurrentString == "" && s.m_CurrentAttrName == "" ); \
\
if( s.m_CurrentElementsParsed.count( #Rule ) ) \
{ \
throw parse_error( #Rule \
" was already defined for this part!", \
in ); \
} \
\
s.m_CurrentElementsParsed.insert( #Rule ); \
ExtraCode; \
} \
} \
Struture that will be populated by the PEGTL parser.

Definition at line 278 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_ATTRIBUTE_ACTION

#define DEFINE_ATTRIBUTE_ACTION (   Rule,
  StateVariable 
)
Value:
template <> \
{ \
template <typename ActionInput> \
static void apply( const ActionInput& in, CADSTAR_LIB_PARSER_STATE& s ) \
{ \
if( s.StateVariable.count( s.m_CurrentAttrName ) ) \
{ \
throw parse_error( \
fmt::format( "Duplicate attribute name '{}'", s.m_CurrentAttrName ), \
in ); \
} \
\
val.m_ReadOnly = s.m_ReadOnly; \
val.m_Value = s.m_CurrentString; \
\
s.StateVariable.insert( { s.m_CurrentAttrName, val } ); \
s.m_CurrentAttrName = ""; \
s.m_CurrentString = ""; \
s.m_ReadOnly = false; \
} \
} \

Definition at line 415 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_CONTENT_TO_NUMBER_ACTION

#define DEFINE_CONTENT_TO_NUMBER_ACTION (   Rule,
  StateVariable 
)
Value:
template <> \
{ \
template <typename ActionInput> \
static void apply( const ActionInput& in, CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( s.m_CurrentString == "" && s.m_CurrentAttrName == "" ); \
s.StateVariable = helperStringToLong( in.string() ); \
} \
}
long helperStringToLong(std::string aString)

Definition at line 77 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_CONTENT_TO_STRING_ACTION

#define DEFINE_CONTENT_TO_STRING_ACTION (   Rule)
Value:
template <> \
{ \
template <typename ActionInput> \
static void apply( const ActionInput& in, CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( s.m_CurrentString == "" && s.m_CurrentAttrName == "" ); \
s.m_CurrentString = in.string(); \
} \
}

Definition at line 114 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_PIN_GROUP_ACTION

#define DEFINE_PIN_GROUP_ACTION (   Rule,
  StateVariable 
)
Value:
template <> \
{ \
static void apply0( CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( s.m_CurrentString == "" && s.m_CurrentAttrName == "" ); \
s.StateVariable.push_back( s.m_CurrentPinEquivalenceGroup ); \
s.m_CurrentPinEquivalenceGroup.clear(); \
} \
} \

Definition at line 342 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_STRING_ACTION

#define DEFINE_STRING_ACTION (   Rule,
  StateVariable 
)
Value:
template <> \
{ \
/* @todo : convert to use apply0 to improve performance( once fully tested ) */ \
template <typename ActionInput> \
static void apply( const ActionInput& in, CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( in.string().size() >= s.m_CurrentString.size() ); \
s.StateVariable = s.m_CurrentString; \
s.m_CurrentString = ""; \
} \
} \

Definition at line 132 of file cadstar_parts_lib_parser.cpp.

◆ DEFINE_SWAP_GROUP_ACTION

#define DEFINE_SWAP_GROUP_ACTION (   Rule,
  StateVariable 
)
Value:
template <> \
{ \
static void apply0( CADSTAR_LIB_PARSER_STATE& s ) \
{ \
assert( s.m_CurrentString == "" && s.m_CurrentAttrName == "" ); \
s.StateVariable.push_back( s.m_CurrentSwapGroup ); \
s.m_CurrentSwapGroup = CADSTAR_SWAP_GROUP(); \
} \
} \

Definition at line 364 of file cadstar_parts_lib_parser.cpp.

Function Documentation

◆ checkHeaderHelper()

template<typename INPUT_TYPE >
bool checkHeaderHelper ( INPUT_TYPE &  aInput)

◆ DECLARE_SINGLE_MATCH_RULE() [1/8]

DECLARE_SINGLE_MATCH_RULE ( DFN_LINE  )

◆ DECLARE_SINGLE_MATCH_RULE() [2/8]

DECLARE_SINGLE_MATCH_RULE ( MXP_LINE  )

◆ DECLARE_SINGLE_MATCH_RULE() [3/8]

DECLARE_SINGLE_MATCH_RULE ( NGS_LINE  ,
s.m_CurrentPart.  m_GateSwappingAllowed = false 
)

◆ DECLARE_SINGLE_MATCH_RULE() [4/8]

DECLARE_SINGLE_MATCH_RULE ( NPV_LINE  ,
s.m_CurrentPart.  m_PinsVisible = false 
)

◆ DECLARE_SINGLE_MATCH_RULE() [5/8]

DECLARE_SINGLE_MATCH_RULE ( PAC_LINE  )

◆ DECLARE_SINGLE_MATCH_RULE() [6/8]

DECLARE_SINGLE_MATCH_RULE ( PART_VALUE  )

◆ DECLARE_SINGLE_MATCH_RULE() [7/8]

DECLARE_SINGLE_MATCH_RULE ( SPI_LINE  )

◆ DECLARE_SINGLE_MATCH_RULE() [8/8]

DECLARE_SINGLE_MATCH_RULE ( STM_LINE  )

◆ DEFINE_ATTRIBUTE_ACTION() [1/4]

DEFINE_ATTRIBUTE_ACTION ( PART_ATTRIBUTE  ,
m_CurrentPart.  m_PartAttributes 
)

◆ DEFINE_ATTRIBUTE_ACTION() [2/4]

DEFINE_ATTRIBUTE_ACTION ( PCB_ATTRIBUTE  ,
m_CurrentPart.  m_PcbAttributes 
)

◆ DEFINE_ATTRIBUTE_ACTION() [3/4]

DEFINE_ATTRIBUTE_ACTION ( SCH_PCB_ATTRIBUTE  ,
m_CurrentPart.  m_SchAndPcbAttributes 
)

◆ DEFINE_ATTRIBUTE_ACTION() [4/4]

DEFINE_ATTRIBUTE_ACTION ( SCM_ATTRIBUTE  ,
m_CurrentPart.  m_SchAttributes 
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [1/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( CURRENT_FORMAT_NUMBER  ,
m_ParsedModel.  m_FormatNumber 
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [2/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( HIERARCHY_NODE_INDEX  ,
m_CurrentLong   
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [3/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( MAX_PIN_COUNT  ,
m_CurrentPart.  m_MaxPinCount 
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [4/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( PIN_IDENTIFIER  ,
m_CurrentPin.  m_Identifier 
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [5/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( PIN_LOADING  ,
m_CurrentPin.  m_Loading 
)

◆ DEFINE_CONTENT_TO_NUMBER_ACTION() [6/6]

DEFINE_CONTENT_TO_NUMBER_ACTION ( PINNUM  ,
m_CurrentLong   
)

◆ DEFINE_CONTENT_TO_STRING_ACTION()

DEFINE_CONTENT_TO_STRING_ACTION ( PINNAME  )

◆ DEFINE_PIN_GROUP_ACTION() [1/3]

DEFINE_PIN_GROUP_ACTION ( EQUIVALENT_PINS_GROUP  ,
m_CurrentPart.  m_PinEquivalences 
)

◆ DEFINE_PIN_GROUP_ACTION() [2/3]

DEFINE_PIN_GROUP_ACTION ( EXTERNAL_SWAP_GATE  ,
m_CurrentSwapGroup.  m_Gates 
)

◆ DEFINE_PIN_GROUP_ACTION() [3/3]

DEFINE_PIN_GROUP_ACTION ( INTERNAL_SWAP_GATE  ,
m_CurrentSwapGroup.  m_Gates 
)

◆ DEFINE_STRING_ACTION() [1/19]

DEFINE_STRING_ACTION ( ACCEPTANCE_PART_NAME  ,
m_CurrentPart.  m_AcceptancePartName 
)

◆ DEFINE_STRING_ACTION() [2/19]

DEFINE_STRING_ACTION ( ACCEPTANCE_TEXT  ,
m_CurrentPart.  m_AcceptanceText 
)

◆ DEFINE_STRING_ACTION() [3/19]

DEFINE_STRING_ACTION ( ATTRIBUTE_NAME  ,
m_CurrentAttrName   
)

◆ DEFINE_STRING_ACTION() [4/19]

DEFINE_STRING_ACTION ( DEFINITION_NAME  ,
m_CurrentPart.  m_PartDefinitionName 
)

◆ DEFINE_STRING_ACTION() [5/19]

DEFINE_STRING_ACTION ( PART_DESCRIPTION  ,
m_CurrentPart.  m_Description 
)

◆ DEFINE_STRING_ACTION() [6/19]

DEFINE_STRING_ACTION ( PART_NAME  ,
m_CurrentPart.  m_Name 
)

◆ DEFINE_STRING_ACTION() [7/19]

DEFINE_STRING_ACTION ( PART_NUMBER  ,
m_CurrentPart.  m_Number 
)

◆ DEFINE_STRING_ACTION() [8/19]

DEFINE_STRING_ACTION ( PART_VERSION  ,
m_CurrentPart.  m_Version 
)

◆ DEFINE_STRING_ACTION() [9/19]

DEFINE_STRING_ACTION ( PCB_ALTERNATE  ,
m_CurrentPart.  m_Pcb_alternate 
)

◆ DEFINE_STRING_ACTION() [10/19]

DEFINE_STRING_ACTION ( PCB_COMPONENT  ,
m_CurrentPart.  m_Pcb_component 
)

◆ DEFINE_STRING_ACTION() [11/19]

DEFINE_STRING_ACTION ( PIN_SIGNAL_NAME  ,
m_CurrentSignalName   
)

◆ DEFINE_STRING_ACTION() [12/19]

DEFINE_STRING_ACTION ( SCH_ALTERNATE  ,
m_CurrentSymbol.  m_SymbolAlternateName 
)

◆ DEFINE_STRING_ACTION() [13/19]

DEFINE_STRING_ACTION ( SCH_NAME  ,
m_CurrentSymbol.  m_SymbolName 
)

◆ DEFINE_STRING_ACTION() [14/19]

DEFINE_STRING_ACTION ( SPICE_MODEL  ,
m_CurrentPart.  m_SpiceModel 
)

◆ DEFINE_STRING_ACTION() [15/19]

DEFINE_STRING_ACTION ( SPICE_PART_NAME  ,
m_CurrentPart.  m_SpicePartName 
)

◆ DEFINE_STRING_ACTION() [16/19]

DEFINE_STRING_ACTION ( STEM  ,
m_CurrentPart.  m_ComponentStem 
)

◆ DEFINE_STRING_ACTION() [17/19]

DEFINE_STRING_ACTION ( SYM_ELEMENT_NAME  ,
m_CurrentSwapGroup.  m_Name 
)

◆ DEFINE_STRING_ACTION() [18/19]

DEFINE_STRING_ACTION ( USER_PART_ATTRIBUTE_NAME  ,
m_CurrentAttrName   
)

◆ DEFINE_STRING_ACTION() [19/19]

DEFINE_STRING_ACTION ( VALUE  ,
m_CurrentPart.  m_Value 
)

◆ DEFINE_SWAP_GROUP_ACTION() [1/2]

DEFINE_SWAP_GROUP_ACTION ( EXTERNAL_SWAP_GROUP  ,
m_CurrentPart.  m_ExternalSwapGroup 
)

◆ DEFINE_SWAP_GROUP_ACTION() [2/2]

DEFINE_SWAP_GROUP_ACTION ( INTERNAL_SWAP_GROUP  ,
m_CurrentPart.  m_InternalSwapGroup 
)

◆ helperStringToLong()

long helperStringToLong ( std::string  aString)

◆ readCadstarHelper()

template<typename INPUT_TYPE >
CADSTAR_PARTS_LIB_MODEL readCadstarHelper ( INPUT_TYPE &  aInput)