KiCad PCB EDA Suite
dsnlexer.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <macros.h>
#include <fctsys.h>
#include <dsnlexer.h>

Go to the source code of this file.

Macros

#define FMT_CLIPBOARD   _( "clipboard" )
 

Functions

static bool isSpace (char cc)
 Function isSpace tests for whitespace. More...
 
bool isDigit (char cc)
 
bool isSep (char cc)
 return true if cc is an s-expression separator character More...
 
static bool isNumber (const char *cp, const char *limit)
 Function isNumber returns true if the next sequence of text is a number: either an integer, fixed point, or float with exponent. More...
 

Variables

static const KEYWORD empty_keywords [1] = {}
 

Macro Definition Documentation

#define FMT_CLIPBOARD   _( "clipboard" )

Definition at line 39 of file dsnlexer.cpp.

Referenced by DSNLEXER::DSNLEXER().

Function Documentation

bool isDigit ( char  cc)
inline

Definition at line 467 of file dsnlexer.cpp.

Referenced by isNumber().

468 {
469  return '0' <= cc && cc <= '9';
470 }
static bool isNumber ( const char *  cp,
const char *  limit 
)
static

Function isNumber returns true if the next sequence of text is a number: either an integer, fixed point, or float with exponent.

Stops scanning at the first non-number character, even if it is not whitespace.

Parameters
cpis the start of the current token.
limitis the end of the current token.
Returns
bool - true if input token is a number, else false.

Definition at line 491 of file dsnlexer.cpp.

References isDigit().

Referenced by DSNLEXER::NextTok().

492 {
493  // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
494  // code traversal manually here:
495 
496  bool sawNumber = false;
497 
498  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
499  ++cp;
500 
501  while( cp < limit && isDigit( *cp ) )
502  {
503  ++cp;
504  sawNumber = true;
505  }
506 
507  if( cp < limit && *cp == '.' )
508  {
509  ++cp;
510 
511  while( cp < limit && isDigit( *cp ) )
512  {
513  ++cp;
514  sawNumber = true;
515  }
516  }
517 
518  if( sawNumber )
519  {
520  if( cp < limit && ( *cp=='E' || *cp=='e' ) )
521  {
522  ++cp;
523 
524  sawNumber = false; // exponent mandates at least one digit thereafter.
525 
526  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
527  ++cp;
528 
529  while( cp < limit && isDigit( *cp ) )
530  {
531  ++cp;
532  sawNumber = true;
533  }
534  }
535  }
536 
537  return sawNumber && cp==limit;
538 }
bool isDigit(char cc)
Definition: dsnlexer.cpp:467
bool isSep ( char  cc)
inline

return true if cc is an s-expression separator character

Definition at line 474 of file dsnlexer.cpp.

References isSpace().

Referenced by DSNLEXER::NextTok().

475 {
476  return isSpace( cc ) || cc=='(' || cc==')';
477 }
static bool isSpace(char cc)
Function isSpace tests for whitespace.
Definition: dsnlexer.cpp:447
static bool isSpace ( char  cc)
static

Function isSpace tests for whitespace.

Our whitespace, by our definition, is a subset of ASCII, i.e. no bytes with MSB on can be considered whitespace, since they are likely part of a multibyte UTF8 character.

Definition at line 447 of file dsnlexer.cpp.

Referenced by isSep(), and DSNLEXER::NextTok().

448 {
449  // cc is signed, so it is often negative.
450  // Treat negative as large positive to exclude rapidly.
451  if( (unsigned char) cc <= ' ' )
452  {
453  switch( (unsigned char) cc )
454  {
455  case ' ':
456  case '\n':
457  case '\r':
458  case '\t':
459  case '\0': // PCAD s-expression files have this.
460  return true;
461  }
462  }
463  return false;
464 }

Variable Documentation

const KEYWORD empty_keywords[1] = {}
static

Definition at line 125 of file dsnlexer.cpp.