source: trunk/src/easymesh/easymesh-scanner.l @ 2350

Last change on this file since 2350 was 2350, checked in by touky, 7 years ago

easymesh : CSG operation is now handled with a safe enum.

File size: 4.4 KB
RevLine 
[1419]1%{
2//
[1510]3// Lol Engine
[1419]4//
[2226]5// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
6//            (c) 2009-2013 Cédric Lecacheur <jordx@free.fr>
7//            (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
[1510]8//   This program is free software; you can redistribute it and/or
9//   modify it under the terms of the Do What The Fuck You Want To
10//   Public License, Version 2, as published by Sam Hocevar. See
[2183]11//   http://www.wtfpl.net/ for more details.
[1419]12//
13
[1425]14#if defined HAVE_CONFIG_H
15#   include "config.h"
16#endif
17
[1512]18#include <cstdlib>
19using std::exit;
20using std::malloc;
21using std::realloc;
22using std::free;
23
[1425]24#include "core.h"
[1510]25#include "easymesh/easymesh-compiler.h"
[1425]26
[1510]27typedef lol::EasyMeshParser::token token;
28typedef lol::EasyMeshParser::token_type token_type;
[1425]29
[1424]30#ifndef YY_DECL
[1510]31#   define YY_DECL lol::EasyMeshParser::token_type \
32        lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \
33                                  lol::EasyMeshParser::location_type* yylloc)
[1424]34#endif
35
[1419]36#define yyterminate() return token::T_END
37#define YY_NO_UNISTD_H
38#define YY_USER_ACTION yylloc->columns(yyleng);
39%}
40
[1510]41%option c++ prefix="EasyMesh"
[1419]42%option batch yywrap nounput stack
43
44%%
45
46%{
47    /* reset location at the beginning of yylex() */
48    yylloc->step();
49%}
50
51sc    { return token::T_COLOR; }
52scb   { return token::T_BGCOLOR; }
53
[1506]54ch    { return token::T_CHAMFER; }
[1419]55tx    { return token::T_TRANSLATEX; }
56ty    { return token::T_TRANSLATEY; }
57tz    { return token::T_TRANSLATEZ; }
58t     { return token::T_TRANSLATE; }
59rx    { return token::T_ROTATEX; }
60ry    { return token::T_ROTATEY; }
61rz    { return token::T_ROTATEZ; }
62tax   { return token::T_TAPERX; }
63tay   { return token::T_TAPERY; }
64taz   { return token::T_TAPERZ; }
65sx    { return token::T_SCALEX; }
66sy    { return token::T_SCALEY; }
67sz    { return token::T_SCALEZ; }
68s     { return token::T_SCALE; }
[2294]69tsw   { return token::T_TOGGLESCALEWINDING; }
[1419]70mx    { return token::T_MIRRORX; }
71my    { return token::T_MIRRORY; }
72mz    { return token::T_MIRRORZ; }
[2294]73rj    { return token::T_RADIALJITTER; }
[1419]74
[2226]75csgu  { return token::T_CSGUNION; }
76csgs  { return token::T_CSGSUBSTRACT; }
[2350]77csgsl { return token::T_CSGSUBSTRACTLOSS; }
[2226]78csga  { return token::T_CSGAND; }
79csgx  { return token::T_CSGXOR; }
80
[1910]81ab    { return token::T_BOX; }
[1419]82ac    { return token::T_CYLINDER; }
[1910]83acap  { return token::T_CAPSULE; }
84acg   { return token::T_COG; }
85ad    { return token::T_DISC; }
86aes   { return token::T_EXPANDEDSTAR; }
87afcb  { return token::T_FLATCHAMFBOX; }
88aq    { return token::T_QUAD; }
89as    { return token::T_STAR; }
[1419]90ascb  { return token::T_SMOOTHCHAMFBOX; }
91asph  { return token::T_SPHERE; }
92at    { return token::T_TRIANGLE; }
[1910]93ato   { return token::T_TORUS; }
[1419]94
[1738]95#[0-9a-fA-F]{3} {
[1512]96        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
[1495]97        yylval->u32val = 0x11000000u * (tmp >> 8)
98                       | 0x00110000u * ((tmp >> 4) & 0xf)
99                       | 0x00001100u * (tmp & 0xf)
100                       | 0x000000ffu;
[1430]101        return token::COLOR; }
[1738]102#[0-9a-fA-F]{4} {
[1512]103        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
[1495]104        yylval->u32val = 0x11000000u * (tmp >> 12)
105                       | 0x00110000u * ((tmp >> 8) & 0xf)
106                       | 0x00001100u * ((tmp >> 4) & 0xf)
107                       | 0x00000011u * (tmp & 0xf);
[1430]108        return token::COLOR; }
[1738]109#[0-9a-fA-F]{6} {
[1495]110        yylval->u32val = 0xffu
[1512]111                       | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
[1495]112        return token::COLOR; }
[1738]113#[0-9a-fA-F]{8} {
[1512]114        yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
[1495]115        return token::COLOR; }
[1419]116[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
[1512]117        yylval->fval = std::atof(yytext); return token::NUMBER; }
[1419]118-     { return token_type('-'); }
[1434]119"["   { return token_type('['); }
120"]"   { return token_type(']'); }
[1442]121[ ,]  { /* ignore this */ }
122[\n]  { /* ignore this */ }
123.     { return token::T_ERROR; }
[1419]124
125%%
126
[1510]127lol::EasyMeshScanner::EasyMeshScanner(char const *command)
128    : EasyMeshFlexLexer(0, 0),
[1419]129      m_input(command)
130{
131}
132
[1510]133lol::EasyMeshScanner::~EasyMeshScanner()
[1419]134{
135}
136
[1510]137int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
[1419]138{
[1808]139    (void)max_size; /* unused for now */
140
[1419]141    buf[0] = m_input[0];
142    if (buf[0])
143        ++m_input;
144    return buf[0] ? 1 : 0;
145}
146
147#ifdef yylex
148#undef yylex
149#endif
[1510]150int EasyMeshFlexLexer::yylex()
[1419]151{
[1510]152    std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
[1419]153    return 0;
154}
155
[1510]156int EasyMeshFlexLexer::yywrap()
[1419]157{
158    return 1;
159}
160
Note: See TracBrowser for help on using the repository browser.