KiCad PCB EDA Suite
dsnlexer.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <dsnlexer.h>
#include <wx/translation.h>

Go to the source code of this file.

Macros

#define FMT_CLIPBOARD   _( "clipboard" )
 

Functions

static bool isSpace (char cc)
 Test for whitespace. More...
 
bool isDigit (char cc)
 
bool isSep (char cc)
 
static bool isNumber (const char *cp, const char *limit)
 Return 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

◆ FMT_CLIPBOARD

#define FMT_CLIPBOARD   _( "clipboard" )

Definition at line 35 of file dsnlexer.cpp.

Function Documentation

◆ isDigit()

bool isDigit ( char  cc)
inline
Returns
true if cc is an s-expression separator character.

Definition at line 443 of file dsnlexer.cpp.

Referenced by isNumber(), and NET_SETTINGS::ParseBusVector().

◆ isNumber()

static bool isNumber ( const char *  cp,
const char *  limit 
)
static

Return 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
true if input token is a number, else false.

Definition at line 465 of file dsnlexer.cpp.

466 {
467  // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
468  // code traversal manually here:
469 
470  bool sawNumber = false;
471 
472  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
473  ++cp;
474 
475  while( cp < limit && isDigit( *cp ) )
476  {
477  ++cp;
478  sawNumber = true;
479  }
480 
481  if( cp < limit && *cp == '.' )
482  {
483  ++cp;
484 
485  while( cp < limit && isDigit( *cp ) )
486  {
487  ++cp;
488  sawNumber = true;
489  }
490  }
491 
492  if( sawNumber )
493  {
494  if( cp < limit && ( *cp=='E' || *cp=='e' ) )
495  {
496  ++cp;
497 
498  sawNumber = false; // exponent mandates at least one digit thereafter.
499 
500  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
501  ++cp;
502 
503  while( cp < limit && isDigit( *cp ) )
504  {
505  ++cp;
506  sawNumber = true;
507  }
508  }
509  }
510 
511  return sawNumber && cp==limit;
512 }
bool isDigit(char cc)
Definition: dsnlexer.cpp:443

References isDigit().

Referenced by DSNLEXER::NextTok().

◆ isSep()

bool isSep ( char  cc)
inline

Definition at line 450 of file dsnlexer.cpp.

451 {
452  return isSpace( cc ) || cc=='(' || cc==')';
453 }
static bool isSpace(char cc)
Test for whitespace.
Definition: dsnlexer.cpp:422

References isSpace().

Referenced by DSNLEXER::NextTok().

◆ isSpace()

static bool isSpace ( char  cc)
static

Test 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 422 of file dsnlexer.cpp.

423 {
424  // cc is signed, so it is often negative.
425  // Treat negative as large positive to exclude rapidly.
426  if( (unsigned char) cc <= ' ' )
427  {
428  switch( (unsigned char) cc )
429  {
430  case ' ':
431  case '\n':
432  case '\r':
433  case '\t':
434  case '\0': // PCAD s-expression files have this.
435  return true;
436  }
437  }
438 
439  return false;
440 }

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

Variable Documentation

◆ empty_keywords

const KEYWORD empty_keywords[1] = {}
static

Definition at line 121 of file dsnlexer.cpp.