[Japi-cvs] SF.net SVN: japi: [374] tools/cstyle/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-06-09 13:27:34
|
Revision: 374 http://svn.sourceforge.net/japi/?rev=374&view=rev Author: christianhujer Date: 2007-06-09 06:27:33 -0700 (Sat, 09 Jun 2007) Log Message: ----------- Added encoding property and memory for previous physical mode. Modified Paths: -------------- tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.java tools/cstyle/trunk/src/test/net/sf/japi/cstyle/CStyleTest.java Added Paths: ----------- tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.properties Modified: tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.java =================================================================== --- tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.java 2007-06-08 21:21:12 UTC (rev 373) +++ tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.java 2007-06-09 13:27:33 UTC (rev 374) @@ -30,6 +30,7 @@ import java.util.List; import net.sf.japi.io.args.ArgParser; import net.sf.japi.io.args.BasicCommand; +import net.sf.japi.io.args.Option; import org.jetbrains.annotations.NotNull; /** CStyle is a simple program that checks whether a C source or header file adhers to a specific code convention. @@ -50,9 +51,28 @@ */ @NotNull private String encoding = Charset.defaultCharset().name(); + /** The previous physicalMode of the parser. */ + @NotNull private PhysicalMode previousPhysicalMode = PhysicalMode.NORMAL; + /** The current physicalMode of the parser. */ @NotNull private PhysicalMode physicalMode = PhysicalMode.NORMAL; + /** The current token of the parser. */ + @NotNull private final StringBuilder currentToken = new StringBuilder(); + + /** Creates a CStyle command. */ + public CStyle() { + reset(); + } + + /** Sets the encoding to use when reading source files. + * @param encoding Encoding to use + */ + @Option({"e", "encoding"}) + public void setEncoding(@NotNull final String encoding) { + this.encoding = Charset.forName(encoding).name(); + } + /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) public int run(@NotNull final List<String> args) throws Exception { @@ -106,13 +126,17 @@ /** Reset the parser to its initial state. */ public void reset() { physicalMode = PhysicalMode.NORMAL; + previousPhysicalMode = PhysicalMode.NORMAL; + currentToken.setLength(0); } /** Processes a single character in the parser. * @param c Character to parse */ public void parse(final char c) { - switch (physicalMode) { + previousPhysicalMode = physicalMode; + // Step 1: Parse the character and determine the new mode. + switch (previousPhysicalMode) { case NORMAL: switch (c) { case '\\': physicalMode = PhysicalMode.ESCAPE; break; @@ -169,8 +193,19 @@ default: assert false; } + // Step 2: Tokenize + switch (physicalMode) { + case NORMAL: + } } + /** Returns the previous physicalMode of the parser. + * @return The previous physicalMode of the parser. + */ + @NotNull public PhysicalMode getPreviousPhysicalMode() { + return previousPhysicalMode; + } + /** Returns the current physicalMode of the parser. * @return The current physicalMode of the parser. */ Added: tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.properties =================================================================== --- tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.properties (rev 0) +++ tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.properties 2007-06-09 13:27:33 UTC (rev 374) @@ -0,0 +1,20 @@ +# +# CStyle is a program that verifies that a C source code adheres to a specific coding convention. +# Copyright (C) 2007 Christian Hujer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +setEncoding=Specify the encoding to use when reading the sources. Defaults to the underlying platform's default encoding. \ No newline at end of file Property changes on: tools/cstyle/trunk/src/net/sf/japi/cstyle/CStyle.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: tools/cstyle/trunk/src/test/net/sf/japi/cstyle/CStyleTest.java =================================================================== --- tools/cstyle/trunk/src/test/net/sf/japi/cstyle/CStyleTest.java 2007-06-08 21:21:12 UTC (rev 373) +++ tools/cstyle/trunk/src/test/net/sf/japi/cstyle/CStyleTest.java 2007-06-09 13:27:33 UTC (rev 374) @@ -43,9 +43,11 @@ @Test public void testReset() { final CStyle testling = new CStyle(); testling.parse('\''); + Assert.assertEquals("previous mode must stay NORMAL.", CStyle.PhysicalMode.NORMAL, testling.getPreviousPhysicalMode()); Assert.assertEquals("mode now must be CHAR.", CStyle.PhysicalMode.CHAR, testling.getPhysicalMode()); testling.reset(); Assert.assertEquals("After reset, mode must be NORMAL", CStyle.PhysicalMode.NORMAL, testling.getPhysicalMode()); + Assert.assertEquals("After reset, previous mode must be NORMAL", CStyle.PhysicalMode.NORMAL, testling.getPreviousPhysicalMode()); } } // class CStyleTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |