Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <Parse/BoostSpiritConfig.h>
- #include <boost/spirit/home/x3.hpp>
- #include <boost/spirit/home/x3/support/utility/annotate_on_success.hpp>
- #include "SchematicFileParserConfig.hpp"
- #include <boost/fusion/adapted.hpp>
- // #include <boost/fusion/include/io.hpp>
- // #include <boost/fusion/include/vector.hpp>
- #include "SchematicFileAST.hpp"
- #include "SchematicFileAST_Adapted.hpp"
- #include "SchematicFileGrammar.hpp"
- #include "SchematicFileGrammarTypes.hpp"
- #include <vector>
- #include "error_handler.hpp"
- #include <boost/optional/optional_io.hpp>
- namespace client {
- namespace KicadFileParser_grammar {
- namespace x3 = boost::spirit::x3;
- namespace ascii = boost::spirit::x3::ascii;
- using x3::uint_;
- using x3::char_;
- using x3::float_;
- using x3::lit;
- using x3::int_;
- using x3::lit;
- using x3::double_;
- using x3::lexeme;
- using x3::no_skip;
- using x3::omit;
- using x3::repeat;
- using x3::with;
- using x3::eps;
- using x3::get;
- using x3::_attr;
- using x3::_pass;
- using x3::_val;
- using x3::hex;
- boost::spirit::x3::int_parser<unsigned, 16, 2, 2> hex_; // This allows for a hex doublet
- // Visit 3
- schematic_type const schematic = "schematic";
- bitmapImage_type const bitmapImage = "bitmapImage";
- busEntry_type const busEntry = "busEntry";
- wireSegment_type const wireSegment = "wireSegment";
- textNote_type const textNote = "textNote";
- schematicHeader_type const schematicHeader = "schematicHeader";
- schematicDescription_type const schematicDescription = "schematicDescription";
- globalLabel_type const globalLabel = "globalLabel";
- busSegment_type const busSegment = "busSegment";
- label_type const label = "label";
- componentAlternateReference_type const componentAlternateReference = "componentAlternateReference";
- componentField_type const componentField = "componentField";
- component_type const component = "component";
- dottedLineSegment_type const dottedLineSegment = "dottedLineSegment";
- heirarchicalSheetSymbolLabel_type const heirarchicalSheetSymbolLabel = "heirarchicalSheetSymbolLabel";
- heirarchicalSheetSymbol_type const heirarchicalSheetSymbol = "heirarchicalSheetSymbol";
- heirarchicalLabel_type const heirarchicalLabel = "heirarchicalLabel";
- junction_type const junction = "junction";
- noConnect_type const noConnect = "noConnect";
- nonQuotedString_type const nonQuotedString = "nonQuotedString";
- nonQuotedStringMultiWord_type const nonQuotedStringMultiWord = "nonQuotedStringMultiWord";
- optionalChar_type const optionalChar = "optionalChar";
- quotedString_type const quotedString = "quotedString";
- // Small generic parsers
- const auto nonQuotedString_def = lexeme[*(char_ - lit(" ")) > lit(" ")];
- const auto nonQuotedStringMultiWord_def = lexeme[*(char_ - lit("\n")) > lit("\n")];
- const auto quotedString_def = lexeme[lit('"') > *(char_ - lit('"')) > lit('"')];
- const auto optionalChar_def = no_skip[lit(' ') > (char_ - (lit(' ') | lit("\n")))];
- const auto bitmapImage_def =
- lit("$Bitmap")
- > lit("Pos") > uint_ > uint_
- > lit("Scale") > float_
- > lit("Data")
- > *(hex_) // The Data itself
- > lit("EndData")
- > lit("$EndBitmap"); // x and y
- const auto busEntry_def =
- lit("Entry")
- > nonQuotedString
- > nonQuotedString
- > uint_ > uint_
- > uint_ > uint_;
- const auto busSegment_def =
- lit("Wire") >> lit("Bus") >> lit("Line")
- > uint_ > uint_
- > uint_ > uint_;
- const auto wireSegment_def =
- lit("Wire") >> lit("Wire") >> lit("Line")
- > uint_ > uint_ // Start X and y
- > uint_ > uint_; // End X and Y
- const auto textNote_def =
- lit("Text")
- >> lit("Notes")
- > uint_ > uint_
- > char_ > uint_
- > nonQuotedString > uint_
- > nonQuotedStringMultiWord;
- const auto componentAlternateReference_def =
- lit("AR")
- > lit("Path=") > quotedString
- > lit("Ref=") > quotedString
- > lit("Part=") > quotedString
- > lit("AR")
- > lit("Path=") > quotedString
- > lit("Ref=") > quotedString
- > lit("Part=") > quotedString;
- const auto label_def =
- lit("Text")
- >> lit("Label")
- > uint_ > uint_
- > char_ > uint_
- > lit("~")
- > uint_
- > nonQuotedStringMultiWord;
- const auto schematicDescription_def =
- lit("$Descr") > char_ > int_ > int_ > int_
- > lit("encoding") > lexeme[+(char_ - "\n") > "\n"]
- > lit("Sheet") > int_ > int_
- > lit("Title") > quotedString
- > lit("Date") > quotedString
- > lit("Rev") > quotedString
- > lit("Comp") > quotedString
- > lit("Comment1") > quotedString
- > lit("Comment2") > quotedString
- > lit("Comment3") > quotedString
- > lit("Comment4") > quotedString
- > lit("$EndDescr");
- const auto schematicHeader_def =
- lit("EESchema Schematic File Version")
- > int_
- > +lexeme[(lit("LIBS:") > *(char_ - lit("\n ")) > lit("\n "))] // Dump the libs
- > lit("EELAYER")
- > int_
- > int_
- > lit("EELAYER")
- > lit("END")
- > schematicDescription;
- const auto componentField_def =
- lit("F")
- > uint_
- > quotedString
- > char_
- > int_
- > int_
- > uint_
- > uint_
- > char_
- > nonQuotedString
- > -quotedString;
- const auto dottedLineSegment_def =
- lit("Wire") >> lit("Notes") >> lit("Line")
- > uint_ > uint_
- > uint_ > uint_;
- const auto heirarchicalLabel_def =
- lit("Text")
- >> lit("HLabel")
- > uint_ > uint_
- > char_
- > uint_
- > nonQuotedString
- > lit("~")
- > uint_
- > nonQuotedStringMultiWord;
- // #TODO rename this to symbol fields
- const auto heirarchicalSheetSymbolLabel_def=
- lexeme[lit("F") > uint_]
- > quotedString
- > -(char_ - int_)
- > -(char_ - int_)
- > uint_
- > -uint_
- > -uint_;
- const auto heirarchicalSheetSymbol_def =
- lit("$Sheet")
- > lit("S")
- > uint_
- > uint_
- > uint_
- > uint_
- > lit("U")
- > hex
- > *(heirarchicalSheetSymbolLabel)
- > lit("$EndSheet");
- const auto component_def =
- lit("$Comp")
- > lit("L") > nonQuotedString > nonQuotedString
- > lit("U") > uint_ > uint_ > hex
- > lit("P") > uint_ > uint_
- > -componentAlternateReference
- > *componentField
- > uint_ > uint_ > uint_
- > int_ > int_ > int_ > int_
- > lit("$EndComp");
- const auto junction_def =
- lit("Connection")
- > lit("~")
- > uint_ > uint_; // x and ye
- const auto noConnect_def =
- lit("NoConn") > lit("~")
- > uint_ > uint_; // x and y
- const auto globalLabel_def =
- lit("Text")
- >> lit("GLabel")
- > uint_ > uint_
- > char_ > uint_ > nonQuotedString > nonQuotedString;
- const auto schematic_def =
- schematicHeader
- > *(
- label
- | textNote
- | noConnect
- | wireSegment
- | busSegment
- | dottedLineSegment
- | busEntry
- | heirarchicalLabel
- | globalLabel
- | junction
- | heirarchicalSheetSymbol
- | bitmapImage
- | component
- )
- > lit("$EndSCHEMATC");
- BOOST_SPIRIT_DEFINE
- (
- schematic,
- bitmapImage,
- busEntry,
- wireSegment,
- textNote,
- schematicHeader,
- schematicDescription,
- busSegment,
- componentAlternateReference,
- componentField,
- globalLabel,
- junction,
- heirarchicalSheetSymbol,
- heirarchicalSheetSymbolLabel,
- heirarchicalLabel,
- component,
- label,
- noConnect,
- dottedLineSegment,
- quotedString,
- nonQuotedString,
- nonQuotedStringMultiWord,
- optionalChar
- )
- struct schematic_class : error_handler_base, x3::annotate_on_success {};
- struct bitmapImage_class : x3::annotate_on_success {};
- struct busEntry_class : x3::annotate_on_success {};
- struct wireSegment_class : x3::annotate_on_success {};
- struct textNote_class : x3::annotate_on_success {};
- struct schematicDescription_class : x3::annotate_on_success {};
- struct schematicHeader_class : x3::annotate_on_success {}; // #TODO add rectshape to lib
- struct globalLabel_class : x3::annotate_on_success {};
- struct busSegment_class : x3::annotate_on_success {};
- struct componentField_class : x3::annotate_on_success {};
- struct componentAlternateReference_class : x3::annotate_on_success {};
- struct component_class : x3::annotate_on_success {};
- struct heirarchicalSheetSymbol_class : x3::annotate_on_success {};
- struct heirarchicalSheetSymbolLabel_class : x3::annotate_on_success {};
- struct heirarchicalLabel_class : x3::annotate_on_success {};
- struct noConnect_class : x3::annotate_on_success {};
- struct label_class : x3::annotate_on_success {};
- struct dottedLineSegment_class : x3::annotate_on_success {};
- struct junction_class : x3::annotate_on_success {};
- struct quotedString_class : x3::annotate_on_success {};
- struct nonQuotedString_class : x3::annotate_on_success {};
- struct nonQuotedStringMultiWord_class : x3::annotate_on_success {};
- struct optionalChar_class : x3::annotate_on_success {};
- }
- }
- namespace client {
- const KicadFileParser_grammar::schematic_type&schematicFile()
- {
- return KicadFileParser_grammar::schematic;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement