diff --git a/nixd/include/nixd/Syntax/Nodes.h b/nixd/include/nixd/Syntax/Nodes.h index 638190598..bc0a490f5 100644 --- a/nixd/include/nixd/Syntax/Nodes.h +++ b/nixd/include/nixd/Syntax/Nodes.h @@ -12,10 +12,25 @@ namespace nixd::syntax { /// TODO: the comment struct Node { nixd::RangeIdx Range; + enum NodeKind { + NK_Node, +#define NODE(NAME, BODY) NK_##NAME, +#include "Nodes.inc" +#undef NODE + }; + virtual NodeKind getKind() { return NK_Node; }; + virtual ~Node() = default; }; +#define COMMON_METHOD virtual NodeKind getKind() override; #define NODE(NAME, BODY) struct NAME : Node BODY; #include "Nodes.inc" #undef NODE +#undef COMMON_METHOD + +#define NODE(NAME, _) \ + inline Node::NodeKind NAME::getKind() { return NK_##NAME; } +#include "Nodes.inc" +#undef NODE } // namespace nixd::syntax diff --git a/nixd/include/nixd/Syntax/Nodes.inc b/nixd/include/nixd/Syntax/Nodes.inc index 6aa406827..550d79356 100644 --- a/nixd/include/nixd/Syntax/Nodes.inc +++ b/nixd/include/nixd/Syntax/Nodes.inc @@ -1,69 +1,139 @@ #ifdef NODE -NODE(Identifier, { nix::Symbol Symbol; }) + +#ifndef COMMON_METHOD +#define COMMON_METHOD +#define P_COMMON_METHOD_DEFINED +#endif + +NODE(Identifier, { + nix::Symbol Symbol; + COMMON_METHOD +}) NODE(Formal, { Identifier *ID; /// The default argument. Node *Default; + COMMON_METHOD }) NODE(Formals, { std::vector Formals; bool Ellipsis; + COMMON_METHOD }) NODE(Function, { Identifier *Arg; Formals *Formals; Node *Body; + COMMON_METHOD }) NODE(Assert, { Node *Cond; Node *Body; + COMMON_METHOD }) NODE(With, { Node *Attrs; Node *Body; + COMMON_METHOD +}) +NODE(Binds, { + std::vector Attributes; + COMMON_METHOD }) -NODE(Binds, { std::vector Attributes; }) -NODE(ListBody, { std::vector Elems; }) -NODE(List, { ListBody *Body; }) +NODE(ListBody, { + std::vector Elems; + COMMON_METHOD +}) +NODE(List, { + ListBody *Body; + COMMON_METHOD +}) NODE(Let, { Node *Binds; Node *Body; + COMMON_METHOD }) NODE(If, { Node *Cond; Node *Then; Node *Else; + COMMON_METHOD +}) +NODE(Variable, { + Node *ID; + COMMON_METHOD +}) +NODE(Int, { + nix::NixInt N; + COMMON_METHOD +}) +NODE(Float, { + nix::NixFloat NF; + COMMON_METHOD +}) +NODE(InterpExpr, { + Node *Body; + COMMON_METHOD +}) +NODE(String, { + std::string S; + COMMON_METHOD +}) +NODE(IndString, { + std::string S; + COMMON_METHOD +}) +NODE(IndStringParts, { + std::vector SubStrings; + COMMON_METHOD +}) +NODE(ConcatStrings, { + std::vector SubStrings; + COMMON_METHOD +}) +NODE(HPath, { + std::string S; + COMMON_METHOD +}) +NODE(Path, { + std::string S; + COMMON_METHOD +}) +NODE(SPath, { + std::string S; + COMMON_METHOD +}) +NODE(URI, { + std::string S; + COMMON_METHOD }) -NODE(Variable, { Node *ID; }) -NODE(Int, { nix::NixInt N; }) -NODE(Float, { nix::NixFloat NF; }) -NODE(InterpExpr, { Node *Body; }) -NODE(String, { std::string S; }) -NODE(IndString, { std::string S; }) -NODE(IndStringParts, { std::vector SubStrings; }) -NODE(ConcatStrings, { std::vector SubStrings; }) -NODE(HPath, { std::string S; }) -NODE(Path, { std::string S; }) -NODE(SPath, { std::string S; }) -NODE(URI, { std::string S; }) NODE(Call, { Node *Fn; std::vector Args; + COMMON_METHOD +}) +NODE(AttrPath, { + std::vector Names; + COMMON_METHOD +}) +NODE(Attrs, { + std::vector Names; + COMMON_METHOD }) -NODE(AttrPath, { std::vector Names; }) -NODE(Attrs, { std::vector Names; }) NODE(Attribute, { AttrPath *Path; Node *Body; + COMMON_METHOD }) NODE(InheritedAttribute, { Attrs *Attrs; Node *E; + COMMON_METHOD }) NODE(Select, { @@ -74,31 +144,52 @@ NODE(Select, { /// expr1 '.' attrpath 'or' expr2 /// expr2 is the default value if we cannot select Node *Default; + COMMON_METHOD }) NODE(OpHasAttr, { Node *Operand; Node *Path; + COMMON_METHOD +}) +NODE(OpNot, { + Node *Body; + COMMON_METHOD +}) +NODE(OpNegate, { + Node *Body; + COMMON_METHOD }) -NODE(OpNot, { Node *Body; }) -NODE(OpNegate, { Node *Body; }) -NODE(Braced, { Node *Body; }) +NODE(Braced, { + Node *Body; + COMMON_METHOD +}) NODE(AttrSet, { Binds *Binds; bool Recursive; + COMMON_METHOD }) -NODE(LegacyLet, { Binds *Binds; }) +NODE(LegacyLet, { + Binds *Binds; + COMMON_METHOD +}) // Binary Operators #define BIN_OP(NAME, _) \ NODE(NAME, { \ Node *LHS; \ Node *RHS; \ + COMMON_METHOD \ }) #include "BinaryOps.inc" #undef BIN_OP -#endif +#ifdef P_COMMON_METHOD_DEFINED +#undef COMMON_METHOD +#undef P_COMMON_METHOD_DEFINED +#endif // P_COMMON_METHOD_DEFINED + +#endif // NODE diff --git a/nixd/include/nixd/Syntax/Parser.h b/nixd/include/nixd/Syntax/Parser.h new file mode 100644 index 000000000..e6d034482 --- /dev/null +++ b/nixd/include/nixd/Syntax/Parser.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Parser/Require.h" + +namespace nixd::syntax { +void parse(char *Text, size_t Size, ParseData *Data); +} // namespace nixd::syntax diff --git a/nixd/include/nixd/Syntax/Parser/Require.h b/nixd/include/nixd/Syntax/Parser/Require.h index a61c6329f..4c64d35e4 100644 --- a/nixd/include/nixd/Syntax/Parser/Require.h +++ b/nixd/include/nixd/Syntax/Parser/Require.h @@ -17,6 +17,8 @@ struct ParseState { }; struct ParseData { + Node *Result; + ParseState State; nix::PosTable::Origin Origin; diff --git a/nixd/lib/AST/meson.build b/nixd/lib/AST/meson.build index 9789bdef6..7179fa254 100644 --- a/nixd/lib/AST/meson.build +++ b/nixd/lib/AST/meson.build @@ -1,7 +1,7 @@ libnixdASTDeps = [ nixd_lsp_server , nix_all , nixdExpr - , nixdParser + , nixdSyntax , nixdNix , llvm ] diff --git a/nixd/lib/Syntax/Parser/Epilogue.cpp b/nixd/lib/Syntax/Parser/Epilogue.cpp new file mode 100644 index 000000000..94459ca78 --- /dev/null +++ b/nixd/lib/Syntax/Parser/Epilogue.cpp @@ -0,0 +1,20 @@ +#pragma once + +#include "Parser.tab.h" + +#include "Lexer.tab.h" + +#include "nixd/Syntax/Parser.h" +#include "nixd/Syntax/Parser/Require.h" + +namespace nixd::syntax { + +void parse(char *Text, size_t Size, ParseData *Data) { + yyscan_t Scanner; + yylex_init(&Scanner); + yy_scan_buffer(Text, Size, Scanner); + yyparse(Scanner, Data); + yylex_destroy(Scanner); +} + +} // namespace nixd::syntax diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index 9ee777c78..1529d0992 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -8,6 +8,7 @@ %parse-param { nixd::syntax::ParseData * Data } %lex-param { void * Scanner } %lex-param { nixd::syntax::ParseData * Data } +%define parse.trace %code requires { #include "nixd/Syntax/Parser/Require.h" @@ -36,6 +37,7 @@ nixd::syntax::Attribute *Attribute; nixd::syntax::InheritedAttribute *IA; nixd::syntax::ListBody *LB; + nixd::syntax::IndString *IndString; // Tokens nixd::syntax::StringToken STR; @@ -50,7 +52,8 @@ %type start expr expr_function expr_if expr_op expr_select expr_simple %type string_parts %type string_attr -%type string ind_string; +%type string; +%type ind_string; %type string_parts_interpolated %type string_parts_interp_expr %type identifier attr @@ -93,49 +96,49 @@ %% -start: expr; +start: expr { Data->Result = $1; }; expr: expr_function; expr_function : identifier ':' expr_function { - $$ = decorateNode(new Function { - .Arg = $1, - .Formals = nullptr, - .Body = $3 - }, yylloc, *Data); + auto N = decorateNode(new Function, yylloc, *Data); + N->Arg = $1; + N->Formals = nullptr; + N->Body = $3; + $$ = N; } | '{' formals '}' ':' expr_function { - $$ = decorateNode(new Function { - .Arg = nullptr, - .Formals = $2, - .Body = $5 - }, yylloc, *Data); + auto N = decorateNode(new Function, yylloc, *Data); + N->Arg = nullptr; + N->Formals = $2; + N->Body = $5; + $$ = N; } | '{' formals '}' '@' identifier ':' expr_function { - $$ = decorateNode(new Function { - .Arg = $5, - .Formals = $2, - .Body = $7 - }, yylloc, *Data); + auto N = decorateNode(new Function, yylloc, *Data); + N->Arg = $5; + N->Formals = $2; + N->Body = $7; + $$ = N; } | ASSERT expr ';' expr_function { - $$ = decorateNode(new Assert { - .Cond = $2, - .Body = $4 - }, yylloc, *Data); + auto N = decorateNode(new Assert, yylloc, *Data); + N->Cond = $2; + N->Body = $4; + $$ = N; } | WITH expr ';' expr_function { - $$ = decorateNode(new With { - .Attrs = $2, - .Body = $4 - }, yylloc, *Data); + auto N = decorateNode(new With, yylloc, *Data); + N->Attrs = $2; + N->Body = $4; + $$ = N; } | LET binds IN expr_function { - $$ = decorateNode(new Let { - .Binds = $2, - .Body = $4 - }, yylloc, *Data); + auto N = decorateNode(new Let, yylloc, *Data); + N->Binds = $2; + N->Body = $4; + $$ = N; } | expr_if @@ -143,25 +146,25 @@ expr_function expr_if : IF expr THEN expr ELSE expr { - $$ = decorateNode(new If { - .Cond = $2, - .Then = $4, - .Else = $6 - }, yylloc, *Data); + auto N = decorateNode(new If, yylloc, *Data); + N->Cond = $2; + N->Then = $4; + N->Else = $6; + $$ = N; } | expr_op expr_op : '!' expr_op %prec NOT { - $$ = decorateNode(new OpNot { - .Body = $2 - }, yylloc, *Data); + auto N = decorateNode(new OpNot, yylloc, *Data); + N->Body = $2; + $$ = N; } | '-' expr_op %prec NEGATE { - $$ = decorateNode(new OpNot { - .Body = $2 - }, yylloc, *Data); + auto N = decorateNode(new OpNegate, yylloc, *Data); + N->Body = $2; + $$ = N; } | expr_op EQ expr_op { $$ = mkBinOp($1, $3, yylloc, *Data); } | expr_op NEQ expr_op { $$ = mkBinOp($1, $3, yylloc, *Data); } @@ -179,10 +182,10 @@ expr_op | expr_op '/' expr_op { $$ = mkBinOp($1, $3, yylloc, *Data); } | expr_op CONCAT expr_op { $$ = mkBinOp($1, $3, yylloc, *Data); } | expr_op '?' attrpath { - $$ = decorateNode(new OpHasAttr{ - .Operand = $1, - .Path = $3 - }, yylloc, *Data); + auto N = decorateNode(new OpHasAttr, yylloc, *Data); + N->Operand = $1; + N->Path = $3; + $$ = N; } | expr_app @@ -193,27 +196,26 @@ expr_app $$->Range = mkRange(yylloc, *Data); } | expr_select { - $$ = decorateNode(new Call{ - .Fn = $1, - .Args = {} - }, yylloc, *Data); + auto N = decorateNode(new Call, yylloc, *Data); + N->Fn = $1; + $$ = N; } expr_select : expr_simple '.' attrpath { - $$ = decorateNode(new Select{ - .Body = $1, - .AttrPath = $3, - .Default = nullptr - }, yylloc, *Data); + auto N = decorateNode(new Select, yylloc, *Data); + N->Body = $1; + N->AttrPath = $3; + N->Default = nullptr; + $$ = N; } | expr_simple '.' attrpath OR_KW expr_select { - $$ = decorateNode(new Select{ - .Body = $1, - .AttrPath = $3, - .Default = $5 - }, yylloc, *Data); + auto N = decorateNode(new Select, yylloc, *Data); + N->Body = $1; + N->AttrPath = $3; + N->Default = $5; + $$ = N; } | expr_simple OR_KW { // TODO @@ -227,19 +229,19 @@ expr_simple // Note: __curPos is actually not a "variable", // but for now we treat as if it is, // and convert it to ExprPos in the lowering process. - $$ = decorateNode(new Variable{ - .ID = $1 - }, yylloc, *Data); + auto N = decorateNode(new Variable, yylloc, *Data); + N->ID = $1; + $$ = N; } | INT { - $$ = decorateNode(new Int { - .N = $1 - }, yylloc, *Data); + auto N = decorateNode(new Int, yylloc, *Data); + N->N = $1; + $$ = N; } | FLOAT { - $$ = decorateNode(new Float { - .NF = $1 - }, yylloc, *Data); + auto N = decorateNode(new Float, yylloc, *Data); + N->NF = $1; + $$ = N; } | '"' string_parts '"' { $$ = $2; @@ -254,31 +256,31 @@ expr_simple } | uri { $$ = $1; } | '(' expr ')' { - $$ = decorateNode(new Braced { - .Body = $2 - }, yylloc, *Data); + auto N = decorateNode(new Braced, yylloc, *Data); + N->Body = $2; + $$ = N; } | LET '{' binds '}' { - $$ = decorateNode(new LegacyLet { - .Binds = $3 - }, yylloc, *Data); + auto N = decorateNode(new LegacyLet, yylloc, *Data); + N->Binds = $3; + $$ = N; } | REC '{' binds '}' { - $$ = decorateNode(new AttrSet { - .Binds = $3, - .Recursive = true - }, yylloc, *Data); + auto N = decorateNode(new AttrSet, yylloc, *Data); + N->Binds = $3; + N->Recursive = true; + $$ = N; } | '{' binds '}' { - $$ = decorateNode(new AttrSet { - .Binds = $2, - .Recursive = false - }, yylloc, *Data); + auto N = decorateNode(new AttrSet, yylloc, *Data); + N->Binds = $2; + N->Recursive = false; + $$ = N; } | '[' list_body ']' { - $$ = decorateNode(new List { - .Body = $2 - }, yylloc, *Data); + auto N = decorateNode(new List, yylloc, *Data); + N->Body = $2; + $$ = N; } list_body @@ -303,35 +305,33 @@ string_parts_interpolated $$->Range = mkRange(yylloc, *Data); } | string_parts_interp_expr { - $$ = decorateNode(new ConcatStrings{ - .SubStrings = {$1} - }, yylloc, *Data); + $$ = decorateNode(new ConcatStrings, yylloc, *Data); + $$->SubStrings = {$1}; } | string string_parts_interp_expr { - $$ = decorateNode(new ConcatStrings{ - .SubStrings = {$1, $2} - }, yylloc, *Data); + $$ = decorateNode(new ConcatStrings, yylloc, *Data); + $$->SubStrings = {$1, $2}; } path_start : PATH { - $$ = decorateNode(new Path{ - .S = std::string($1) - }, yylloc, *Data); + auto N = decorateNode(new Path, yylloc, *Data); + N->S = std::string($1); + $$ = N; } | HPATH { - $$ = decorateNode(new HPath{ - .S = std::string($1) - }, yylloc, *Data); + auto N = decorateNode(new HPath, yylloc, *Data); + N->S = std::string($1); + $$ = N; } // Nixd extension, nix uses the token directly spath : SPATH { - $$ = decorateNode(new SPath{ - .S = std::string($1) - }, yylloc, *Data); + auto N = decorateNode(new SPath, yylloc, *Data); + N->S = std::string($1); + $$ = N; } @@ -349,41 +349,36 @@ ind_string_parts // Nixd extension, nix uses the token directly string : STR { - $$ = decorateNode(new String{ - .S = std::string($1) - }, yylloc, *Data); + $$ = decorateNode(new String, yylloc, *Data); + $$->S = std::string($1); } // Nixd extension, nix uses the token directly ind_string : IND_STR { - $$ = decorateNode(new String{ - .S = std::string($1) - }, yylloc, *Data); + $$ = decorateNode(new IndString, yylloc, *Data); + $$->S = std::string($1); } // Nixd extension // nix: DOLLAR_CURLY expr '}' string_parts_interp_expr : DOLLAR_CURLY expr '}' { - $$ = decorateNode(new InterpExpr{ - .Body = $2 - }, yylloc, *Data); + $$ = decorateNode(new InterpExpr, yylloc, *Data); + $$->Body = $2; } // Nixd extension, nix uses the token directly uri : URI { - $$ = decorateNode(new nixd::syntax::URI { - .S = std::string($1) - }, yylloc, *Data); + $$ = decorateNode(new nixd::syntax::URI, yylloc, *Data); + $$->S = std::string($1); } identifier : ID { - $$ = decorateNode(new Identifier { - .Symbol = Data->State.Symbols.create($1) - }, yylloc, *Data); + $$ = decorateNode(new Identifier, yylloc, *Data); + $$->Symbol = Data->State.Symbols.create($1); } @@ -401,25 +396,22 @@ binds // Nixd extension inherited_attribute : INHERIT attrs ';' { - $$ = decorateNode(new InheritedAttribute { - .Attrs = $2, - .E = nullptr - }, yylloc, *Data); + $$ = decorateNode(new InheritedAttribute, yylloc, *Data); + $$->Attrs = $2; + $$->E = nullptr; } | INHERIT '(' expr ')' attrs ';' { - $$ = decorateNode(new InheritedAttribute { - .Attrs = $5, - .E = $3 - }, yylloc, *Data); + $$ = decorateNode(new InheritedAttribute, yylloc, *Data); + $$->Attrs = $5; + $$->E = $3; } // Nixd extension attribute : attrpath '=' expr ';' { - $$ = decorateNode(new Attribute { - .Path = $1, - .Body = $3 - }, yylloc, *Data); + $$ = decorateNode(new Attribute, yylloc, *Data); + $$->Path = $1; + $$->Body = $3; } attrs @@ -432,9 +424,8 @@ attrs $$->Range = mkRange(yylloc, *Data); } | { - $$ = decorateNode(new Attrs { - .Names = {} - }, yylloc, *Data); + $$ = decorateNode(new Attrs, yylloc, *Data); + $$->Names = {}; } @@ -448,14 +439,12 @@ attrpath $$->Range = mkRange(yylloc, *Data); } | attr { - $$ = decorateNode(new AttrPath { - .Names = {$1} - }, yylloc, *Data); + $$ = decorateNode(new AttrPath, yylloc, *Data); + $$->Names = {$1}; } | string_attr { - $$ = decorateNode(new AttrPath { - .Names = {$1} - }, yylloc, *Data); + $$ = decorateNode(new AttrPath, yylloc, *Data); + $$->Names = {$1}; } @@ -463,9 +452,8 @@ attr : identifier { $$ = $1; } | OR_KW { auto Or = Data->State.Symbols.create("or"); - $$ = decorateNode(new Identifier { - .Symbol = Or - }, yylloc, *Data); + $$ = decorateNode(new Identifier, yylloc, *Data); + $$->Symbol = Or; } @@ -480,38 +468,35 @@ formals $$->Range = mkRange(yylloc, *Data); } | formal { - $$ = decorateNode(new Formals { - .Formals = {$1}, - .Ellipsis = false - }, yylloc, *Data); + $$ = decorateNode(new Formals, yylloc, *Data); + $$->Formals = {$1}; + $$->Ellipsis = false; } | { - $$ = decorateNode(new Formals { - .Formals = {}, - .Ellipsis = false - }, yylloc, *Data); + $$ = decorateNode(new Formals, yylloc, *Data); + $$->Formals = {}; + $$->Ellipsis = false; } | ELLIPSIS { - $$ = decorateNode(new Formals { - .Formals = {}, - .Ellipsis = true - }, yylloc, *Data); + $$ = decorateNode(new Formals, yylloc, *Data); + $$->Formals = {}; + $$->Ellipsis = true; } formal : identifier { - $$ = decorateNode(new Formal { - .ID = $1, - .Default = nullptr - }, yylloc, *Data); + $$ = decorateNode(new Formal, yylloc, *Data); + $$->ID = $1; + $$->Default = nullptr; } | identifier '?' expr { - $$ = decorateNode(new Formal { - .ID = $1, - .Default = $3 - }, yylloc, *Data); + $$ = decorateNode(new Formal, yylloc, *Data); + $$->ID = $1; + $$->Default = $3; } %% + +#include "Parser/Epilogue.cpp" diff --git a/nixd/lib/Syntax/Parser/Prologue.cpp b/nixd/lib/Syntax/Parser/Prologue.cpp index 4a6d426b8..c26e78a7a 100644 --- a/nixd/lib/Syntax/Parser/Prologue.cpp +++ b/nixd/lib/Syntax/Parser/Prologue.cpp @@ -5,6 +5,8 @@ #include "nixd/Syntax/Nodes.h" #include "nixd/Syntax/Parser/Require.h" +using namespace nixd::syntax; + YY_DECL; void yyerror(YYLTYPE *loc, yyscan_t scanner, nixd::syntax::ParseData *data, @@ -33,7 +35,8 @@ T *decorateNode(T *Node, YYLTYPE YL, nixd::syntax::ParseData &Data) { template T *mkBinOp(nixd::syntax::Node *LHS, nixd::syntax::Node *RHS, YYLTYPE YL, nixd::syntax::ParseData &Data) { - return decorateNode(new T{.LHS = LHS, .RHS = RHS}, YL, Data); + auto N = decorateNode(new T, YL, Data); + N->LHS = LHS; + N->RHS = RHS; + return N; } - -using namespace nixd::syntax; diff --git a/nixd/lib/Syntax/meson.build b/nixd/lib/Syntax/meson.build index ea3881778..c00af5097 100644 --- a/nixd/lib/Syntax/meson.build +++ b/nixd/lib/Syntax/meson.build @@ -19,20 +19,20 @@ parser = custom_target('parser' ) #------------------------------------------------------------------------------# -libnixdParserDeps = [ nix_all, nixdExpr, nixdSupport ] - -libnixdParser = library('nixdParser' +libnixdSyntaxDeps = [ nix_all, nixdExpr, nixdSupport ] +libnixdSyntaxInc = [ nixd_inc, './' ] +libnixdSyntax = library('nixdSyntax' , lexer , parser -, include_directories: nixd_inc -, dependencies: libnixdParserDeps +, include_directories: libnixdSyntaxInc +, dependencies: libnixdSyntaxDeps , install: true ) -nixdParser = declare_dependency( include_directories: nixd_inc +nixdSyntax = declare_dependency( include_directories: libnixdSyntaxInc , sources: [ lexer , parser ] - , link_with: libnixdParser - , dependencies: libnixdParserDeps + , link_with: libnixdSyntax + , dependencies: libnixdSyntaxDeps ) diff --git a/nixd/meson.build b/nixd/meson.build index baecfc3ff..00ec6a756 100644 --- a/nixd/meson.build +++ b/nixd/meson.build @@ -13,7 +13,6 @@ subdir('lib') nixdDeps = [ nixdAST , nixdNix - , nixdParser , nixdServer , nixdSupport ] @@ -37,3 +36,6 @@ test_server = executable('test-server' ) test('server', test_server) + + +subdir('test') diff --git a/nixd/test/Syntax/Basic.cpp b/nixd/test/Syntax/Basic.cpp new file mode 100644 index 000000000..f51e09c4d --- /dev/null +++ b/nixd/test/Syntax/Basic.cpp @@ -0,0 +1,27 @@ +#include + +#include "nixd/Syntax/Parser.h" +#include "nixd/Syntax/Parser/Require.h" + +#include +#include + +extern int yydebug; + +namespace nixd::syntax { + +TEST(NixdSyntax, Case1) { + auto STable = std::make_unique(); + auto PTable = std::make_unique(); + yydebug = 1; + + auto Data = std::unique_ptr( + new ParseData{.State = {*STable, *PTable}, + .Origin = nix::Pos::Origin(nix::Pos::none_tag())}); + Data->Result = nullptr; + + char Test[] = "let { x = 1; y = 2; } in x\n\0\0"; + parse(Test, strlen(Test) + 2, Data.get()); +} + +} // namespace nixd::syntax diff --git a/nixd/test/Syntax/meson.build b/nixd/test/Syntax/meson.build new file mode 100644 index 000000000..e8a7a4a81 --- /dev/null +++ b/nixd/test/Syntax/meson.build @@ -0,0 +1,6 @@ +libnixdSyntaxTest = executable('libnixdSyntaxTest' +, [ 'Basic.cpp' ] +, dependencies: [ nixdSyntax , gtest_main ] +) + +test('libnixdSyntaxTest', libnixdSyntaxTest) diff --git a/nixd/test/meson.build b/nixd/test/meson.build new file mode 100644 index 000000000..69aa1421b --- /dev/null +++ b/nixd/test/meson.build @@ -0,0 +1 @@ +subdir('Syntax')