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

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

Added MeshViewer new project, its goal being to have a program capable of previewing a mesh from an outer source (.txt, js, etc ...) in order to speed up mesh creation.
Added RadialJitter("rj") to EasyMesh parser.

File size: 4.3 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; }
77csga  { return token::T_CSGAND; }
78csgx  { return token::T_CSGXOR; }
79
80ab    { return token::T_BOX; }
81ac    { return token::T_CYLINDER; }
82acap  { return token::T_CAPSULE; }
83acg   { return token::T_COG; }
84ad    { return token::T_DISC; }
85aes   { return token::T_EXPANDEDSTAR; }
86afcb  { return token::T_FLATCHAMFBOX; }
87aq    { return token::T_QUAD; }
88as    { return token::T_STAR; }
89ascb  { return token::T_SMOOTHCHAMFBOX; }
90asph  { return token::T_SPHERE; }
91at    { return token::T_TRIANGLE; }
92ato   { return token::T_TORUS; }
93
94#[0-9a-fA-F]{3} {
95        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
96        yylval->u32val = 0x11000000u * (tmp >> 8)
97                       | 0x00110000u * ((tmp >> 4) & 0xf)
98                       | 0x00001100u * (tmp & 0xf)
99                       | 0x000000ffu;
100        return token::COLOR; }
101#[0-9a-fA-F]{4} {
102        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
103        yylval->u32val = 0x11000000u * (tmp >> 12)
104                       | 0x00110000u * ((tmp >> 8) & 0xf)
105                       | 0x00001100u * ((tmp >> 4) & 0xf)
106                       | 0x00000011u * (tmp & 0xf);
107        return token::COLOR; }
108#[0-9a-fA-F]{6} {
109        yylval->u32val = 0xffu
110                       | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
111        return token::COLOR; }
112#[0-9a-fA-F]{8} {
113        yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
114        return token::COLOR; }
115[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
116        yylval->fval = std::atof(yytext); return token::NUMBER; }
117-     { return token_type('-'); }
118"["   { return token_type('['); }
119"]"   { return token_type(']'); }
120[ ,]  { /* ignore this */ }
121[\n]  { /* ignore this */ }
122.     { return token::T_ERROR; }
123
124%%
125
126lol::EasyMeshScanner::EasyMeshScanner(char const *command)
127    : EasyMeshFlexLexer(0, 0),
128      m_input(command)
129{
130}
131
132lol::EasyMeshScanner::~EasyMeshScanner()
133{
134}
135
136int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
137{
138    (void)max_size; /* unused for now */
139
140    buf[0] = m_input[0];
141    if (buf[0])
142        ++m_input;
143    return buf[0] ? 1 : 0;
144}
145
146#ifdef yylex
147#undef yylex
148#endif
149int EasyMeshFlexLexer::yylex()
150{
151    std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
152    return 0;
153}
154
155int EasyMeshFlexLexer::yywrap()
156{
157    return 1;
158}
159
Note: See TracBrowser for help on using the repository browser.