* [gentoo-commits] proj/libbash:master commit in: bashast/, coding_standard/
@ 2011-03-30 12:48 Petteri Räty
0 siblings, 0 replies; 2+ messages in thread
From: Petteri Räty @ 2011-03-30 12:48 UTC (permalink / raw
To: gentoo-commits
commit: 1f8f800cee198affb83f4c86206377ef3f66591e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 28 02:42:05 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Mar 29 04:34:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1f8f800c
Add indentation rules for grammar and autotools
Use tabs(ts=4) for grammar and autotools related files. Fixed
current indentation.
---
bashast/bashast.g | 4 ++--
coding_standard/coding_standard.tex | 9 ++++++---
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index d16ba5c..ef87271 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -509,8 +509,8 @@ name : NAME
//****************
COMMENT
- : (BLANK|EOL) '#' ~('\n'|'\r')* {$channel=HIDDEN;}
- ;
+ : (BLANK|EOL) '#' ~('\n'|'\r')* {$channel=HIDDEN;}
+ ;
//Bash "reserved words"
BANG : '!';
CASE : 'case';
diff --git a/coding_standard/coding_standard.tex b/coding_standard/coding_standard.tex
index 8230453..ba2e508 100644
--- a/coding_standard/coding_standard.tex
+++ b/coding_standard/coding_standard.tex
@@ -28,7 +28,7 @@ Header files must contain the appropriate ifndef header guard:
#ifndef FILENAME_H
#define FILENAME_H
-/*
+/*
code
*/
@@ -76,7 +76,10 @@ Member variables in a class should have the following comment block:
\section{Program code}
\subsection{Indentation}
Every line inside of a code block should be indented for easier readability.\\
-Tabs should not be used for indentation, only spaces. Indentation width will be two spaces.
+Tabs should not be used for indentation, only spaces. Indentation width will be two spaces. \\
+Tabs should be used for ANTLR grammar because antlrworks automatically generate tabs. \\
+Tabs should also be used for autotools related files(Makefile.am, configure.ac, etc). \\
+Use ts=4 for indentation.
\subsection{Naming conventions}
The name of a variable, function, class, or struct should be obvious from it's name.\\
Names will use underscored names not mixed case.\\
@@ -135,4 +138,4 @@ return my_list.size();
return (index<max_index? index : max_index);
\end{verbatim}
-\end{document}
\ No newline at end of file
+\end{document}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, coding_standard/
@ 2011-04-20 14:04 Petteri Räty
0 siblings, 0 replies; 2+ messages in thread
From: Petteri Räty @ 2011-04-20 14:04 UTC (permalink / raw
To: gentoo-commits
commit: 196d4ef6e15ec963d1b932706c537f42c231e248
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 18 11:23:37 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 20 12:48:43 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=196d4ef6
Coding standard: Add indentation rule for walker grammar
Put colon and the first alternative of a rule in the same line. Add
space between the rule and the left brace of the embedded action
block. Use one space between rule name and 'returns'. Limit for
line length is also added to the coding standard.
---
bashast/libbashWalker.g | 208 +++++++++++++++++------------------
coding_standard/coding_standard.tex | 7 +
2 files changed, 109 insertions(+), 106 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 848c110..76400f3 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -27,86 +27,85 @@ options
@includes{
-#include <memory>
-#include <string>
+ #include <memory>
+ #include <string>
-class interpreter;
-void set_interpreter(std::shared_ptr<interpreter> w);
+ class interpreter;
+ void set_interpreter(std::shared_ptr<interpreter> w);
}
@postinclude{
-#include "core/interpreter.h"
-#include <boost/format.hpp>
+ #include "core/interpreter.h"
+ #include <boost/format.hpp>
}
@members{
-static std::shared_ptr<interpreter> walker;
+ static std::shared_ptr<interpreter> walker;
-void set_interpreter(std::shared_ptr<interpreter> w)
-{
- walker = w;
-}
-
-inline void set_index(const std::string& name, unsigned& index, int value)
-{
- if(value < 0)
- throw interpreter_exception((boost::format("Array index is less than 0: \%s[\%d]") \% name \% value).str());
- index = value;
-}
+ void set_interpreter(std::shared_ptr<interpreter> w)
+ {
+ walker = w;
+ }
-// Recursively count number of nodes of curr
-static int count_nodes(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE curr)
-{
- int child_count = adaptor->getChildCount(adaptor, curr);
- if(child_count == 0)
+ inline void set_index(const std::string& name, unsigned& index, int value)
{
- // Leaf node
- return 1;
+ if(value < 0)
+ throw interpreter_exception((boost::format("Array index is less than 0: \%s[\%d]") \% name \% value).str());
+ index = value;
}
- else
+
+ // Recursively count number of nodes of curr
+ static int count_nodes(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE curr)
{
- int result = 0;
- // Count every child
- for(int i = 0; i != child_count; ++i)
- result += count_nodes(adaptor, (pANTLR3_BASE_TREE)(adaptor->getChild(adaptor, curr, i)));
- // Add itself, DOWN and UP
- return result + 3;
+ int child_count = adaptor->getChildCount(adaptor, curr);
+ if(child_count == 0)
+ {
+ // Leaf node
+ return 1;
+ }
+ else
+ {
+ int result = 0;
+ // Count every child
+ for(int i = 0; i != child_count; ++i)
+ result += count_nodes(adaptor, (pANTLR3_BASE_TREE)(adaptor->getChild(adaptor, curr, i)));
+ // Add itself, DOWN and UP
+ return result + 3;
+ }
}
-}
}
start: list|EOF;
-list:
- ^(LIST (function_def|logic_command_list)+);
+list: ^(LIST (function_def|logic_command_list)+);
variable_definitions: ^(VARIABLE_DEFINITIONS var_def+);
-name_base returns[std::string libbash_value]:
- NAME {$libbash_value = walker->get_string($NAME);}
- | LETTER {$libbash_value = walker->get_string($LETTER);}
- | '_' {$libbash_value="_";};
+name_base returns[std::string libbash_value]
+ :NAME { $libbash_value = walker->get_string($NAME); }
+ |LETTER { $libbash_value = walker->get_string($LETTER); }
+ |'_' { $libbash_value="_"; };
-name returns[std::string libbash_value, unsigned index]
+name returns[std::string libbash_value, unsigned index]
@init {
$index = 0;
-}:
- ^(libbash_name=name_base value=arithmetics){
+}
+ :^(libbash_name=name_base value=arithmetics) {
set_index(libbash_name, $index, value);
$libbash_value = libbash_name;
}
- |libbash_name=name_base{
+ |libbash_name=name_base {
$libbash_value = libbash_name;
};
num returns[std::string libbash_value]
-options{ k=1; }:
- DIGIT { $libbash_value = walker->get_string($DIGIT); }
+options{ k=1; }
+ :DIGIT { $libbash_value = walker->get_string($DIGIT); }
|NUMBER { $libbash_value = walker->get_string($NUMBER); };
var_def
@@ -114,8 +113,8 @@ var_def
std::map<int, std::string> values;
unsigned index = 0;
bool is_null = true;
-}:
- ^(EQUALS name (libbash_string=string_expr { is_null = false; })?){
+}
+ :^(EQUALS name (libbash_string=string_expr { is_null = false; })?) {
walker->set_value($name.libbash_value, libbash_string, $name.index, is_null);
}
|^(EQUALS libbash_name=name_base ^(ARRAY (
@@ -128,8 +127,8 @@ var_def
walker->define(libbash_name, values);
};
-string_expr returns[std::string libbash_value]:
- ^(STRING(
+string_expr returns[std::string libbash_value]
+ :^(STRING(
(DOUBLE_QUOTED_STRING) => ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*)
|(ARITHMETIC_EXPRESSION) => ^(ARITHMETIC_EXPRESSION value=arithmetics { $libbash_value = boost::lexical_cast<std::string>(value); })
|(var_ref[false]) => libbash_string=var_ref[false] { $libbash_value = libbash_string; }
@@ -137,30 +136,30 @@ string_expr returns[std::string libbash_value]:
));
//double quoted string rule, allows expansions
-double_quoted_string returns[std::string libbash_value]:
- (var_ref[true]) => libbash_string=var_ref[true] { $libbash_value = libbash_string; }
+double_quoted_string returns[std::string libbash_value]
+ :(var_ref[true]) => libbash_string=var_ref[true] { $libbash_value = libbash_string; }
|(ARITHMETIC_EXPRESSION) => ^(ARITHMETIC_EXPRESSION value=arithmetics) { $libbash_value = boost::lexical_cast<std::string>(value); }
|libbash_string=any_string { $libbash_value = libbash_string; };
any_string returns[std::string libbash_value]
@declarations {
pANTLR3_BASE_TREE any_token;
-}:
- any_token=. { $libbash_value = walker->get_string(any_token); };
+}
+ :any_token=. { $libbash_value = walker->get_string(any_token); };
//Allowable variable names in the variable expansion
var_name returns[std::string libbash_value, unsigned index]
@init {
$var_name.index = 0;
-}:
- libbash_string=num { $libbash_value = libbash_string; }
+}
+ :libbash_string=num { $libbash_value = libbash_string; }
|name {
$libbash_value = $name.libbash_value;
$index = $name.index;
};
-var_expansion returns[std::string libbash_value]:
- ^(USE_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=word) {
+var_expansion returns[std::string libbash_value]
+ :^(USE_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=word) {
libbash_value = walker->do_default_expansion($var_name.libbash_value, libbash_word, $var_name.index);
}
|^(ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=word) {
@@ -184,14 +183,14 @@ var_expansion returns[std::string libbash_value]:
}
));
-word returns[std::string libbash_value]:
- |(num) => libbash_string=num { $libbash_value = libbash_string; }
+word returns[std::string libbash_value]
+ :(num) => libbash_string=num { $libbash_value = libbash_string; }
|libbash_string=string_expr { $libbash_value = libbash_string; }
|value=arithmetics { $libbash_value = boost::lexical_cast<std::string>(value); };
//variable reference
-var_ref [bool double_quoted] returns[std::string libbash_value]:
- ^(VAR_REF name) { $libbash_value = walker->resolve<std::string>($name.libbash_value, $name.index); }
+var_ref [bool double_quoted] returns[std::string libbash_value]
+ :^(VAR_REF name) { $libbash_value = walker->resolve<std::string>($name.libbash_value, $name.index); }
|^(VAR_REF ^(libbash_string=name_base AT)) { walker->get_all_elements(libbash_string, $libbash_value); }
|^(VAR_REF ^(libbash_string=name_base TIMES)) {
if(double_quoted)
@@ -201,12 +200,12 @@ var_ref [bool double_quoted] returns[std::string libbash_value]:
}
|^(VAR_REF libbash_string=var_expansion) { $libbash_value = libbash_string; };
-command:
- variable_definitions
+command
+ :variable_definitions
|simple_command;
-simple_command:
- ^(COMMAND libbash_string=string_expr argument* var_def*) {
+simple_command
+ :^(COMMAND libbash_string=string_expr argument* var_def*) {
ANTLR3_MARKER func_index;
if((func_index = walker->get_function_index(libbash_string)) != -1)
{
@@ -225,23 +224,21 @@ simple_command:
}
};
-argument:
- var_ref[false]
+argument
+ :var_ref[false]
|string_expr;
-logic_command_list:
- command
- | ^(LOGICAND command command)
- | ^(LOGICOR command command);
+logic_command_list
+ :command
+ |^(LOGICAND command command)
+ |^(LOGICOR command command);
-command_list:
- ^(LIST logic_command_list+);
+command_list: ^(LIST logic_command_list+);
-compound_command:
- ^(CURRENT_SHELL command_list);
+compound_command: ^(CURRENT_SHELL command_list);
-function_def returns[int placeholder]:
- ^(FUNCTION ^(STRING name) {
+function_def returns[int placeholder]
+ :^(FUNCTION ^(STRING name) {
// Define the function with current index
walker->define_function($name.libbash_value, INDEX());
// Skip the AST for function body, minus one is needed to make the offset right.
@@ -252,8 +249,8 @@ function_def returns[int placeholder]:
});
// Only used in arithmetic expansion
-primary returns[std::string libbash_value, unsigned index]:
- (^(VAR_REF name)) => ^(VAR_REF name) {
+primary returns[std::string libbash_value, unsigned index]
+ :(^(VAR_REF name)) => ^(VAR_REF name) {
$libbash_value = $name.libbash_value;
$index = $name.index;
}
@@ -269,38 +266,37 @@ primary returns[std::string libbash_value, unsigned index]:
// shell arithmetic
arithmetics returns[int value]
-:
- ^(LOGICOR l=arithmetics r=arithmetics){ $value = walker->logicor(l, r); }
- |^(LOGICAND l=arithmetics r=arithmetics){ $value = walker->logicand(l, r); }
- |^(PIPE l=arithmetics r=arithmetics){ $value = walker->bitwiseor(l, r); }
- |^(CARET l=arithmetics r=arithmetics){ $value = walker->bitwisexor(l, r); }
- |^(AMP l=arithmetics r=arithmetics){ $value = walker->bitwiseand(l, r); }
- |^(LEQ l=arithmetics r=arithmetics){ $value = walker->less_equal_than(l, r); }
- |^(GEQ l=arithmetics r=arithmetics){ $value = walker->greater_equal_than(l, r); }
- |^(LESS_THAN l=arithmetics r=arithmetics){ $value = walker->less_than(l, r); }
- |^(GREATER_THAN l=arithmetics r=arithmetics){ $value = walker->greater_than(l, r); }
- |^(LSHIFT l=arithmetics r=arithmetics){ $value = walker->left_shift(l, r); }
- |^(RSHIFT l=arithmetics r=arithmetics){ $value = walker->right_shift(l, r); }
- |^(PLUS l=arithmetics r=arithmetics){ $value = walker->plus(l, r); }
- |^(PLUS_SIGN l=arithmetics){ $value = l; }
- |^(MINUS l=arithmetics r=arithmetics){ $value = walker->minus(l, r); }
- |^(MINUS_SIGN l=arithmetics){ $value = -l; }
- |^(TIMES l=arithmetics r=arithmetics){ $value = walker->multiply(l, r); }
- |^(SLASH l=arithmetics r=arithmetics){ $value = walker->divide(l, r); }
- |^(PCT l=arithmetics r=arithmetics){ $value = walker->mod(l, r); }
- |^(EXP l=arithmetics r=arithmetics){ $value = walker->exp(l, r); }
- |^(BANG l=arithmetics){ $value = walker->negation(l); }
- |^(TILDE l=arithmetics){ $value = walker->bitwise_negation(l); }
- |^(ARITHMETIC_CONDITION cnd=arithmetics l=arithmetics r=arithmetics){
+ :^(LOGICOR l=arithmetics r=arithmetics) { $value = walker->logicor(l, r); }
+ |^(LOGICAND l=arithmetics r=arithmetics) { $value = walker->logicand(l, r); }
+ |^(PIPE l=arithmetics r=arithmetics) { $value = walker->bitwiseor(l, r); }
+ |^(CARET l=arithmetics r=arithmetics) { $value = walker->bitwisexor(l, r); }
+ |^(AMP l=arithmetics r=arithmetics) { $value = walker->bitwiseand(l, r); }
+ |^(LEQ l=arithmetics r=arithmetics) { $value = walker->less_equal_than(l, r); }
+ |^(GEQ l=arithmetics r=arithmetics) { $value = walker->greater_equal_than(l, r); }
+ |^(LESS_THAN l=arithmetics r=arithmetics) { $value = walker->less_than(l, r); }
+ |^(GREATER_THAN l=arithmetics r=arithmetics) { $value = walker->greater_than(l, r); }
+ |^(LSHIFT l=arithmetics r=arithmetics) { $value = walker->left_shift(l, r); }
+ |^(RSHIFT l=arithmetics r=arithmetics) { $value = walker->right_shift(l, r); }
+ |^(PLUS l=arithmetics r=arithmetics) { $value = walker->plus(l, r); }
+ |^(PLUS_SIGN l=arithmetics) { $value = l; }
+ |^(MINUS l=arithmetics r=arithmetics) { $value = walker->minus(l, r); }
+ |^(MINUS_SIGN l=arithmetics) { $value = -l; }
+ |^(TIMES l=arithmetics r=arithmetics) { $value = walker->multiply(l, r); }
+ |^(SLASH l=arithmetics r=arithmetics) { $value = walker->divide(l, r); }
+ |^(PCT l=arithmetics r=arithmetics) { $value = walker->mod(l, r); }
+ |^(EXP l=arithmetics r=arithmetics) { $value = walker->exp(l, r); }
+ |^(BANG l=arithmetics) { $value = walker->negation(l); }
+ |^(TILDE l=arithmetics) { $value = walker->bitwise_negation(l); }
+ |^(ARITHMETIC_CONDITION cnd=arithmetics l=arithmetics r=arithmetics) {
$value = walker->arithmetic_condition(cnd, l, r);
}
|primary {
$value = walker->resolve<int>($primary.libbash_value, $primary.index);
}
- |^(PRE_INCR primary){ $value = walker->pre_incr($primary.libbash_value, $primary.index); }
- |^(PRE_DECR primary){ $value = walker->pre_decr($primary.libbash_value, $primary.index); }
- |^(POST_INCR primary){ $value = walker->post_incr($primary.libbash_value, $primary.index); }
- |^(POST_DECR primary){ $value = walker->post_decr($primary.libbash_value, $primary.index); }
+ |^(PRE_INCR primary) { $value = walker->pre_incr($primary.libbash_value, $primary.index); }
+ |^(PRE_DECR primary) { $value = walker->pre_decr($primary.libbash_value, $primary.index); }
+ |^(POST_INCR primary) { $value = walker->post_incr($primary.libbash_value, $primary.index); }
+ |^(POST_DECR primary) { $value = walker->post_decr($primary.libbash_value, $primary.index); }
|^(EQUALS primary l=arithmetics) {
$value = walker->set_value($primary.libbash_value, l, $primary.index);
}
diff --git a/coding_standard/coding_standard.tex b/coding_standard/coding_standard.tex
index e039fb0..4d663a1 100644
--- a/coding_standard/coding_standard.tex
+++ b/coding_standard/coding_standard.tex
@@ -97,6 +97,13 @@ Tabs should not be used for indentation, only spaces. Indentation width will be
Tabs should be used for ANTLR grammar because antlrworks automatically generate tabs. \\
Tabs should also be used for autotools related files(Makefile.am, configure.ac, etc). \\
Use ts=4 for indentation.
+\subsection{Line length}
+We don't have strict line length limit but you shouldn't write a line that is too long to be read easily. In general, we should keep the line length under 110 characters.
+\subsubsection{More indentation rules for tree walker grammar}
+Put colon and the first alternative of a rule in the same line with no space between them.\\
+Do not use space between the alternatives and '\textbar'.\\
+Put left brace of the embedded action block and the rule in the same line with one space between them.\\
+Use one space between rule name and 'returns'.
\subsection{Naming conventions}
The name of a variable, function, class, or struct should be obvious from it's name.\\
Names will use underscored names not mixed case.\\
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-04-20 14:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-30 12:48 [gentoo-commits] proj/libbash:master commit in: bashast/, coding_standard/ Petteri Räty
-- strict thread matches above, loose matches on Subject: below --
2011-04-20 14:04 Petteri Räty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox