You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lexer-wavefront-obj.l 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. %{
  2. // In this section we can add all needed headers, from Qt or another libraries.
  3. //#include <QtScript>
  4. #include <QVariant>
  5. #include <QDebug>
  6. // Also, we must add the parser's header where are defined the tokens.
  7. #include "utils/vector3d.h"
  8. #include "utils/wavefrontobj.h"
  9. #include "parser-wavefront-obj.h"
  10. #define TOKEN(type) \
  11. TOK_WFOBJ_##type
  12. %}
  13. %option noyywrap
  14. %option nounput
  15. %option prefix="wavefront_obj"
  16. %%
  17. /* Whitespace */
  18. [ \t]+ { }
  19. /* Newline */
  20. \n|\n\r { ++wavefront_objlineno; }
  21. /* Comment */
  22. "#"[^\n\r]* { }
  23. /* Material library */
  24. "mtllib" { return TOKEN(MTLLIB); }
  25. /* Use material */
  26. "usemtl" { return TOKEN(USEMTL); }
  27. /* Named object */
  28. "o" { return TOKEN(O); }
  29. /* Vertex */
  30. "v" { return TOKEN(V); }
  31. /* Texture coordinate */
  32. "vt" { return TOKEN(VT); }
  33. /* Vertex normal */
  34. "vn" { return TOKEN(VN); }
  35. /* Parameter space vertices */
  36. "vp" { return TOKEN(VP); }
  37. /* Face */
  38. "f" { return TOKEN(F); }
  39. /* Smooth */
  40. "s" { return TOKEN(S); }
  41. /* Slash */
  42. "/" { return TOKEN(SLASH); }
  43. /* Number */
  44. -?[0-9]+(.[0-9]+)? { wavefront_objlval.number=atof(yytext); return TOKEN(NUMBER); }
  45. /* String */
  46. [^\n\r\t ]+ { wavefront_objlval.string = strcpy((char*)malloc(strlen(yytext) + 1), yytext); return TOKEN(STRING); }
  47. %%