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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "parser-wavefront-obj.h"
  9. #define TOKEN(type) \
  10. TOK_##type
  11. %}
  12. %option noyywrap
  13. %option prefix="wavefront_obj"
  14. %%
  15. /* Whitespace */
  16. [ \t]+ { }
  17. /* Newline */
  18. \n|\n\r { ++wavefront_objlineno; }
  19. /* Comment */
  20. "#"[^\n\r]* { }
  21. /* Material library */
  22. "mtllib" { return TOKEN(MTLLIB); }
  23. /* Use material */
  24. "usemtl" { return TOKEN(USEMTL); }
  25. /* Named object */
  26. "o" { return TOKEN(O); }
  27. /* Vertex */
  28. "v" { return TOKEN(V); }
  29. /* Texture coordinate */
  30. "vt" { return TOKEN(VT); }
  31. /* Vertex normal */
  32. "vn" { return TOKEN(VN); }
  33. /* Parameter space vertices */
  34. "vp" { return TOKEN(VP); }
  35. /* Face */
  36. "f" { return TOKEN(F); }
  37. /* Smooth */
  38. "s" { return TOKEN(S); }
  39. /* Slash */
  40. "/" { return TOKEN(SLASH); }
  41. /* Number */
  42. -?[0-9]+(.[0-9]+)? { wavefront_objlval.number=atof(yytext); return TOKEN(NUMBER); }
  43. /* String */
  44. [^\n\r\t ]+ { wavefront_objlval.string = strcpy((char*)malloc(strlen(yytext)), yytext); return TOKEN(STRING); }
  45. %%