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
Line 
1%{
2//
3// Lol Engine
4//
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>
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
11//   http://www.wtfpl.net/ for more details.
12//
13
14#if defined HAVE_CONFIG_H
15#   include "config.h"
16#endif
17
18#include <cstdlib>
19using std::exit;
20using std::malloc;
21using std::realloc;
22using std::free;
23
24#include "core.h"
25#include "easymesh/easymesh-compiler.h"
26
27typedef lol::EasyMeshParser::token token;
28typedef lol::EasyMeshParser::token_type token_type;
29
30#ifndef YY_DECL
31#   define YY_DECL lol::EasyMeshParser::token_type \
32        lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \
33                                  lol::EasyMeshParser::location_type* yylloc)
34#endif
35
36#define yyterminate() return token::T_END
37#define YY_NO_UNISTD_H
38#define YY_USER_ACTION yylloc->columns(yyleng);
39%}
40
41%option c++ prefix="EasyMesh"
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
54ch    { return token::T_CHAMFER; }
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; }
69tsw   { return token::T_TOGGLESCALEWINDING; }
70mx    { return token::T_MIRRORX; }
71my    { return token::T_MIRRORY; }
72mz    { return token::T_MIRRORZ; }
73rj    { return token::T_RADIALJITTER; }
74
75csgu  { return token::T_CSGUNION; }
76csgs  { return token::T_CSGSUBSTRACT; }
77csgsl { return token::T_CSGSUBSTRACTLOSS; }
78csga  { return token::T_CSGAND; }
79csgx  { return token::T_CSGXOR; }
80
81ab    { return token::T_BOX; }
82ac    { return token::T_CYLINDER; }
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; }
90ascb  { return token::T_SMOOTHCHAMFBOX; }
91asph  { return token::T_SPHERE; }
92at    { return token::T_TRIANGLE; }
93ato   { return token::T_TORUS; }
94
95#[0-9a-fA-F]{3} {
96        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
97        yylval->u32val = 0x11000000u * (tmp >> 8)
98                       | 0x00110000u * ((tmp >> 4) & 0xf)
99                       | 0x00001100u * (tmp & 0xf)
100                       | 0x000000ffu;
101        return token::COLOR; }
102#[0-9a-fA-F]{4} {
103        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
104        yylval->u32val = 0x11000000u * (tmp >> 12)
105                       | 0x00110000u * ((tmp >> 8) & 0xf)
106                       | 0x00001100u * ((tmp >> 4) & 0xf)
107                       | 0x00000011u * (tmp & 0xf);
108        return token::COLOR; }
109#[0-9a-fA-F]{6} {
110        yylval->u32val = 0xffu
111                       | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
112        return token::COLOR; }
113#[0-9a-fA-F]{8} {
114        yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
115        return token::COLOR; }
116[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
117        yylval->fval = std::atof(yytext); return token::NUMBER; }
118-     { return token_type('-'); }
119"["   { return token_type('['); }
120"]"   { return token_type(']'); }
121[ ,]  { /* ignore this */ }
122[\n]  { /* ignore this */ }
123.     { return token::T_ERROR; }
124
125%%
126
127lol::EasyMeshScanner::EasyMeshScanner(char const *command)
128    : EasyMeshFlexLexer(0, 0),
129      m_input(command)
130{
131}
132
133lol::EasyMeshScanner::~EasyMeshScanner()
134{
135}
136
137int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
138{
139    (void)max_size; /* unused for now */
140
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
150int EasyMeshFlexLexer::yylex()
151{
152    std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
153    return 0;
154}
155
156int EasyMeshFlexLexer::yywrap()
157{
158    return 1;
159}
160
Note: See TracBrowser for help on using the repository browser.