diff options
author | Thomas White <taw@physics.org> | 2019-02-18 16:56:52 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-03-11 16:49:37 +0100 |
commit | a2f4977e0f8bd9becd50ab5a2ef903038273133c (patch) | |
tree | e754341a53aa89f821a5fc6a39bc6d34fb2a3806 /libcrystfel/src/symop.y | |
parent | 169e7c5677ffc9c296c0a7eeddb0b77e024a4a55 (diff) |
Implement parse_symmetry_operations
Diffstat (limited to 'libcrystfel/src/symop.y')
-rw-r--r-- | libcrystfel/src/symop.y | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/libcrystfel/src/symop.y b/libcrystfel/src/symop.y index 4aec791a..a304ea37 100644 --- a/libcrystfel/src/symop.y +++ b/libcrystfel/src/symop.y @@ -30,15 +30,20 @@ #include <stdio.h> #include "rational.h" + #include "symmetry.h" extern int symoplex(); - extern int symopparse(RationalMatrix *m); - void symoperror(RationalMatrix *m, const char *s); + extern int symopparse(RationalMatrix *m, SymOpList *list); + void symoperror(RationalMatrix *m, SymOpList *list, const char *s); %} %define api.prefix {symop} -%parse-param {RationalMatrix *m} +%parse-param {RationalMatrix *m} {SymOpList *list} + +%code requires { + #include "symmetry.h" +} %union { RationalMatrix *m; /* Full rational matrix */ @@ -47,6 +52,7 @@ int n; /* Just a number */ } +%token SEMICOLON %token COMMA %token NUMBER %token OPENB CLOSEB @@ -63,8 +69,33 @@ %type <n> NUMBER %type <r> fraction +%{ +static int try_add_symop(SymOpList *list, RationalMatrix *m) +{ + if ( list == NULL ) { + yyerror(m, list, "Must be a single symmetry operation"); + return 1; + } else { + IntegerMatrix *im; + im = intmat_from_rtnl_mtx(m); + if ( im == NULL ) { + yyerror(m, list, "Symmetry operations must all be integer"); + return 1; + } else { + add_symop(list, im); + } + } + return 0; +} +%} + %% +symoplist: + symop { if ( try_add_symop(list, m) ) YYERROR; } +| symoplist SEMICOLON symop { if ( try_add_symop(list, m) ) YYERROR; } +; + symop: axexpr COMMA axexpr COMMA axexpr { rtnl_mtx_set(m, 0, 0, $1[0]); rtnl_mtx_set(m, 0, 1, $1[1]); @@ -101,6 +132,6 @@ fraction: %% -void symoperror(RationalMatrix *m, const char *s) { - printf("Error\n"); +void symoperror(RationalMatrix *m, SymOpList *list, const char *s) { + printf("Error: %s\n", s); } |