NCDConfigParser_parse.y 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * @file NCDConfigParser.y
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. %include {
  23. #include <string.h>
  24. #include <stddef.h>
  25. #include <misc/debug.h>
  26. #include <ncdconfig/NCDConfig.h>
  27. struct parser_out {
  28. int out_of_memory;
  29. int syntax_error;
  30. struct NCDConfig_interfaces *ast;
  31. };
  32. }
  33. %extra_argument {struct parser_out *parser_out}
  34. %token_type {void *}
  35. %token_destructor { free($$); }
  36. %type interfaces {struct NCDConfig_interfaces *}
  37. %type statements {struct NCDConfig_statements *}
  38. %type statement_names {struct NCDConfig_strings *}
  39. %type statement_args {struct NCDConfig_strings *}
  40. %destructor interfaces { NCDConfig_free_interfaces($$); }
  41. %destructor statements { NCDConfig_free_statements($$); }
  42. %destructor statement_names { NCDConfig_free_strings($$); }
  43. %destructor statement_args { NCDConfig_free_strings($$); }
  44. %syntax_error {
  45. parser_out->syntax_error = 1;
  46. }
  47. input ::= interfaces(A). {
  48. parser_out->ast = A;
  49. if (!A) {
  50. parser_out->out_of_memory = 1;
  51. }
  52. }
  53. interfaces(R) ::= INTERFACE NAME(A) CURRLY_OPEN statements(B) CURLY_CLOSE. {
  54. R = NCDConfig_make_interfaces(A, B, 0, NULL);
  55. if (!R) {
  56. parser_out->out_of_memory = 1;
  57. }
  58. }
  59. interfaces(R) ::= INTERFACE NAME(A) CURRLY_OPEN statements(B) CURLY_CLOSE interfaces(N). {
  60. R = NCDConfig_make_interfaces(A, B, 1, N);
  61. if (!R) {
  62. parser_out->out_of_memory = 1;
  63. }
  64. }
  65. statements(R) ::= statement_names(A) SEMICOLON. {
  66. R = NCDConfig_make_statements(A, 0, NULL, 0, NULL);
  67. if (!R) {
  68. parser_out->out_of_memory = 1;
  69. }
  70. }
  71. statements(R) ::= statement_names(A) statement_args(B) SEMICOLON. {
  72. R = NCDConfig_make_statements(A, 1, B, 0, NULL);
  73. if (!R) {
  74. parser_out->out_of_memory = 1;
  75. }
  76. }
  77. statements(R) ::= statement_names(A) SEMICOLON statements(N). {
  78. R = NCDConfig_make_statements(A, 0, NULL, 1, N);
  79. if (!R) {
  80. parser_out->out_of_memory = 1;
  81. }
  82. }
  83. statements(R) ::= statement_names(A) statement_args(B) SEMICOLON statements(N). {
  84. R = NCDConfig_make_statements(A, 1, B, 1, N);
  85. if (!R) {
  86. parser_out->out_of_memory = 1;
  87. }
  88. }
  89. statement_names(R) ::= NAME(A). {
  90. R = NCDConfig_make_strings(A, 0, NULL);
  91. if (!R) {
  92. parser_out->out_of_memory = 1;
  93. }
  94. }
  95. statement_names(R) ::= NAME(A) DOT statement_names(N). {
  96. R = NCDConfig_make_strings(A, 1, N);
  97. if (!R) {
  98. parser_out->out_of_memory = 1;
  99. }
  100. }
  101. statement_args(R) ::= STRING(A). {
  102. R = NCDConfig_make_strings(A, 0, NULL);
  103. if (!R) {
  104. parser_out->out_of_memory = 1;
  105. }
  106. }
  107. statement_args(R) ::= STRING(A) statement_args(N). {
  108. R = NCDConfig_make_strings(A, 1, N);
  109. if (!R) {
  110. parser_out->out_of_memory = 1;
  111. }
  112. }