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 454 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 476 of file dsnlexer.cpp.

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

References isDigit().

Referenced by DSNLEXER::NextTok().

◆ isSep()

bool isSep ( char  cc)
inline

Definition at line 461 of file dsnlexer.cpp.

462 {
463  return isSpace( cc ) || cc=='(' || cc==')';
464 }
static bool isSpace(char cc)
Test for whitespace.
Definition: dsnlexer.cpp:433

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

434 {
435  // cc is signed, so it is often negative.
436  // Treat negative as large positive to exclude rapidly.
437  if( (unsigned char) cc <= ' ' )
438  {
439  switch( (unsigned char) cc )
440  {
441  case ' ':
442  case '\n':
443  case '\r':
444  case '\t':
445  case '\0': // PCAD s-expression files have this.
446  return true;
447  }
448  }
449 
450  return false;
451 }

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

Variable Documentation

◆ empty_keywords

const KEYWORD empty_keywords[1] = {}
static

Definition at line 121 of file dsnlexer.cpp.