Commit ed8c021f authored by Dick Hollenbeck's avatar Dick Hollenbeck

++all:

  * TokenList2DsnLexer.cmake now supports comments, which start with a leading
    # character, and may be either on their own line or on a line after a token.
  * DSNLEXER::PopReader() now pops even the last LINE_READER* and returns it.
++pcbnew:
  * SPECCTRA_DB now inherits from new class SPECCTRA_LEXER, which led to a great
    deal of simplification and code factoring.
  * Moved specctra keywords into specctra.keywords.
parent 42b9e0e6
......@@ -17,6 +17,8 @@ install_manifest.txt
Documentation/doxygen
*.cmake
*.bak
pcbnew/specctra_keywords.cpp
pcbnew/specctra_lexer.h
new/html
new/sch_lib_table_keywords.cpp
new/sch_lib_table_lexer.h
......
......@@ -4,6 +4,17 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.
2011-Jan-19 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all:
* TokenList2DsnLexer.cmake now supports comments, which start with a leading
# character, and may be either on their own line or on a line after a token.
* DSNLEXER::PopReader() now pops even the last LINE_READER* and returns it.
++pcbnew:
* SPECCTRA_DB now inherits from new class SPECCTRA_LEXER, which led to a great
deal of simplification and code factoring.
* Moved specctra keywords into specctra.keywords.
2011-Jan-17 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all:
......
#
# This program source code file is part of KICAD, a free EDA CAD application.
#
# Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
......@@ -160,26 +160,33 @@ const KEYWORD ${LEXERCLASS}::keywords[] = {
"
)
file( STRINGS ${inputFile} tmpTokens NO_HEX_CONVERSION )
file( STRINGS ${inputFile} lines NO_HEX_CONVERSION )
foreach( tmpToken ${tmpTokens} )
foreach( line ${lines} )
math( EXPR lineCount "${lineCount} + 1" )
string( STRIP tmpToken "${tmpToken}" )
# strip any comment from # to end of line
string( REGEX REPLACE "#.*$" "" tmpToken "${line}" )
string( STRIP "${tmpToken}" token )
# Ignore empty lines.
if( tmpToken )
if( NOT token STREQUAL "" ) # if token is "off" simple if( token) does not work
# Make sure token is valid.
string( REGEX MATCH "[a-z][_0-9a-z]*[0-9a-z]$" validToken "${tmpToken}" )
if( validToken STREQUAL tmpToken )
#message( "token=${token}" )
string( REGEX MATCH "[a-z][_0-9a-z]*" validToken "${token}" )
#message( "validToken=${validToken}" )
if( validToken STREQUAL token )
list( APPEND tokens "${validToken}" )
else( validToken STREQUAL tmpToken )
else()
message( FATAL_ERROR
"Invalid token string \"${tmpToken}\" at line ${lineCount} in file "
"<${inputFile}>." )
endif( validToken STREQUAL tmpToken )
endif( tmpToken )
endforeach( tmpToken ${tmpTokens} )
endif()
endif()
endforeach()
list( SORT tokens )
......@@ -190,7 +197,7 @@ list( LENGTH tokens tokensAfter )
if( NOT ( tokensBefore EQUAL tokensAfter ) )
message( FATAL_ERROR "Duplicate tokens found in file <${inputFile}>." )
endif( NOT ( tokensBefore EQUAL tokensAfter ) )
endif()
file( WRITE "${outHeaderFile}" "${includeFileHeader}" )
file( WRITE "${outCppFile}" "${sourceFileHeader}" )
......@@ -214,7 +221,7 @@ foreach( token ${tokens} )
file( APPEND "${outCppFile}" ",\n" )
endif( lineCount EQUAL tokensAfter )
math( EXPR lineCount "${lineCount} + 1" )
endforeach( token ${tokens} )
endforeach()
file( APPEND "${outHeaderFile}"
" };
......@@ -275,6 +282,12 @@ public:
{
}
/**
* Function TokenName
* returns the name of the token in ASCII form.
*/
static const char* TokenName( ${enum}::T aTok );
/**
* Function NextTok
* returns the next token found in the input file or T_EOF when reaching
......@@ -356,5 +369,23 @@ file( APPEND "${outCppFile}"
const unsigned ${LEXERCLASS}::keyword_count = unsigned( sizeof( ${LEXERCLASS}::keywords )/sizeof( ${LEXERCLASS}::keywords[0] ) );
const char* ${LEXERCLASS}::TokenName( T aTok )
{
const char* ret;
if( (unsigned) aTok < keyword_count )
{
ret = keywords[aTok].name;
}
else if( aTok < 0 )
{
return DSNLEXER::Syntax( aTok );
}
else
ret = \"token too big\";
return ret;
}
"
)
......@@ -91,6 +91,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
keywords( aKeywordTable ),
keywordCount( aKeywordCount )
{
if( aLineReader )
PushReader( aLineReader );
init();
}
......@@ -119,22 +120,33 @@ void DSNLEXER::PushReader( LINE_READER* aLineReader )
}
bool DSNLEXER::PopReader()
LINE_READER* DSNLEXER::PopReader()
{
// the very last reader cannot be popped, for that would screw up limit and next.
if( readerStack.size() >= 2 )
LINE_READER* ret = 0;
if( readerStack.size() )
{
ret = reader;
readerStack.pop_back();
if( readerStack.size() )
{
reader = readerStack.back();
start = (const char*) (*reader);
start = reader->Line();
// force a new readLine() as first thing.
limit = start;
next = start;
return true;
}
return false;
else
{
reader = 0;
start = dummy;
limit = dummy;
limit = dummy;
}
}
return ret;
}
......@@ -198,7 +210,7 @@ const char* DSNLEXER::Syntax( int aTok )
ret = "quoted string";
break;
case DSN_EOF:
ret = "end of file";
ret = "end of input";
break;
default:
ret = "???";
......@@ -257,10 +269,10 @@ void DSNLEXER::Expecting( int aTok ) throw( IO_ERROR )
}
void DSNLEXER::Expecting( const wxString& text ) throw( IO_ERROR )
void DSNLEXER::Expecting( const char* text ) throw( IO_ERROR )
{
wxString errText( _("Expecting") );
errText << wxT(" '") << text << wxT("'");
errText << wxT(" '") << wxString::FromUTF8( text ) << wxT("'");
THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
......@@ -272,6 +284,7 @@ void DSNLEXER::Unexpected( int aTok ) throw( IO_ERROR )
THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
{
wxString errText;
......@@ -280,10 +293,11 @@ void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
void DSNLEXER::Unexpected( const wxString& text ) throw( IO_ERROR )
void DSNLEXER::Unexpected( const char* text ) throw( IO_ERROR )
{
wxString errText( _("Unexpected") );
errText << wxT(" '") << text << wxT("'");
errText << wxT(" '") << wxString::FromUTF8( text ) << wxT("'");
THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
......@@ -317,7 +331,7 @@ int DSNLEXER::NeedSYMBOLorNUMBER() throw( IO_ERROR )
{
int tok = NextTok();
if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
Expecting( _("symbol|number") );
Expecting( "symbol|number" );
return tok;
}
......
......@@ -79,7 +79,7 @@ void TEMPLATE_FIELDNAME::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR
break;
default:
in->Expecting( wxT( "value|visible" ) );
in->Expecting( "value|visible" );
break;
}
}
......@@ -129,7 +129,7 @@ void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR )
break;
default:
in->Unexpected( CONV_FROM_UTF8( in->CurText() ) );
in->Unexpected( in->CurText() );
break;
}
}
......
......@@ -76,10 +76,12 @@ enum DSN_SYNTAX_T {
*/
class DSNLEXER
{
protected:
bool iOwnReaders; ///< on readerStack, should I delete them?
const char* start;
const char* next;
const char* limit;
char dummy[1]; ///< when there is no reader.
typedef std::vector<LINE_READER*> READER_STACK;
......@@ -102,18 +104,22 @@ class DSNLEXER
void init();
int readLine() throw( IO_ERROR )
{
if( reader )
{
unsigned len = reader->ReadLine();
// start may have changed in ReadLine(), which can resize and
// relocate reader's line buffer.
start = (*reader);
start = reader->Line();
next = start;
limit = next + len;
return len;
}
return 0;
}
/**
......@@ -220,10 +226,11 @@ public:
* possible if there are at least 2 LINE_READERs on the stack, since popping
* the last one is not supported.
*
* @return bool - true if there was at least two readers on the stack and
* therefore the pop succeeded, else false and the pop failed.
* @return LINE_READER* - is the one that was in use before the pop, or NULL
* if there was not at least two readers on the stack and therefore the
* pop failed.
*/
bool PopReader();
LINE_READER* PopReader();
// Some functions whose return value is best overloaded to return an enum
// in a derived class.
......@@ -341,11 +348,11 @@ public:
/**
* Function Expecting
* throws an IO_ERROR exception with an input file specific error message.
* @param aErrorMsg is the token/keyword type which was expected at the
* current input location.
* @param aTokenList is the token/keyword type which was expected at the
* current input location, e.g. "pin|graphic|property"
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Expecting( const wxString& aErrorMsg ) throw( IO_ERROR );
void Expecting( const char* aTokenList ) throw( IO_ERROR );
/**
* Function Unexpected
......@@ -369,11 +376,11 @@ public:
/**
* Function Unexpected
* throws an IO_ERROR exception with an input file specific error message.
* @param aErrorMsg is the token/keyword type which was not expected at the
* @param aToken is the token which was not expected at the
* current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Unexpected( const wxString& aErrorMsg ) throw( IO_ERROR );
void Unexpected( const char* aToken ) throw( IO_ERROR );
/**
* Function NeedLEFT
......
......@@ -171,6 +171,7 @@ set(PCBNEW_SRCS
specctra.cpp
specctra_export.cpp
specctra_import.cpp
specctra_keywords.cpp
surbrill.cpp
swap_layers.cpp
tool_modedit.cpp
......@@ -245,6 +246,16 @@ set_source_files_properties( dialogs/dialog_freeroute_exchange.cpp
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/dialog_freeroute_exchange_help_html.h
)
# auto-generate specctra_lexer.h and specctra_keywords.cpp
make_lexer(
${CMAKE_CURRENT_SOURCE_DIR}/specctra.keywords
${CMAKE_CURRENT_SOURCE_DIR}/specctra_lexer.h
${CMAKE_CURRENT_SOURCE_DIR}/specctra_keywords.cpp
DSN
)
###
# Create the pcbnew executable
###
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
# Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
# These are keywords for the Specctra DSN (s-expression) lexer and parser.
absolute
added
add_group
add_pins
allow_antenna
allow_redundant_wiring
amp
ancestor
antipad
aperture_type
array
attach
attr
average_pair_length
back
base_design
bbv_ctr2ctr
bend_keepout
bond
both
bottom
bottom_layer_sel
boundary
brickpat
bundle
bus
bypass
capacitance_resolution
capacitor
case_sensitive
cct1
cct1a
center_center
checking_trim_by_pin
circ
circle
circuit
class
class_class
classes
clear
clearance
cluster
cm
color
colors
comment
comp
comp_edge_center
comp_order
component
composite
conductance_resolution
conductor
conflict
connect
constant
contact
control
corner
corners
cost
created_time
cross
crosstalk_model
current_resolution
delete_pins
deleted
deleted_keepout
delta
diagonal
direction
directory
discrete
effective_via_length
elongate_keepout
exclude
expose
extra_image_directory
family
family_family
family_family_spacing
fanout
farad
file
fit
fix
flip_style
floor_plan
footprint
forbidden
force_to_terminal_point
forgotten
free
fromto
front
front_only
gap
gate
gates
generated_by_freeroute
global
grid
group
group_set
guide
hard
height
high
history
horizontal
host_cad
host_version
image
image_conductor
image_image
image_image_spacing
image_outline_clearance
image_set
image_type
inch
include
include_pins_in_crosstalk
inductance_resolution
insert
instcnfg
inter_layer_clearance
jumper
junction_type
keepout
kg
kohm
large
large_large
layer
layer_depth
layer_noise_weight
layer_pair
layer_rule
length
length_amplitude
length_factor
length_gap
library
library_out
limit
limit_bends
limit_crossing
limit_vias
limit_way
linear
linear_interpolation
load
lock_type
logical_part
logical_part_mapping
low
match_fromto_delay
match_fromto_length
match_group_delay
match_group_length
match_net_delay
match_net_length
max_delay
max_len
max_length
max_noise
max_restricted_layer_length
max_stagger
max_stub
max_total_delay
max_total_length
max_total_vias
medium
mhenry
mho
microvia
mid_driven
mil
min_gap
mirror
mirror_first
mixed
mm
negative_diagonal
net
net_number
net_out
net_pin_changes
nets
network
network_out
no
noexpose
noise_accumulation
noise_calculation
normal
object_type
off
off_grid
offset
on
open
opposite_side
order
orthogonal
outline
overlap
pad
pad_pad
padstack
pair
parallel
parallel_noise
parallel_segment
parser
part_library
path
pcb
permit_orient
permit_side
physical
physical_part_mapping
piggyback
pin
pin_allow
pin_cap_via
pin_via_cap
pin_width_taper
pins
pintype
place
place_boundary
place_control
place_keepout
place_rule
placement
plan
plane
pn
point
polyline_path
polygon
position
positive_diagonal
power
power_dissipation
power_fanout
prefix
primary
priority
property
protect
qarc
quarter
radius
ratio
ratio_tolerance
rect
reduced
region
region_class
region_class_class
region_net
relative_delay
relative_group_delay
relative_group_length
relative_length
reorder
reroute_order_viols
resistance_resolution
resistor
resolution
restricted_layer_length_factor
room
rotate
rotate_first
round
roundoff_rotation
route
route_to_fanout_only
routes
routes_include
rule
same_net_checking
sample_window
saturation_length
sec
secondary
self
sequence_number
session
set_color
set_pattern
shape
shield
shield_gap
shield_loop
shield_tie_down_interval
shield_width
side
signal
site
small
smd
snap
snap_angle
soft
source
space_in_quoted_tokens
spacing
spare
spiral_via
square
stack_via
stack_via_depth
standard
starburst
status
structure
structure_out
subgate
subgates
substituted
such
suffix
super_placement
supply
supply_pin
swapping
switch_window
system
tandem_noise
tandem_segment
tandem_shield_overhang
terminal
terminator
term_only
test
test_points
testpoint
threshold
time_length_factor
time_resolution
tjunction
tolerance
top
topology
total
track_id
turret
type
um
unassigned
unconnects
unit
up
use_array
use_layer
use_net
use_via
value
vertical
via
via_array_template
via_at_smd
via_keepout
via_number
via_rotate_first
via_site
via_size
virtual_pin
volt
voltage_resolution
was_is
way
weight
width
window
wire
wire_keepout
wires
wires_include
wiring
write_resolution
x # test cmake script with indent and comment
xy
y
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment